Loop ending abruptly and Java not saving object? - java

So I'm having a problem with my code where my loop is ending for after my "C" case. I need it to print out a message saying the store is full and keep loop back up and print out the main menu. Also, my Pet3 is not being saved when I list all the pets after adding a new one. My
import java.util.*;
public class MainPets
{
static Scanner scan = new Scanner(System.in);
private static String Userinput;
private static void mainmenu(){
System.out.println("A."+" " + "List the pets in the store.");
System.out.println("B."+" " + "Age up the pets");
System.out.println("C."+" " + "Add a new pet");
System.out.println("D."+" " + "Adopt a pet");
System.out.println("E."+" " + "Quit");
Userinput=scan.nextLine();
}
public static String Getuserinput(){
return Userinput;
}
public static void main (String [] args){
int Pet3age;
String Pet3name;
Pet Pet1=new Pet("Fido",3);
Pet Pet2=new Pet("furball",1);
int Userinputint;
Pet Pet3=null;
System.out.println("Welcome to the pet store.Type the letter to make your selection");
MainPets.mainmenu();
while(Userinput.equals("A")||Userinput.equals("B")||Userinput.equals("C")||Userinput.equals("D")||Userinput.equals("E")){
switch(Userinput) {
case "A":
System.out.println("Fido is "+Pet1.GetAge()+ " years old and is " + Pet1.Getadoptionstatus());
System.out.println("furball is " + Pet2.GetAge()+ " years old and is " + Pet2.Getadoptionstatus());
Userinput=scan.nextLine();
case "B":
System.out.println("Everyone just got a little older.");
Pet1.ageincrease();
Pet2.ageincrease();
Userinput=scan.nextLine();
case "C":
if (Pet3!=null){
System.out.println("Sorry the store is full");
Userinput=scan.nextLine();
}/* If the Pet 3 spot has been filled I want it to print this
and loop back up to print the main menu again.*/
if(Pet3==null){
System.out.println("Please type in a name");
Pet3name=scan.nextLine();
System.out.println("Please type in an age");
Pet3age=scan.nextInt();
Pet3=new Pet(Pet3name,Pet3age);/*This line is Not saving Pet3 as
a "Pet" class and when I try to list all the pets by pressing
A when it loops back up , Pet3 does not show up as a Pet*/
Userinput=scan.nextLine();/* This is where my program just
ends.It doesn't even take a user input */
}
case "D":
//will add later on
break;
case "E":
//will add later on
break;
}
}
Here is the code for my Pet class:
public class Pet {
String Name, AdoptionStatus, True = "not adopted";
int Age;
public Pet() {}
public Pet(String Name, int Age) {
this.Name = Name;
this.Age = Age;
}
public void SetName(String namesetup) {
Name = namesetup;
}
public String GetName() {
return Name;
}
public int GetAge() {
return Age;
}
public int ageincrease() {
return Age++;
}
public String Getadoptionstatus() {
return AdoptionStatus;
}
public void Setadoptionstatus(String setadoption2) {
AdoptionStatus = True;
}
}

Your loop is extting when Pet3!=null because you are not taking any input from the scanner after it.
Take input in both conditions inside case "C":
if (Pet3!=null){
System.out.println("Sorry the store is full");
} else {
System.out.println("Please type in a name");
Pet3name=scan.nextLine();
System.out.println("Please type in an age");
Pet3age=scan.nextInt();
Pet3=new Pet(Pet3name,Pet3age);/*This line is Not saving Pet3 as
a "Pet" class and when I try to list all the pets by pressing
A when it loops back up , Pet3 does not show up as a Pet*/
}
Userinput=scan.nextLine(); //make sure to keep this line outside the curly braces.
break;

Related

How do I create a class designated to store an array, and then call it from any other method?

I am trying to clean my code up by creating a class specifically for an array of information. It is basically like a storage for variables in case I need them later. Here is what I have so far:
package com.input;
import java.util.Scanner;
public class Gender extends Welcome {
Scanner input = new Scanner(System.in);
private static String gender;
public static void setGender() {
Scanner input = new Scanner(System.in);
int[] storeInts = new int[25];
storeInts[0] = 0;
//The [0] index of array storeInformation is the gender value. 0 = female; 1 = male
gender = input.nextLine();
if(gender.equalsIgnoreCase("boy")) {
System.out.println("What is your name, sir?");
while (storeInts[0] < 1) {
storeInts[0]++;
}
}else if(gender.equalsIgnoreCase("girl")) {
System.out.println("What is your name, ma'am?");
}else{
System.out.println("You have failed to answer correctly. Try again:");
init();
}
Name nameObject = new Name();
nameObject.setName(storeInts[0]);
}
public static void nextName(int x) {
if(x == 1) {
System.out.println("What is your name, sir?");
}else{
System.out.println("What is your name, ma'am?");
}
Name nameObject = new Name();
nameObject.setName2();
}
}
What I'm trying to accomplish here, is if the user types "boy" my code will store 1 in the index [0] of array storeInts[]. If the user types "girl" the index [0] will remain the value of 0.
If I need to refer to the user's gender later on, I want to be able to go back and figure out if they are a "boy" or a "girl" using the array.
I want to be able to called this array from any method within my code. I have already used this array in a complicated way and I would like to find a solution to make it easier.
Here is when I used it:
nameObject.setName(storeInts[0]);
I transferred the index [0] to the setName() method.
Here is the setName() method:
public void setName(int x) {
String name;
name = input.nextLine();
String storedStrings[] = new String[25];
storedStrings[0] = name;
FirstTask firstTaskObject = new FirstTask();
if (name.length() == 0) {
System.out.println("You must be a unicorn. You want to play games?");
altInit(x);
}else{
System.out.println("Nice to meet you, " + name + "!");
firstTaskObject.beginning(name);
}
}
As you can see I created another array in the same manner as the previous one, but this one is to store Strings instead. Now back to what I was saying-- the parameter (int x) is the same value as storeInts[0]. This will tell me if the user is male or female. This value is sent to altInit() method when the user decides to try to continue without typing their name in first.
Here is the altInit() method:
public void altInit(int x) {
String yesOrNo;
AltStory altStoryObject = new AltStory();
Gender backToGender = new Gender();
yesOrNo = input.nextLine();
if(yesOrNo.equalsIgnoreCase("yes")) {
altStoryObject.AltInit();
}else if(yesOrNo.equalsIgnoreCase("no")) {
System.out.println("Consider this your last warning...");
backToGender.nextName(x);
}else{
System.out.println("You have failed to answer correctly. Try again:");
init();
}
}
When asked if they want to play games, they can type "yes" or "no." If the user types "no" as in they do not want to play games, then the program will print, "Consider this your last warning..." and then continue to the nextName() method in the previous class Gender. This also passes on that index[0] again in the array storedInts[].
Here is the nextName() method:
public static void nextName(int x) {
if(x == 1) {
System.out.println("What is your name, sir?");
}else{
System.out.println("What is your name, ma'am?");
}
Name nameObject = new Name();
nameObject.setName2();
}
As you can see, if the user is that value of a male (or 1) then the program will print, "What is your name, sir?." If the value is a female (or 0), then the program will print, "What is your name, ma'am?"
This whole time I felt like the stored value of storeInts[0], was just leap frogging around until it was used... I want to prevent this by just creating a class with methods giving me the ability to call any value stored in that array whenever I need it. How do I create an array, store it in a method, and call it when needed?
As someone has requested, here is the entire code:
//Gender class
package com.input;
import java.util.Scanner;
public class Gender extends Welcome {
Scanner input = new Scanner(System.in);
private static String gender;
public void setGender() {
Scanner input = new Scanner(System.in);
int [] storeInts = new int[25];
storeInts[0] = 0;
//The [0] index of array storeInformation is the gender value. 0 = female; 1 = male
gender = input.nextLine();
if (gender.equalsIgnoreCase("boy")) {
System.out.println("What is your name, sir?");
while(storeInts[0]<1){
storeInts[0]++;
}
} else if (gender.equalsIgnoreCase("girl")) {
System.out.println("What is your name, ma'am?");
} else {
System.out.println("You have failed to answer correctly. Try again:");
init();
}
Name nameObject = new Name();
nameObject.setName(storeInts[0]);
}
public void nextName(int x){
if (x == 1) {
System.out.println("What is your name, sir?");
}else {
System.out.println("What is your name, ma'am?");
}
Name nameObject = new Name();
nameObject.setName2();
}
}
//Name class
package com.input;
public class Name extends Gender{
public void setName(int x) {
String name;
name = input.nextLine();
String storedStrings[] = new String[25];
storedStrings[0] = name;
FirstTask firstTaskObject = new FirstTask();
if (name.length() == 0) {
System.out.println("You must be a unicorn. You want to play games?");
altInit(x);
} else {
System.out.println("Nice to meet you, " + name + "!");
firstTaskObject.beginning(name);
}
}
public void altInit(int x){
String yesOrNo;
AltStory altStoryObject = new AltStory();
Gender backToGender = new Gender();
yesOrNo = input.nextLine();
if(yesOrNo.equalsIgnoreCase("yes")) {
altStoryObject.AltInit();
}else if(yesOrNo.equalsIgnoreCase("no")){
System.out.println("Consider this your last warning...");
backToGender.nextName(x);
}else{
System.out.println("You have failed to answer correctly. Try again:");
init();
}
}
public void setName2() {
String name;
name = input.nextLine();
FirstTask firstTaskObject = new FirstTask();
if (name.length() == 0) {
System.out.println("You have failed to answer correctly. Try again:");
init();
} else {
System.out.println("Nice to meet you, " + name + "!");
firstTaskObject.beginning(name);
}
}
}
How do I create an array, store it in a method, and call it when needed?

Remove element from ArrayList using user input and iterator

I need to remove an element from an ArrayList, based on the user input. So what I have is an ArrayList where a user can register dogs. Then if the user wants to remove a dog, he/she should be able to do it by using the command "remove dog" followed by the name of the dog.
I have tried using an iterator, but when using it only the else statement is used and "Nothing has happened" is printed out on the screen.
import java.util.Iterator;
import java.util.Scanner;
import java.util.ArrayList;
public class DogRegister {
ArrayList<Dog> dogs = new ArrayList<>();
private Scanner keyboard = new Scanner(System.in);
public static void initialize() {
System.out.println("Welcome to this dog application");
}
private boolean handleCommand(String command) {
switch (command) {
case "One":
return true;
case "register new dog":
registerNewDog();
break;
case "increase age":
increaseAge();
break;
case "list dogs":
listDogs();
break;
case "remove dog":
removeDog();
break;
default:
System.out.println("Error: Unknown command");
}
return false;
}
private void registerNewDog() {
System.out.print("What is the dog's name? ");
String dogNameQuestion = keyboard.nextLine().toLowerCase().trim();
System.out.print("Which breed does it belong to? ");
String dogBreedQuestion = keyboard.nextLine().toLowerCase().trim();
System.out.print("How old is the dog? ");
int dogAgeQuestion = keyboard.nextInt();
System.out.print("What is its weight? ");
int dogWeightQuestion = keyboard.nextInt();
keyboard.nextLine();
Dog d = new Dog(dogNameQuestion, dogBreedQuestion, dogAgeQuestion,
dogWeightQuestion);
dogs.add(d);
System.out.println(dogs.get(0).toString());
}
private void removeDog() {
System.out.print("Enter the name of the dog ");
String removeDogList = keyboard.nextLine();
for (Iterator<Dog> dogsIterator = dogs.iterator();
dogsIterator.hasNext();) {
if (removeDogList.equals(dogsIterator)) {
System.out.println("The dog has been removed ");
break;
} else {
System.out.println("Nothing has happened ");
break;
}
}
}
public void closeDown() {
System.out.println("Goodbye!");
}
public void run() {
initialize();
runCommandLoop();
}
public static void main(String[] args) {
new DogRegister().run();
}
}
You compare a String will an Iterator as said by JB Nizet :
if (removeDogList.equals(dogsIterator)) {
It will never return true.
Besides even invoking next() on the iterator will not solve the problem as a String cannot be equal to a Dog object either.
Instead of, compare String with String when you use equals() and invoke Iterator.remove() to effectively remove the current iterated element.
That should be fine :
private void removeDog() {
System.out.print("Enter the name of the dog ");
String removeDogList = keyboard.nextLine();
for (Iterator<Dog> dogsIterator = dogs.iterator();dogsIterator.hasNext();) {
Dog dog = dogsIterator.next();
if (removeDogList.equals(dog.getName())) {
dogsIterator.remove();
System.out.println("The dog has been removed");
return;
}
}
System.out.println("Nothing has been removed");
}
An Iterator<Dog> can't possibly be equal to a String: they don't even have the same type.
Only a String can be equal to a String.
You want to get the next value of the iterator, which is a Dog. Then you want to compare the name of the dog with the String input.
And then you want to remove the dog, using the iterator's remove() method. Read the javadoc of Iterator.

How to look for element in linked list from user input java

so I have an assignment for my Data Structures class and I've tried to do as much as I can but I'm currently stuck on this part of the assignment and I need some help. The assignment basically requires you to make a java program that is a student record database that stores 6 variables: id, name, subCode, subName, sem, and year using linked list. This is what I have done so far.
Main class:
import java.util.*;
public class Main {
public int id =0;
public String name= "";
public String subCode="";
public String subName="";
public String sem;
public int year;
LinkedList list = new LinkedList();
Scanner scan = new Scanner(System.in);
public void Menu() {
boolean valid = true;
while (valid) {
final String menu[] = {"Main Menu",
"1. Register student's subjects",
"2. Retrieve all students' subjects listing",
"3. Retrieve a student's subjects listing",
"4. Update a student's registered subjects",
"5. Delete a student's registered subjects",
"6. Delete a student registration",
"7. Exit"};
for (String menuList : menu)
System.out.println(menuList);
switch (scan.nextInt()) {
case 1:
create();
break;
case 2:
list.retrieveAll();
break;
case 3:
//retrieveOne();
break;
case 4:
//update();
break;
case 5:
//deleteSub();
break;
case 6:
deleteStud();
break;
case 7:
System.out.println("Have a nice day!");
valid = false;
break;
default:
System.out.println("You have not entered a valid option");
break;
}
}
}
public void create() {
System.out.println();
boolean validate = true;
while(validate) {
try {
System.out.println("Please enter Name");
scan.nextLine();
name = scan.nextLine();
//validate =Validation.validateName(name);
System.out.println("Please enter Student ID");
String tempID=scan.nextLine();
// validate=Validation.validateId(tempID);
id= Integer.parseInt(tempID);
System.out.println("Please enter student Subject Code");
subCode=scan.nextLine();
System.out.println("Please enter Subject's Name");
subName = scan.nextLine();
System.out.println("Please enter Student's semester");
sem = scan.nextLine();
System.out.println("Please enter Student's Year of Study");
year = scan.nextInt();
scan.nextLine();
list.create(id, name, subCode, subName, sem, year);
validate=false;
/* list.create(17052960, "Samuel Ho", "CSCP 2014", "Programming 2", "Fall 2017", 2);
list.create(17040007, "Jodi Mak", "ENVS 1014", "Enviromental Studies", "Fall 2016", 3);
list.create(17022880, "Yee Hong Chun", "MATH 1024", "Calculus 1", "Fall 2018", 1);
list.retrieveAll();
list.deleteAt(1);
list.retrieveAll();*/
}catch(Exception e) {
validate = true;
}
}
}
public void deleteStud() {
System.out.println("Enter Student ID of the student you wish to delete");
int tempID = scan.nextInt();
scan.nextLine();
}
public static void main(String[] args) {
Main main = new Main();
main.Menu();
}
}
LinkedList class:
public class LinkedList {
Node head;
public void create(int id, String name, String subCode, String subName, String sem, int year) {
Node node= new Node();
node.id=id;
node.name=name;
node.subCode=subCode;
node.subName=subName;
node.sem=sem;
node.year=year;
node.next=null;
if (head==null) {
head=node;
}else {
Node n = head;
while (n.next!=null) {
n=n.next;
}
n.next=node;
}
}
public void retrieveAll() {
Node node=head;
while(node.next!=null) {
System.out.printf("%d %3s %10s %3s %14s %3d\n",
node.id, node.name, node.subCode, node.subName, node.sem, node.year );
node=node.next;
}
System.out.printf("%d %3s %10s %3s %14s %3d\n",
node.id, node.name, node.subCode, node.subName, node.sem, node.year );
}
public void deleteAt(int index) {
if (index==0)
head=head.next;
else {
Node n = head;
Node n1=null;
for (int i =0; i<index-1;i++) {
n=n.next;
}
n1=n.next;
n.next = n1.next;
System.out.println("Deleted " + n1.id);
n1=null;
}
}
}
Node class:
class Node {
int id;
String name;
String subCode;
String subName;
String sem;
int year;
Node next;
}
So this is what I have done, it is far from complete but I need to do it quick and I'm stuck at the deleteStud() method. I need a user input of which id of a student to delete. Then it searches in the linked list and deletes the student. I have implemented to deleteAt a certain index, but have no idea how to search and delete the student from their id. This is will also help my retrieveOne() method where I have to display a student's records from user input of their id.
I hope I'm not to long winded but I really need your help. Thank you so much.
Wouldn't it simply be the same as your deleteAt function, with the exception that you check node.Id instead of an Index?
Here's a rough crack at a solution (I didn't run this or anything).
public void deleteId(int ID){
Node previousNode=head;
Node currentNode=head;
while(currentNode!=null){
if(currentNode.id==ID){
previousNode.next=currentNode.next;
currentNode=currentNode.next;
}else{
previousNode=currentNode;
currentNode=currentNode.next;
}
}
System.out.println("Deleted " + ID);
}
What this code essentially does, is it goes through all nodes starting from head, keeping track of the current node you're inspecting, and the previous node you inspected.
If the current node's ID is equal to the ID you're looking for, we remove that node from the linked list by adjusting the previous node's next pointer.

How can i log in using a name and a password stored in two different arrays?

public class Coach extends Team {
private int Code;
public Coach(String name, String team, int age) {
super(name, team, age);
}
public Coach() {
}
public void setCode(int code) {
this.Code = code;
}
public int getCode() {
return Code;
}
public String code[] = {
"qwe",
"asd",
"zxc"
};
public String CoachName[] = {
"person1",
"person2",
"person3"
};
}
The main class
import com.org.FS.Coach;
import com.org.FS.Team;
import java.util.Scanner;
public class TeamTest {
public static void main(String[] args) {
System.out.println("Welcome to Federation System!! \n\nPlease enter your name:");
Scanner input = new Scanner(System.in);
String name = input.nextLine();
System.out.println("\nHi " + name + " !!\n\nPlease select an option\n 1- Guest and 2- Admin : \n Guest Admin ");
int choice = input.nextInt();
System.out.println("You choose --- " + choice);
switch (choice) {
case 1:
System.out.println("Table Info");
System.out.println("=============================================================");
break;
case 2:
System.out.println(" ==Log in== ");
}
if (choice == 1) {
Card c = new Card();
System.out.println(" ==Players==\n" + c);
System.out.println("==============================================================");
} else if (choice == 2) {
Coach co=new Coach();
System.out.println("Enter username:\n");
name=input.nextLine();
System.out.println("\n\nWelcome " + name + "\nPlease enter your verification code :");
String code1=input.nextLine();
for(int i=0;i<co.CoachName.length;i++) {
if( name.equals(co.CoachName[i]) || code1.equals(co.code[i]) && (!co.getName().equals(co.CoachName[++i]) || !co.code.equals(co.code[++i])) )
System.out.println("Wrong code!\nTry Again!");
else
System.out.println("Success !");
}
}
}
}
my project contains 5 classes named
TeamTest1(the main class)
Team
Players
Coach
and Card
the team class is the superclass and have coach and players as subclasses.
When i run the code and i press 1 the guest it shows only the players information.If i press two Admin,i want to put the name person1 like i have it in the array and the password too.Im very confused if i need to creATE A new array or to use the one i have...
for getting user input repeatedly you can use a while loop like so
int choice = input.nextInt();
while (choice != 3) {
...
choice = input.nextInt();
}
for getting (user,password) pairs you can use a map like so
Map users = new HashMap();
m.put("person1", "qwe");
m.put("person2", "asd");
m.put("person3", "zxc");
and check if the key value match
value = m.get(co.CoachName)
if code.equals(value) ....
Don't forget to use try catch and/or check for integrity of user input and keys exists in map and so...

Method not working properly when called upon?

I set up a method to increase the age of a Pet by 1 each time its called upon but for some reason, it is giving me the age originally set.
Here is the file with my methods and classes listed:
public class Pet
{
String Name;
int Age;
String AdoptionStatus;
String True="not adopted";
public Pet(){
}
public Pet(String Name,int Age){
this.Name=Name;
this.Age=Age;
}
public void SetName(String namesetup){
namesetup=Name;
}
public String GetName(){
return Name;
}
public int GetAge(){
return Age;
}
public int ageincrease(){
return Age+1;
}
public String Getadoptionstatus(){
return AdoptionStatus;
}
public void Setadoptionstatus(String setadoption2){
AdoptionStatus=True;
}
}
Here is the other class where the ageincrease() is called but ends up giving me zero:
public class MainPets
{
static Scanner scan = new Scanner(System.in);
private static String Userinput;
private static void mainmenu(){
System.out.println("A."+" " + "List the pets in the store.");
System.out.println("B."+" " + "Age up the pets");
System.out.println("C."+" " + "Add a new pet");
System.out.println("D."+" " + "Adopt a pet");
System.out.println("E."+" " + "Quit");
Userinput=scan.nextLine();
}
public static String Getuserinput(){
return Userinput;
}
public static void main (String [] args){
int Pet3age;
String Pet3name;
Pet Pet1=new Pet("Fido",3);
Pet Pet2=new Pet("furball",1);
Pet Pet3=null;
System.out.println("Welcome to the pet store.Type the letter to make your selection");
MainPets.mainmenu();
while (Userinput.equals("E")||Userinput.equals("A")||Userinput.equals("B")||Userinput.equals("C")||Userinput.equals("D")){
if (Userinput.equals("E")){
System.out.println("Have a good day!");
break;
}
else if(Userinput.equals("A")){
System.out.println("Fido is "+Pet1.GetAge()+ " years old and is " + Pet1.Getadoptionstatus());
System.out.println("furball is " + Pet2.GetAge()+ " years old and is " + Pet2.Getadoptionstatus());
Userinput=scan.nextLine();
}
if(Userinput.equals("B")){
System.out.println("Everyone just got a little older.");
Pet1.ageincrease();//Still keeps Pet1 age to 3
Pet2.ageincrease();//Still keeps Pet2 age to 1
Userinput=scan.nextLine();
}
else if (Userinput.equals("C")){
System.out.println("Please type in a name");
Pet3name=scan.nextLine();
System.out.println("Please type in an age");
Pet3age=scan.nextInt();
Userinput=scan.nextLine();
}
}
}
}
I cleaned up the code for you a little bit.
To answer your question first: You were returning the Age of the pet plus 1, not actually asigning a new value to the Pet's Age. To do this, use Age++ or Age = Age + 1 or Age += 1. This should assign a new value to the Pet's age, thus fixing your issue.
Here are the changes I've made:
Condensed the String declarations to one line
Fixed SetName(String namesetup). You had the statment namesetup=Name, which assigns the Name field of the class to the instance variable namesetup of the method. You want to assign what was passed to the method to the class which is done by Name=namesetup
Changed the return statement in ageincrease() to return Age++; instead of return Age + 1;. This is the same as Age = Age + 1;
Replaced the long while loop in the main class with a switch statement and a while loop. This is convenient because you don't need a long condition check in the while loop. I used a flag variable that flags when the user inputs "E". If you're unfamiliar with switch statements, then you can readup on them here.
Notes and concerns:
With your current code, you check for the condition Userinput.equals("D") in the while loop, but you have nothing in the while loop to handle that condition, which leaves a possibility for an infinite loop.
I'm not going to change the names of your variables or methods, but you should know that the convention is variableName, where the first word is lowercase and the all the following have the first letter uppercased. Your variable and method names are inconsitent with this convention in your code, which can make it confusing for other coders to read and use. Following this convention is a good coding practice that can save you headaches on larger projects.
Here's your edited Pet class:
public class Pet {
String Name, AdoptionStatus, True = "not adopted";
int Age;
public Pet() {}
public Pet(String Name, int Age) {
this.Name = Name;
this.Age = Age;
}
public void SetName(String namesetup) {
Name = namesetup;
}
public String GetName() {
return Name;
}
public int GetAge() {
return Age;
}
public int ageincrease() {
return Age++;
}
public String Getadoptionstatus() {
return AdoptionStatus;
}
public void Setadoptionstatus(String setadoption2) {
AdoptionStatus = True;
}
}
And here's what I replaced the your while loop with:
int flag = 0;
while(flag != -1) {
switch(Userinput) {
case "A":
System.out.println("Fido is "+Pet1.GetAge()+ " years old and is " + Pet1.Getadoptionstatus());
System.out.println("furball is " + Pet2.GetAge()+ " years old and is " + Pet2.Getadoptionstatus());
Userinput=scan.nextLine();
break;
case "B":
System.out.println("Everyone just got a little older.");
Pet1.ageincrease();//Still keeps Pet1 age to 3
Pet2.ageincrease();//Still keeps Pet2 age to 1
System.out.println(Pet1.GetAge() + " " + Pet2.GetAge());
Userinput=scan.nextLine();
break;
case "C":
System.out.println("Please type in a name");
Pet3name=scan.nextLine();
System.out.println("Please type in an age");
Pet3age=scan.nextInt();
Userinput=scan.nextLine();
break;
case "D":
//Not sure how you want to implement this
break;
case "E":
flag = -1;
break;
}
}

Categories