I have written a Java code for zoo monitoring but for some reason
I keep getting error messages when I run it. I am using Java Net Beans IDE to build the program. Could someone please help me so that I can get this to work properly in Net Beans IDE?import java.io.IOException;import java.util.List;import java.util.Scanner;import javax.swing.JFrame;import javax.swing.JOptionPane;////public class ZooMonitoringSystem {@SuppressWarnings("empty-statement")public static void main(String[] args) throws IOException {//main() function will allow user to choose something to monitor.//regrdless of which is chosen the program will open a file, save each line//to a list then search the list for details on while keeping track of wherevr it is// on the list. It will the prompt the user for a specific animal and continue searching the//list from where it left of to the end...while outputing the things it finds relevant//while statement allows the user to return to main menu after completionwhile (true) {System.out.println("What would you like to monitor? ");System.out.println("Enter 1 to monitor Animals ");System.out.println("Enter 2 to monitor Habitats ");System.out.println("Enter 3 to Exit");int userInput = 0;// scanner reads input from userScanner sc = new Scanner(System.in);userInput = sc.nextInt();// a variable to keep track of where we are searching in the fileint write = 0;String animalName;String habitatName;//if the input from the user is the number 1if (userInput == 1) {System.out.println("List of Animals ");//calls from animals fileReader rd = new Reader("ANIMALS.txt");//rd.get() will store all contents of animals file into a list// the list's elements are each of the lines of the fileList list = rd.get();// a for loop to go through the listfor (String line : list) {// if an element (line) in the list contains the words "Details on"if (line.toLowerCase().contains("Details on".toLowerCase())) {//increase the write variable that tracks the index of the listwrite = write + 1;//print out every line that has "details on" substringSystem.out.println(line);}}//allow user to input an animal's name for searchingSystem.out.println("Enter name of animal you would like to monitor: ");animalName = sc.next();for (String category : list.subList(write, list.size()))//specific range within the list (From where we stopped searching as tracked by the write variable, to the end of the list) {//search for an animal in the list{if (category.toLowerCase().contains(animalName.toLowerCase())) {write = list.indexOf(category);// if an animal is found, then the next 5 elements in the list (next 5 lines in the file)// are info about the animalfor (int i = write; i//displays alert message if file contains ******--indicating abnormal detection//check first if the line in the for loop contains ***if (list.get(i).contains("*****")) {JOptionPane.showMessageDialog(new JFrame(), list.get(i), "ALERT!!!", JOptionPane.ERROR_MESSAGE);break;} //if the line in the for loop doesn't contain a **** then print it printedelse {System.out.println(list.get(i));}}}}} else if (userInput == 2) {System.out.println("List of Habitats ");//calls from habitats fileReader rd = new Reader("HABITATS.txt");//rd.get() will store all contents of habitats file into a list// the list's elements are each of the lines of the fileList list = rd.get();//loop through the whole listfor (String line : list) {//search for "details on" in the list's elementsif (line.toLowerCase().contains("Details on".toLowerCase())) {//maintain the position of the line being searched using the write variablewrite = write + 1;//print out every line that has "details on" substringSystem.out.println(line);}}System.out.println("Enter the name of a habitat you would like to monitor: ");//ask user for a habitat namehabitatName = sc.next();// search for a habitats beginning from where we left of our search as tracked by the write variable//we use sublist() to separate already searched itemsfor (String res : list.subList(write, list.size())) {//check if line contains a habitat nameif (res.toLowerCase().contains(habitatName.toLowerCase())) {write = list.indexOf(res);// if a habitat is found, then the next 4 elements in the list (next 4 lines in the file)// are info about the habitatfor (int i = write; i//check if the line to be printed contains "****"if (list.get(i).contains("*****")) {//raise Alert boxJOptionPane.showMessageDialog(new JFrame(), list.get(i), "ALERT!!!", JOptionPane.ERROR_MESSAGE);break;} //if the line in the for loop doesn't contain a **** then print it printedelse {System.out.println(list.get(i));}}}}} //if the user chooses the third choiceelse if (userInput == 3) {//close the scannersc.close();//exit the systemSystem.exit(0);}}}}
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here