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 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 completion

while (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 user

Scanner sc = new Scanner(System.in);

userInput = sc.nextInt();

// a variable to keep track of where we are searching in the file

int write = 0;

String animalName;

String habitatName;

//if the input from the user is the number 1

if (userInput == 1) {

System.out.println("List of Animals ");

//calls from animals file

Reader 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 file

List list = rd.get();

// a for loop to go through the list

for (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 list

write = write + 1;

//print out every line that has "details on" substring

System.out.println(line);

}





}

//allow user to input an animal's name for searching

System.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 animal

for (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 printed

else {





System.out.println(list.get(i));

}

}





}

}





} else if (userInput == 2) {

System.out.println("List of Habitats ");

//calls from habitats file

Reader 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 file

List list = rd.get();

//loop through the whole list

for (String line : list) {

//search for "details on" in the list's elements

if (line.toLowerCase().contains("Details on".toLowerCase())) {

//maintain the position of the line being searched using the write variable

write = write + 1;

//print out every line that has "details on" substring

System.out.println(line);





}

}





System.out.println("Enter the name of a habitat you would like to monitor: ");

//ask user for a habitat name

habitatName = 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 items

for (String res : list.subList(write, list.size())) {

//check if line contains a habitat name

if (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 habitat

for (int i = write; i


//check if the line to be printed contains "****"

if (list.get(i).contains("*****")) {

//raise Alert box

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 printed

else {

System.out.println(list.get(i));

}

}

}





}





} //if the user chooses the third choice

else if (userInput == 3) {

//close the scanner

sc.close();

//exit the system

System.exit(0);

}

}





}

}



May 18, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here