Question: In JAVA, In two classes: As a zookeeper, it is important to know the activities of the animals in your care and to monitor their

In JAVA, In two classes:

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

The class that I need assistance in creating is the "Monitoring" class that is menu driven and will create an "AnimalsHabitat" object and call the methods in it.

The AnimalsHabitat file has already been created. The txt files are below.

AnimalsHabitat:

import java.io.FileInputStream;

import java.io.IOException;

import java.util.*;

import javax.swing.JOptionPane;

public class AnimalsHabitat {

private String filePath;

final private Scanner scnr;

public AnimalsHabitat() {

//filePath = "C:\\Users\\mine\\Documents\\monitoring\\";

filePath = "";

scnr = new Scanner(System.in);

}

public void askForWhichDetails(String fileName) throws IOException {

FileInputStream fileByteStream = null; // File input stream

Scanner inFS = null; // Scanner object

String textLine = null;

ArrayList aList1 = new ArrayList();

int i = 0;

int option = 0;

boolean bailOut = false;

// open file

fileByteStream = new FileInputStream(filePath + fileName + ".txt");

inFS = new Scanner(fileByteStream);

while (inFS.hasNextLine() && bailOut == false) {

textLine = inFS.nextLine();

if (textLine.contains("Details")) {

i += 1;

System.out.println(i + ". " + textLine);

ArrayList aList2 = new ArrayList();

for (String retval : textLine.split(" ")) {

aList2.add(retval);

}

String str = aList2.remove(2).toString();

aList1.add(str);

}

else {

System.out.print("Enter selection: ");

option = scnr.nextInt();

System.out.println("");

if (option <= i) {

String detailOption = aList1.remove(option - 1).toString();

showData(fileName, detailOption);

bailOut = true;

} break;

}

}

// close file

fileByteStream.close(); // close() may throw IOException if fails

}

public void showData(String fileName, String detailOption) throws IOException {

FileInputStream fileByteStream = null; // File input stream

Scanner inFS = null; // Scanner object

String textLine = null;

String lcTextLine = null;

String alertMessage = "*****";

int lcStr1Len = fileName.length();

String lcStr1 = fileName.toLowerCase().substring(0, lcStr1Len - 1);

int lcStr2Len = detailOption.length();

String lcStr2 = detailOption.toLowerCase().substring(0, lcStr2Len - 1);

boolean bailOut = false;

// open file

fileByteStream = new FileInputStream(filePath + fileName + ".txt");

inFS = new Scanner(fileByteStream);

while (inFS.hasNextLine() && bailOut == false) {

textLine = inFS.nextLine();

lcTextLine = textLine.toLowerCase();

if (lcTextLine.contains(lcStr1) && lcTextLine.contains(lcStr2)) {

do {

System.out.println(textLine);

textLine = inFS.nextLine();

if (textLine.isEmpty()) {

bailOut = true;

}

if (textLine.contains(alertMessage)) {

JOptionPane.showMessageDialog(null, textLine.substring(5));

}

} while (inFS.hasNextLine() && bailOut == false);

}

}

// close file file

ByteStream.close(); // close() may throw IOException if fails

}

}

Animals txt file:

Details on lions

Details on tigers

Details on bears

Details on giraffes

Animal - Lion Name: Leo Age: 5 *****Health concerns: Cut on left front paw Feeding schedule: Twice daily

Animal - Tiger Name: Maj Age: 15 Health concerns: None Feeding schedule: 3x daily

Animal - Bear Name: Baloo Age: 1 Health concerns: None *****Feeding schedule: None on record

Animal - Giraffe Name: Spots Age: 12 Health concerns: None Feeding schedule: Grazing

Habitats txt file:

Details on penguin habitat

Details on bird house

Details on aquarium

Habitat - Penguin Temperature: Freezing *****Food source: Fish in water running low Cleanliness: Passed

Habitat - Bird Temperature: Moderate Food source: Natural from environment Cleanliness: Passed

Habitat - Aquarium Temperature: Varies with output temperature Food source: Added daily *****Cleanliness: Needs cleaning from algae

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!