IT-144 Project 2

mwinqu1983
Project2_Part3_Driver.java.java

package com.it145; import java.util.ArrayList; // Allow to make lists with room for expansion import java.util.List; // Allow the creation of lists import java.util.Scanner; // Provide various ways to read user input /* * Use 'public' modifier on the RescueAnimal java class so it is accessible to the entire application. */ public class Driver { // Use a mutator method that is public, not associated with a class, doesn't // have to return a value ans accepts a single string array arguement /** * @param args * @return */ public static void main(String[] args) { // Create an array list of variables ArrayList<RescueAnimal> animals = new ArrayList<>(); // Create New Dog Dog dog = new Dog(); dog.setBreed("Beagle"); animals.add(dog); // Create New Monkey Monkey monkey = new Monkey(); monkey.setTailLength(25F); monkey.setHeight(50F); monkey.setBodyLength(30F); monkey.setTorsoMeasurement(15F); monkey.setSkullMeasurement(10F); monkey.setNeckMeasurement(5F); monkey.setSpecies("Tamarin"); animals.add(monkey); // Method to process request for a rescue animal // Method(s) to update information on existing animals // Method to display matrix of aninmals based on location and // status/training phase // Method to add animals addAnimal(animals); // Method to out process animals for the farm or in-service placement // Method to display in-service animals // Process reports from in-service agencies reporting death/retirement } /** * @param animals */ public static void addAnimal(List<RescueAnimal> animals) { Scanner input = new Scanner(System.in); int choice = 1; while (true) { // Ask user for input of animal type System.out.println("Select an animal to input\n\t1. Dog\n\t2. Monkey\n Input your number below"); try { // Ensure that their input is a number and a valid choice choice = Integer.parseInt(input.nextLine()); if (choice != 1 || choice != 2) throw new NumberFormatException(); break; } // If it is not, print an error message and loop again catch (Exception e) { System.out.println("Invalid input. Try again."); } } // Ask user for the animal's name System.out.println("Input the animal's name below"); String name = input.nextLine(); // Ask for the animal breed System.out.println("Input the animal's breed below"); String breed = input.nextLine(); // If the animal is a dog, then add a dog to the list if (choice == 1) { Dog newDog = new Dog(); newDog.setName(name); newDog.setBreed(breed); animals.add(newDog); } // Otherwise, if the user chose a monkey, add a monkey to the list else if (choice == 2) { Monkey newMonkey = new Monkey(); newMonkey.setName(name); newMonkey.setType(breed); animals.add(newMonkey); } input.close(); } }