Driver.java Class

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.
  1. 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.

  1. 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 RescueAnimal classes as you create this method.

  1. 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 intakeNewMonkey() 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.

  2. 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.
  1. 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.
    • 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 criteria, the method should output feedback to the user letting them know that no animals of that type and location are available.
  1. 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”

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

public class Driver {
private static ArrayList dogList = new ArrayList();
private static ArrayList monkeyList = new ArrayList();
private static ArrayList monkeySpecies = new ArrayList();
// Instance variables (if needed)
Object listDogs = new Object();

public static void main(String[] args) {

initializeDogList();
initializeMonkeyList();
initializeMonkeySpecies();

Scanner scnr = new Scanner(System.in);
displayMenu();

String userIn = scnr.nextLine();

while (!userIn.equalsIgnoreCase(“Q”)) {

if (userIn.equals(“1”)) {
intakeNewDog(scnr);
userIn = scnr.nextLine();
}

if (userIn.equals(“2”)) {
intakeNewMonkey(scnr);
userIn = scnr.nextLine();
}

if (userIn.equals(“3”)) {
reserveAnimal(scnr);
userIn = scnr.nextLine();
}

if (userIn.equals(“4”)) {
printAnimals(“dog”);
userIn = scnr.nextLine();
}

if (userIn.equals(“5”)) {
printAnimals(“monkey”);
userIn = scnr.nextLine();
}

if (userIn.equals(“6”)) {
printAnimals(“available”);
userIn = scnr.nextLine();
}

else {
System.out.println(“Invalid input”);
displayMenu();
userIn = scnr.nextLine();
}
}

if (userIn.equalsIgnoreCase(“q”)) {
System.out.println(“Exiting program”);
scnr.close();
System.exit(0);
}
}

// This method prints the menu options
public static void displayMenu() {
System.out.println(“\n\n”);
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\n”);
}
}