Question: Can you help me with this code at the end of the Driver.java please? Finally, you have been asked to implement a printAnimals() method that
Can you help me with this code at the end of the Driver.java please?
Finally, you have been asked to implement a printAnimals() method that provides easy-to-read output displaying the details of objects in an ArrayList.
- To demonstrate this criterion in a proficient way, your implemented method must successfully print the ArrayList of dogs or the ArrayList of monkeys.
- To demonstrate this criterion in an exemplary way, your implemented method must successfully print a list of all animals that are in service and available.
Implement a method to print (display) information about the animals that: Prints a list of all dogs OR all monkeys OR all animals that are in service and available (not reserved)
Provided code:






1 import java.util.ArrayList; 2 3 import java.util.Scanner; 4 5 public class Driver { 6 7 private static Scanner scanner = new Scanner(System.in); 8 9 private static ArrayList doglist = new ArrayList(); LO // Instance variables (if needed) 1 2 private static ArrayList monkeylist new ArrayList();|| 3 -40 public static void main(String[] args) { 5 String menuChoice =""; -7 initializeDoglist(); 9 initializeMonkeyList(); u o o oo o // Add a loop that displays the menu, accepts the users input // and takes the appropriate action. // For the project submission you must also include input validation // and appropriate feedback to the user. // Hint: create a Scanner and pass it to the necessary // methods // Hint: Menu options 4, 5, and 6 should all connect to the printAnimals() method. while( ! menuChoice.equalsIgnoreCase("q")){ displayMenu(); menuChoice = scanner.nextLine(); switch(menuChoice) { case "1": intakeNewDog(scanner); System.out.println(" "); break; case "2": intakeNewMonkey (scanner); System.out.println(" "); break; case "3": reserveAnimal (scanner); System.out.println(" "); break; 7 8 -0 -1 -2. -3 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 610 printAnimals(scanner); System.out.println(" "); break; case "5": printAnimals(scanner); System.out.println(" "); break; case "6": printAnimals(scanner); System.out.println(" "); break; } } 62 63 64 65 66 67 68 69 // This method prints the menu options public static void displayMenu() { System.out.println(" "); System.out.println("\t\t\t\tRescue Animal System Menu"); System.out.println("[1] Intake a new dog"); System.out.println("[2] Intake a new monkey"); System.out.println("[3] Reserve an animal"); System.out.println("[4] Print a list of all dogs"); System.out.println("[5] Print a list of all monkeys"); System.out.println("[6] Print a list of all animals that are not reserved"); System.out.println("[9] Quit application"); System.out.println(); System.out.println("Enter a menu selection"); } 70 71 72 73 74 75 760 77 78 79 80 81 82 83 // Adds dogs to a list for testing public static void initializeDoglist() { Dog dog1 = new Dog("Spot", "German Shepherd", "male", "1", "25.6", "05-12-2019", "United States", "intake", false, "United States"); Dog dog2 = new Dog("Rex", "Great Dane", "male", "3", "35.2", "02-03-2020", "United States", "Phase I", false, "United States"); Dog dog3 = new Dog("Bella", "Chihuahua", "female", "4", "25.6", "12-12-2019", "Canada", "in service", true, "Canada"); dogList.add(dog1); doglist.add(dog2); doglist.add(dog3); 84 } 85 86 // Adds monkeys to a list for testing 87 88e 89 90 //Optional for testing public static void initializeMonkeyList() { Monkey monkey1 = new Monkey("George", "Capuchin", "5.2", "9.4", "19.6", "male", "2", "15.3", "09-11-2019", "Canada", "Phase I", true, "Canada"); Monkey monkey2 = new Monkey ("Kong", "Macaque", "4.8", "10.2", "20.7", "female", "1", "17.4", "12-05-2020", "United Kingdom", "in service", false, "United Kingdom"); Monkey monkey3 = new Monkey ("Donkey", "Tamarin", "5.5", "8.6", "18.4", "male", "3", "18.2", "12-10-2019", "United States", "intake", false, "United States"); monkeyList.add(monkey1); monkeyList.add(monkey2); monkeyList.add(monkey3); } // Complete the intakeNewDog method // The input validation to check that the dog is not already in the list // is done for you public static void intakeNewDog(Scanner scanner) { System.out.println("What is the dog's name?"); String name = scanner.nextLine(); for(Dog dog: doglist) { if(dog.getName().equalsignoreCase(name)) { System.out.println(" This dog is already in our system "); return; //returns to menu } } 91 92 93 94 95 96 97 98 99 100 1010 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 // Add the code to instantiate a new dog and add it to the appropriate list System.out.println("What is the dog's breed?"); String breed = scanner.nextLine(); System.out.println("What is the dog's gender?"); String gender = scanner.nextLine(); System.out.println("What is the dog's age?"); String age = scanner.nextLine(); System.out.println("What is the dog's weight?"); String weight = scanner.nextLine(); System.out.println("What is the dog's acquisition date?"); String acqDate = scanner.nextLine(); System.out.println("What is the dog's acquisition country?"); String acqCountry = scanner.nextLine(); System.out.println("What is the dog's training status?"); String ts = scanner.nextLine(); System.out.println("Is the dog reserved?"); boolean res = scanner.nextBoolean(); scanner.nextLine(); System.out.println("What is the dog's in Service Country?"); String isc = scanner.nextLine(); Dog newdog = new Dog (name, breed, gender, age, weight, acqDate, acq Country,ts,res, isc); dogList.add(newdog); } // Complete intakeNewMonkey //Instantiate and add the new monkey to the appropriate list // For the project submission you must also validate the input // to make sure the monkey doesn't already exist and the species type is allowed public static void intakeNewMonkey (Scanner scanner) { String name = scanner.nextLine(); for (Monkey monkey: monkeylist) { if(monkey.getName().equalsignoreCase(name)) { System.out.println(" This monkey is already in our system "); return; //returns to menu } } System.out.println("What is the monkey's species?"); String species = scanner.nextLine(); if(!(species.equalsIgnoreCase("Capuchin"))&& !(species.equalsIgnoreCase("Guenon"))&& !(species.equals IgnoreCase("Mac System.out.println(" This monkey's species is not allowed "); return; } System.out.println("What is the monkey's tail length?"); String tailLength = scanner.nextLine(); System.out.println("What is the monkey's height?"); String height = scanner.nextLine(); System.out.println("What is the monkey's body length?"); String bodyLength = scanner.nextLine(); System.out.println("What is the monkey's gender?"); String gender = scanner.nextLine(); System.out.println("What is the monkey's age?"); String age = scanner.nextLine(); System.out.println("What is the monkey's weight?"); String weight = scanner.nextLine(); System.out.println("What is the monkey's acquisition date?"); String acqDate = scanner.nextLine(); System.out.println("What is the monkey's acquisition country?"); String acqCountry = scanner.nextLine(); System.out.println("What is the monkey's training status?"); String ts = scanner.nextLine(); System.out.println("Is the monkey reserved?"); boolean res = scanner.nextBoolean(); scanner.nextLine(); System.out.println("What is the monkey's in Service Country?"); System.out.println("What is the monkey's in Service Country?"); String isc = scanner.nextLine(); Monkey newmonkey = new Monkey (name, species, tailLength, height, bodyLength, gender, age, weight, acqDate, acqCountry, ts,res, isc); monkeyList.add(newmonkey); } // Complete reserveAnimal // You will need to find the animal by animal type and in service country public static void reserveAnimal(Scanner scanner) { System.out.println("Enter the animal type"); String type = scanner.nextLine(); if(type.equals("Monkey") || type.equals("monkey")){ System.out.println("Enter the Monkey's Country"); String country = scanner.nextLine(); for(Monkey obj: monkeyList){ if(obj.acquisitionCountry.equals(country)){ obj.reserved = true; return; 172 173 174 175 176 177 178 179 1800 181 182 3183 184 185 186 2187 2188 3189 190 2191 192 193 194 2195 196 2197 198 3199 2200 201 2202 203 204 205 206 2207 208 209 210 211 System.out.println("Sorry that Monkey is not in our list"); } else if(type.equals("Dog") || type.equals("dog")){ System.out.println("Enter the Dog's Country"); String country = scannen.nextLine(); for (Dog obj: doglist){ if(obj.acquisitionCountry.equals(country)) { obj.reserved = true; return; } } System.out.println("Sorry that Dog is not in our list"); } else System.out.println("Type Not Found"); } 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 2250 226 227 228 229 } 230 231 // Complete printAnimals // Include the animal name, status, acquisition country and if the animal is reserved. // Remember that this method connects to three different menu items. // The printAnimals() method has three different outputs // based on the listType parameter // dog - prints the list of dogs // monkey - prints the list of monkeys // available - prints a combined list of all animals that are // fully trained ("in service") but not reserved // Remember that you only have to fully implement ONE of these lists. // The other lists can have a print statement saying "This option needs to be implemented". // to score "exemplary" you must correctly implement the "available" list. public static void printAnimals(Scanner scanner2) { System.out.println("The method printAnimals needs to be implemented"); } 1 import java.util.ArrayList; 2 3 import java.util.Scanner; 4 5 public class Driver { 6 7 private static Scanner scanner = new Scanner(System.in); 8 9 private static ArrayList doglist = new ArrayList(); LO // Instance variables (if needed) 1 2 private static ArrayList monkeylist new ArrayList();|| 3 -40 public static void main(String[] args) { 5 String menuChoice =""; -7 initializeDoglist(); 9 initializeMonkeyList(); u o o oo o // Add a loop that displays the menu, accepts the users input // and takes the appropriate action. // For the project submission you must also include input validation // and appropriate feedback to the user. // Hint: create a Scanner and pass it to the necessary // methods // Hint: Menu options 4, 5, and 6 should all connect to the printAnimals() method. while( ! menuChoice.equalsIgnoreCase("q")){ displayMenu(); menuChoice = scanner.nextLine(); switch(menuChoice) { case "1": intakeNewDog(scanner); System.out.println(" "); break; case "2": intakeNewMonkey (scanner); System.out.println(" "); break; case "3": reserveAnimal (scanner); System.out.println(" "); break; 7 8 -0 -1 -2. -3 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 610 printAnimals(scanner); System.out.println(" "); break; case "5": printAnimals(scanner); System.out.println(" "); break; case "6": printAnimals(scanner); System.out.println(" "); break; } } 62 63 64 65 66 67 68 69 // This method prints the menu options public static void displayMenu() { System.out.println(" "); System.out.println("\t\t\t\tRescue Animal System Menu"); System.out.println("[1] Intake a new dog"); System.out.println("[2] Intake a new monkey"); System.out.println("[3] Reserve an animal"); System.out.println("[4] Print a list of all dogs"); System.out.println("[5] Print a list of all monkeys"); System.out.println("[6] Print a list of all animals that are not reserved"); System.out.println("[9] Quit application"); System.out.println(); System.out.println("Enter a menu selection"); } 70 71 72 73 74 75 760 77 78 79 80 81 82 83 // Adds dogs to a list for testing public static void initializeDoglist() { Dog dog1 = new Dog("Spot", "German Shepherd", "male", "1", "25.6", "05-12-2019", "United States", "intake", false, "United States"); Dog dog2 = new Dog("Rex", "Great Dane", "male", "3", "35.2", "02-03-2020", "United States", "Phase I", false, "United States"); Dog dog3 = new Dog("Bella", "Chihuahua", "female", "4", "25.6", "12-12-2019", "Canada", "in service", true, "Canada"); dogList.add(dog1); doglist.add(dog2); doglist.add(dog3); 84 } 85 86 // Adds monkeys to a list for testing 87 88e 89 90 //Optional for testing public static void initializeMonkeyList() { Monkey monkey1 = new Monkey("George", "Capuchin", "5.2", "9.4", "19.6", "male", "2", "15.3", "09-11-2019", "Canada", "Phase I", true, "Canada"); Monkey monkey2 = new Monkey ("Kong", "Macaque", "4.8", "10.2", "20.7", "female", "1", "17.4", "12-05-2020", "United Kingdom", "in service", false, "United Kingdom"); Monkey monkey3 = new Monkey ("Donkey", "Tamarin", "5.5", "8.6", "18.4", "male", "3", "18.2", "12-10-2019", "United States", "intake", false, "United States"); monkeyList.add(monkey1); monkeyList.add(monkey2); monkeyList.add(monkey3); } // Complete the intakeNewDog method // The input validation to check that the dog is not already in the list // is done for you public static void intakeNewDog(Scanner scanner) { System.out.println("What is the dog's name?"); String name = scanner.nextLine(); for(Dog dog: doglist) { if(dog.getName().equalsignoreCase(name)) { System.out.println(" This dog is already in our system "); return; //returns to menu } } 91 92 93 94 95 96 97 98 99 100 1010 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 // Add the code to instantiate a new dog and add it to the appropriate list System.out.println("What is the dog's breed?"); String breed = scanner.nextLine(); System.out.println("What is the dog's gender?"); String gender = scanner.nextLine(); System.out.println("What is the dog's age?"); String age = scanner.nextLine(); System.out.println("What is the dog's weight?"); String weight = scanner.nextLine(); System.out.println("What is the dog's acquisition date?"); String acqDate = scanner.nextLine(); System.out.println("What is the dog's acquisition country?"); String acqCountry = scanner.nextLine(); System.out.println("What is the dog's training status?"); String ts = scanner.nextLine(); System.out.println("Is the dog reserved?"); boolean res = scanner.nextBoolean(); scanner.nextLine(); System.out.println("What is the dog's in Service Country?"); String isc = scanner.nextLine(); Dog newdog = new Dog (name, breed, gender, age, weight, acqDate, acq Country,ts,res, isc); dogList.add(newdog); } // Complete intakeNewMonkey //Instantiate and add the new monkey to the appropriate list // For the project submission you must also validate the input // to make sure the monkey doesn't already exist and the species type is allowed public static void intakeNewMonkey (Scanner scanner) { String name = scanner.nextLine(); for (Monkey monkey: monkeylist) { if(monkey.getName().equalsignoreCase(name)) { System.out.println(" This monkey is already in our system "); return; //returns to menu } } System.out.println("What is the monkey's species?"); String species = scanner.nextLine(); if(!(species.equalsIgnoreCase("Capuchin"))&& !(species.equalsIgnoreCase("Guenon"))&& !(species.equals IgnoreCase("Mac System.out.println(" This monkey's species is not allowed "); return; } System.out.println("What is the monkey's tail length?"); String tailLength = scanner.nextLine(); System.out.println("What is the monkey's height?"); String height = scanner.nextLine(); System.out.println("What is the monkey's body length?"); String bodyLength = scanner.nextLine(); System.out.println("What is the monkey's gender?"); String gender = scanner.nextLine(); System.out.println("What is the monkey's age?"); String age = scanner.nextLine(); System.out.println("What is the monkey's weight?"); String weight = scanner.nextLine(); System.out.println("What is the monkey's acquisition date?"); String acqDate = scanner.nextLine(); System.out.println("What is the monkey's acquisition country?"); String acqCountry = scanner.nextLine(); System.out.println("What is the monkey's training status?"); String ts = scanner.nextLine(); System.out.println("Is the monkey reserved?"); boolean res = scanner.nextBoolean(); scanner.nextLine(); System.out.println("What is the monkey's in Service Country?"); System.out.println("What is the monkey's in Service Country?"); String isc = scanner.nextLine(); Monkey newmonkey = new Monkey (name, species, tailLength, height, bodyLength, gender, age, weight, acqDate, acqCountry, ts,res, isc); monkeyList.add(newmonkey); } // Complete reserveAnimal // You will need to find the animal by animal type and in service country public static void reserveAnimal(Scanner scanner) { System.out.println("Enter the animal type"); String type = scanner.nextLine(); if(type.equals("Monkey") || type.equals("monkey")){ System.out.println("Enter the Monkey's Country"); String country = scanner.nextLine(); for(Monkey obj: monkeyList){ if(obj.acquisitionCountry.equals(country)){ obj.reserved = true; return; 172 173 174 175 176 177 178 179 1800 181 182 3183 184 185 186 2187 2188 3189 190 2191 192 193 194 2195 196 2197 198 3199 2200 201 2202 203 204 205 206 2207 208 209 210 211 System.out.println("Sorry that Monkey is not in our list"); } else if(type.equals("Dog") || type.equals("dog")){ System.out.println("Enter the Dog's Country"); String country = scannen.nextLine(); for (Dog obj: doglist){ if(obj.acquisitionCountry.equals(country)) { obj.reserved = true; return; } } System.out.println("Sorry that Dog is not in our list"); } else System.out.println("Type Not Found"); } 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 2250 226 227 228 229 } 230 231 // Complete printAnimals // Include the animal name, status, acquisition country and if the animal is reserved. // Remember that this method connects to three different menu items. // The printAnimals() method has three different outputs // based on the listType parameter // dog - prints the list of dogs // monkey - prints the list of monkeys // available - prints a combined list of all animals that are // fully trained ("in service") but not reserved // Remember that you only have to fully implement ONE of these lists. // The other lists can have a print statement saying "This option needs to be implemented". // to score "exemplary" you must correctly implement the "available" list. public static void printAnimals(Scanner scanner2) { System.out.println("The method printAnimals needs to be implemented"); }