Driver

.docx

School

Southern New Hampshire University *

*We aren’t endorsed by this school

Course

145

Subject

Computer Science

Date

Dec 6, 2023

Type

docx

Pages

8

Uploaded by AmbassadorDove3627

Report
Stanley Artis IT-145 Professor Daff Kalulu 26 November 2023 Package Grazioso import java . util . ArrayList ; import java . util . Scanner ; public class Driver { private static ArrayList < Dog > dogList = new ArrayList < Dog >(); // Instance variables (if needed) private static ArrayList < Monkey > monkeyList = new 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. char input = 0 ; int input1 = Character . getNumericValue ( input ); boolean isValidSelection = true ; displayMenu (); //Starts Menu// do { isValidSelection = true ; try { input = scnr . nextLine (). charAt ( 0 );
if ( input == 'q' ) { //Quits Menu System . out . print ( "Good Bye!" ); System . exit ( 0 ); } else { input1 = Character . getNumericValue ( input ); } if ( input1 < 1 || input1 > 6 ) throw new Exception ( "Invalid Entry. Please try again" ); } catch ( Exception excpt ) { System . out . println ( excpt . getMessage ()); isValidSelection = false ; } } while ( ! isValidSelection ); switch ( input1 ) { case 1 -> intakeNewDog (scnr); case 2 -> intakeNewMonkey (scnr); case 3 -> reserveAnimal (scnr); case 4 -> printDogs (); case 5 -> printMonkey (); case 6 -> printAnimals (); } } // This method prints the menu options public static void displayMenu () { System . out . println ( " \n\n " ); System . out . println ( " \t\t\t\t Rescue 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 ( "Johnny" , "Macaque" , "5.9" , "8.9" , "20.6" , "male" , "1" , "16.3" , "08-10-2019" , "Canada" , "Phase I" , true , "Canada" ); Monkey monkey2 = new Monkey ( "Breck" , "Capuchin" , "5.1" , "11.2" , "21.7" , "female" , "1" , "17.1" , "06-04-2020" , "Mexico" , "in service" , false , "Mexico" ); Monkey monkey3 = new Monkey ( "Earl" , "Tamarin" , "5.7" , "7.7" , "19.3" , "male" , "3" , "17.2" , "12-05-2021" , "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 ( " \n\n This dog is already in our system \n\n " );
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help