Question: Please assist with providing pseudocode only for the below problem/provided code. Thank you! Problem: As a zookeeper, it is important to know the activities of
Please assist with providing pseudocode only for the below problem/provided code. Thank you!
Problem:
As a zookeeper, it is important to know the activities of the animals in your care and to monitor their living habitats. Create a monitoring system that does all of the following:
Asks a user if they want to monitor an animal, monitor a habitat, or exit
Displays a list of animal/habitat options (based on the previous selection) as read from either the animals or habitats file o Asks the user to enter one of the options
Displays the monitoring information by finding the appropriate section in the file Separates sections by the category and selection (such as Animal - Lion or Habitat - Penguin)
Uses a dialog box to alert the zookeeper if the monitor detects something out of the normal range (These will be denoted in the files by a new line starting with *****. Do not display the asterisks in the dialog.)
Allows a user to return to the original options You are allowed to add extra animals, habitats, or alerts, but you may not remove the existing ones.
Code provided:
MonitorSystem.java
package monitorsystem; import java.io.File; import java.util.Scanner; import java.io.FileNotFoundException; import javax.swing.*;
//the class monitorSystem public class MonitorSystem { private static String monitorOption;
//main public static void main(String[] args){ try { //display the main menu monitorOptionMenu(); } catch (FileNotFoundException ex) { } } //monitor option menu definition public static void monitorOptionMenu() throws FileNotFoundException{ //the scanner object to take the inputs Scanner scnr = new Scanner(System.in); String monitorOption = ""; // monitor input System.out.println(" Welcome to the Zookeeper's Monitoring System! "); boolean inputDone = false; while (!inputDone){ System.out.println("Pick monitor options Habitats, Animals, or Exit?"); monitorOption = scnr.nextLine();
//switch to handle the selections switch (monitorOption) { case ("Animals"): //the function to handle animal option handleAnimalOption(); break; case ("Habitats"): //the function to hanlde habitat option handleHabitatOption (); break; case ("Exit"): //to handle exit System.out.println("Goodbye"); inputDone = true; System.exit(0); break; //if error in input default: //display to input again System.out.println("Error in Input..Enter Again!"); monitorOptionMenu(); break; } } } //monitor animal menu function public static void handleAnimalOption () throws FileNotFoundException { Scanner scnr = new Scanner(System.in); int animalSelect;
System.out.println("Animals Picked");
//the do while loop to read the file and perform the operations
do { //the scanner object to read the file Scanner scnFile = new Scanner(new File("animals.txt")); String firstLine=scnFile.nextLine(); String secondLine=scnFile.nextLine(); String thirdLine=scnFile.nextLine(); String fourthLine=scnFile.nextLine(); System.out.println("Please Select Option: 1, 2, 3, 4, 5, 6 or 7! 1. "+firstLine+" 2. "+secondLine+ " 3. "+thirdLine+" 4. " +fourthLine+" 5. Go back to Main Menu 6. Monitor a Habitat 7. to Exit"); while (!scnr.hasNextInt()) { System.out.println("Error in input!! Please input the number representing the item"); System.out.println("Please Select Option: 1, 2, 3, 4, 5, 6 or 7! 1. "+firstLine+" 2. "+secondLine+ " 3. "+thirdLine+" 4. " +fourthLine+" 5. Go back to Main Menu 6. Monitor a Habitat 7. to Exit"); scnr.next(); } animalSelect = scnr.nextInt(); //User inputs option String fileLine; switch (animalSelect) { //case to handle the first line animal case 1: scnFile.nextLine(); System.out.println(); for(int itr=0;itr<5;itr++) { fileLine=scnFile.nextLine(); if(fileLine.charAt(0)=='*') JOptionPane.showMessageDialog(null, fileLine.substring(5)); else System.out.println(fileLine); } break; //case to handle second line animal case 2: for(int itr=0;itr<7;itr++) scnFile.nextLine(); System.out.println(); for(int itr=0;itr<5;itr++) { fileLine=scnFile.nextLine(); if(fileLine.charAt(0)=='*') JOptionPane.showMessageDialog(null, fileLine.substring(5)); else System.out.println(fileLine); } break; //To handle third lined animal case 3: for(int itr=0;itr<13;itr++) scnFile.nextLine(); System.out.println(); for(int itr=0;itr<5;itr++) { fileLine=scnFile.nextLine(); if(fileLine.charAt(0)=='*') JOptionPane.showMessageDialog(null, fileLine.substring(5)); else System.out.println(fileLine); } break; //To handle fourth lined animal case 4: for(int itr=0;itr<19;itr++) scnFile.nextLine(); System.out.println(); for(int itr=0;itr<5;itr++) { fileLine=scnFile.nextLine(); if(fileLine.charAt(0)=='*') JOptionPane.showMessageDialog(null, fileLine.substring(5)); else System.out.println(fileLine); } break; //to go back to main menu case 5: monitorOptionMenu(); break; case 6: handleHabitatOption(); break; case 7: System.out.println("Goodbye"); System.exit(0); break; default: System.out.println("Error in Input..Enter Again!"); handleAnimalOption(); break; } //close the file scanner scnFile.close(); }while (animalSelect!=7); } //The function tp handle habitat selection public static void handleHabitatOption () throws FileNotFoundException { Scanner scnr = new Scanner(System.in); int habitSelect; System.out.println("Monitor a Habitat"); do { //the lines to read from habitat file Scanner scnFile = new Scanner(new File("habitats.txt")); String firstLine=scnFile.nextLine(); String secondLine=scnFile.nextLine(); String thirdLine=scnFile.nextLine(); System.out.println("Please Select Option: 1, 2, 3, 4, 5 or 6! 1. "+firstLine + " 2. "+secondLine+" 3. "+thirdLine+ " 4. " + "Go back to Main Menu 5. Monitor an Animal 6. to Exit"); while (!scnr.hasNextInt()) { System.out.println("Invalid Input! Not A Number"); System.out.println("Please Select Option: 1, 2, 3, 4, 5 or 6! 1. "+firstLine + " 2. "+secondLine+" 3. "+thirdLine+ " 4. " + "Go back to Main Menu 5. Monitor an Animal 6. to Exit"); scnr.next(); } //read the option habitSelect = scnr.nextInt(); String fileLine; //the switch to handle the habitat selections switch (habitSelect) { case 1: scnFile.nextLine(); System.out.println(); for(int itr=0;itr<4;itr++) { fileLine=scnFile.nextLine(); if(fileLine.charAt(0)=='*') JOptionPane.showMessageDialog(null, fileLine.substring(5)); else System.out.println(fileLine); } break; case 2: for(int itr=0;itr<6;itr++) scnFile.nextLine(); for(int itr=0;itr<4;itr++) { fileLine=scnFile.nextLine(); if(fileLine.charAt(0)=='*') JOptionPane.showMessageDialog(null, fileLine.substring(5)); else System.out.println(fileLine); } break; case 3: for(int itr=0;itr<11;itr++) scnFile.nextLine(); for(int itr=0;itr<4;itr++) { fileLine=scnFile.nextLine(); if(fileLine.charAt(0)=='*') JOptionPane.showMessageDialog(null, fileLine.substring(5)); else System.out.println(fileLine); } break; case 4: monitorOptionMenu(); break; case 5: handleAnimalOption(); break; case 6: System.out.println("Goodbye"); System.exit(0); break; default: System.out.println("Error in Input..Enter Again!"); handleHabitatOption(); break; } scnFile.close(); } while (habitSelect !=6); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
