Question: Can I have help fixing this code? My instant feedback stated my monkey class was correct but I don't know what I have done wrong
Can I have help fixing this code? My instant feedback stated my monkey class was correct but I don't know what I have done wrong here for the driver...
import java.util.ArrayList; import java.util.Scanner;
public class Driver { private static ArrayList
public static void main(String[] args) {
initializeDogList(); initializeMonkeyList();
// 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.
Scanner sc=new Scanner(System.in); displayMenu(); char userInput = sc.nextLine().charAt(0); if (userInput == 'q') { System.exit(0); } int userIntInput=Character.getNumericValue(userInput); while(userIntInput<1 || userintinput>6){ System.out.println("Please make a valid selection!"); displayMenu(); userInput = sc.nextLine().charAt(0); userIntInput = Character.getNumericValue(userInput);} switch(userIntInput) { case 1: intakeNewDog(sc); break; case 2: intakeNewMonkey(sc); break; case 3: reserveAnimal(sc); break; case 4: printAnimals(); break; case 5: printAnimals(); break; case 6: printAnimals(); break; } }
// 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("[q] Quit application"); System.out.println(); System.out.println("Enter a menu selection"); }
// 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); }
// Adds monkeys to a list for testing //Optional for testing public static void initializeMonkeyList() { }
// 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 } }
// Add the code to instantiate a new dog and add it to the appropriate list System.out.println("Breed?"); String breed = scanner.nextLine(); System.out.println("Gender?"); String gender = scanner.nextLine(); System.out.println("Age?"); String age = scanner.nextLine(); System.out.println("Weight?"); String weight = scanner.nextLine(); System.out.println("Acquistion Date?"); String acquireDate = scanner.nextLine(); System.out.println("Acquistion Country?"); String acquireCountry = scanner.nextLine(); System.out.println("Training Status?"); String trainingStatus = scanner.nextLine(); System.out.println("Is this animal reserved?"); boolean reserved = scanner.nextBoolean(); scanner.nextLine(); System.out.println("Service Country?"); String serviceCountry = scanner.nextLine(); Dog (name, breed, gender, age, weight, acquireDate, acquireCountry, trainingStatus, reserved, serviceCountry); dogList.add(new dog); }
// 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) { System.out.println("What is the monkey's name?"); 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 } }
// Add the code to instantiate a new dog and add it to the appropriate list System.out.println("Species?"); String species = scanner.nextLine(); if(!(species.equalsIgnoreCase("Capuchin")) && !(species.equalsIgnoreCase("Guenon")) && !(species.equalsIgnoreCase("Macaque")) && !(species.equalsIgnoreCase("Marmoset")) && !(species.equalsIgnoreCase("Squirrel Monkey")) && !(species.equalsIgnoreCase("Tamarin"))){ System.out.println("This monkey's species is not allowed"); return; System.out.println("Tail Length?"); String tailLength = scanner.nextLine(); System.out.println("Height?"); String height = scanner.nextLine(); System.out.println("Body Length?"); String bodyLength = scanner.nextLine(); System.out.println("Gender?"); String gender = scanner.nextLine(); System.out.println("Age?"); String age = scanner.nextLine(); System.out.println("Weight?"); String weight = scanner.nextLine(); System.out.println("Acquistion Date?"); String acquireDate = scanner.nextLine(); System.out.println("Acquistion Country?"); String acquireCountry = scanner.nextLine(); System.out.println("Training Status?"); String trainingStatus = scanner.nextLine(); System.out.println("Is this animal reserved?"); boolean reserved = scanner.nextBoolean(); scanner.nextLine(); System.out.println("Service Country?"); String serviceCountry = scanner.nextLine(); Monkey (name, species, tailLength, height, bodyLength, gender, age, weight, acquireDate, acquireCountry, trainingStatus, reserved, serviceCountry); monkeyList.add(new Monkey); }
// 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("The method reserveAnimal needs to be implemented");
}
// 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() { System.out.println("The method printAnimals needs to be implemented");
} }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
