Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.ArrayList; import java.util.Scanner; public class Driver { private static ArrayList dogList = new ArrayList (); private static ArrayList monkeyList = new ArrayList (); //

image text in transcribed

import java.util.ArrayList; import java.util.Scanner;

public class Driver { private static ArrayList dogList = new ArrayList(); private static ArrayListmonkeyList = new ArrayList(); // Instance variables (if needed)

// 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() { Monkey monkey1 = new Monkey("Marcel", "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("Pat", "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 } }

// 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,acqCountry,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) { 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 } } System.out.println("What is the monkey's species?"); String species = scanner.nextLine(); //if statement 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("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?"); 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("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");

}

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. //array for Scanner scnr=new Scanner(System.in); displayMenu(); System.out.println("Enter a menu selection"); char input=scnr.nextLine().charAt(0); if(input=='q'){ System.exit(0); } int input1=Character.getNumericValue(input); while(input16){ System.out.println("Invalid selection!"); displayMenu(); System.out.println("Enter a menu selection"); input=scnr.nextLine().charAt(0); input1=Character.getNumericValue(input); } switch(input1){ case 1: intakeNewDog(scnr); break; case 2: intakeNewMonkey(scnr); break; case 3: reserveAnimal(scnr); break; case 4: printAnimals(); break; case 5: printAnimals(); break; case 6: System.exit(0); } } } if the other java is needed please let me know I have java for monkey, dog and rescueAnimal

Driver.java Class In this class, you will modify and implement several different methods. You will need to refer back to the code from the other classes to properly implement these methods. 1. As a reminder, you must demonstrate industry standard best practices, such as in-line comments to denote changes and describe functionality and appropriate naming conventions throughout the code that you create or modify for this class. 2. First, you will modify the main() method. In main(), you must create a menu loop that does the following: Displays the menu by calling the displayMenu() method. This method is in the Driver.java class. Prompts the user for input Includes input validation. If the user inputs a value not on the menu, the program should print an error message. Takes the appropriate action based on the value that the user entered. IMPORTANT: In the Module Five milestone, you were asked to create a menu loop but were not required to include input validation. Be sure to include input validation for your Project Two submission. 3. Next, you will complete the intakeNewDog() method. Your completed method should do the following: Prompt the user for input . Include input validation. Note: The required input validation has already been included in the starter code; be sure to review it. Set data for all attributes based on user input Add the newly instantiated dog to an ArrayList Hint: Remember to refer to the accessors and mutators in the Dog and Rescue Animal classes as you create this method. 4. Next, you will implement the intakeNewMonkey() method. Before you do this, you will need to create a monkey ArrayList in the Driver.java class. Refer to the dog ArrayList for an example. Then, begin implementing the intakeNewMonkey0 method. Your completed method should do the following: Prompt the user for input Include input validation for the monkey's name and species type. If the user enters an invalid option, the program should print an error message Set data for all attributes based on user input Add the newly instantiated monkey to an ArrayList Hint: Remember to refer to the accessors and mutators in your Monkey and RescueAnimal classes as you create this method. IMPORTANT: In the Module Five milestone, you began implementing this method but were not required to include input validation. Be sure to include input validation for your Project Two submission. 5. Next, you will implement the reserveAnimal() method. Your completed method should do the following: Prompt the user for input. The user should enter their desired animal type and country. o If there is an available animal which meets the user's input criteria, the method should access an animal object from an ArrayList. If there are multiple animals that meet these criteria, the program should access the first animal in the ArrayList. The method should also update the "reserved" attribute of the accessed animal. If there is not an available animal which meets the user's input crite the method should output feedback to the user letting them know that no animals of that type and location are available. 6. 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 25th European Conference Adbis 2021 Tartu Estonia August 24 26 2021 Proceedings Lncs 12843

Authors: Ladjel Bellatreche ,Marlon Dumas ,Panagiotis Karras ,Raimundas Matulevicius

1st Edition

3030824713, 978-3030824716

More Books

Students also viewed these Databases questions

Question

Perform the indicated operations, if possible. CDA

Answered: 1 week ago

Question

4. Does cultural aptitude impact ones emotional intelligence?

Answered: 1 week ago

Question

7. Do the organizations social activities reflect diversity?

Answered: 1 week ago