JAVA:
Add to the code at the bottom to do the following two things
1. A \"Monitoring.java\" class that contains a “main(…)” method that will instantiate a
“animalsHabitat” object and call the methods in it.
2. Proper comments and formatting in this .java file and the one that you will create.
PROMPT:
Create a program for a zookeeper monitoring system using two classes. One to be used to
determine what the user wants to do, monitor animals or habitats. The other to read the file for
the chosen action (listed below as animal/habitat file). Create a monitoring system that does all
of the following:
1) Asks a user if they want to monitor an animal, monitor a habitat, or exit
2)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
3) Displays the monitoring information by finding the appropriate section in the file
4) Separates sections by the category and selection (such as “Animal - Lion” or “Habitat -
Penguin”)
5) 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.)
6) Allows a user to return to the original options
Animals file: (saved on local)
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
Habitat file: (Saved on local)
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
Code so far:
package monitoring;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.*;
public class animalsHabitat {
private String filePath;
final private Scanner scnr;
public animalsHabitat() {
filePath = \"C:\\\\mylocalfolder\";
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;
// Try to open file
fileByteStream = new FileInputStream(filePath + fileName + \".txt\");
inFS = new Scanner(fileByteStream);
while (inFS.hasNextLine() && bailOut == false) {
textLine = inFS.nextLine();
if (textLine.cont.
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
JAVAAdd to the code at the bottom to do the following two things.pdf
1. JAVA:
Add to the code at the bottom to do the following two things
1. A "Monitoring.java" class that contains a “main(…)” method that will instantiate a
“animalsHabitat” object and call the methods in it.
2. Proper comments and formatting in this .java file and the one that you will create.
PROMPT:
Create a program for a zookeeper monitoring system using two classes. One to be used to
determine what the user wants to do, monitor animals or habitats. The other to read the file for
the chosen action (listed below as animal/habitat file). Create a monitoring system that does all
of the following:
1) Asks a user if they want to monitor an animal, monitor a habitat, or exit
2)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
3) Displays the monitoring information by finding the appropriate section in the file
4) Separates sections by the category and selection (such as “Animal - Lion” or “Habitat -
Penguin”)
5) 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.)
6) Allows a user to return to the original options
Animals file: (saved on local)
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
2. 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
Habitat file: (Saved on local)
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
Code so far:
package monitoring;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.*;
public class animalsHabitat {
private String filePath;
final private Scanner scnr;
public animalsHabitat() {
filePath = "C:mylocalfolder";
3. 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;
// Try to 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;
}
}
4. // Done with file, so try to close it
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;
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;
// Try to 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;
}
} while (inFS.hasNextLine() && bailOut == false);
}
}
// Done with file, so try to close it
fileByteStream.close(); // close() may throw IOException if fails
}
}
Solution
5. // main Method
public class Monitoring
{
public static void main(String a[])
{
try
{
animalsHabitat zoo = new animalsHabitat(); // Create object of anumalshabitat
zoo.askForWhichDetails("animals"); // Call askForWhichDetails() method for animals file
zoo.askForWhichDetails("habitat"); //Call askForWhichDetails() method for habitat file
zoo.showData("habitat", "bird"); // Call showData() method to display data in habitat file
}
catch(Exception e)
{
System.out.println(e);
}
}
}
package monitoring;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.*;
public class animalsHabitat {
private String filePath;
final private Scanner scnr;
public animalsHabitat() {
filePath = "C:mylocalfolder";
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(); // Arraylist to hold details of each animal or habitat
6. int i = 0;
int option = 0;
boolean bailOut = false;
// Try to open file
fileByteStream = new FileInputStream(filePath + fileName + ".txt");
inFS = new Scanner(fileByteStream);
while (inFS.hasNextLine() && bailOut == false) { // Read data from file line by line
textLine = inFS.nextLine();
if (textLine.contains("Details")) {
i += 1;
System.out.println(i + ". " + textLine);
ArrayList aList2 = new ArrayList();
for (String retval : textLine.split(" ")) { // add each line to array list
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;
}
}
// Done with file, so try to close it
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;
7. String lcTextLine = null;
int lcStr1Len = fileName.length();
String lcStr1 = fileName.toLowerCase().substring(0, lcStr1Len - 1); // convert file name to
lower case
int lcStr2Len = detailOption.length();
String lcStr2 = detailOption.toLowerCase().substring(0, lcStr2Len - 1);
boolean bailOut = false;
// Try to open file
fileByteStream = new FileInputStream(filePath + fileName + ".txt"); // open file
inFS = new Scanner(fileByteStream);
while (inFS.hasNextLine() && bailOut == false) { // read data line by line from file
textLine = inFS.nextLine();
lcTextLine = textLine.toLowerCase();
if (lcTextLine.contains(lcStr1) && lcTextLine.contains(lcStr2)) { // check if this line contains
detailOption
do {
System.out.println(textLine);
textLine = inFS.nextLine();
if (textLine.isEmpty()) {
bailOut = true;
}
} while (inFS.hasNextLine() && bailOut == false);
}
}
// Done with file, so try to close it
fileByteStream.close(); // close() may throw IOException if fails
}
}