Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Break down the problem statement into programming terms through creation of pseu

ID: 3586839 • Letter: B

Question

Break down the problem statement into programming terms through creation of pseudocode.


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
import javax.swing.JOptionPane;

public class Monitoringsystem {
public static void main(String[] args) throws IOException
{ Scanner sc=new Scanner(System.in);
BufferedReader brA=new BufferedReader(new FileReader("g://files/animals.txt"));
BufferedReader brH=new BufferedReader(new FileReader("g://files/habitats.txt"));
BufferedWriter bwA=new BufferedWriter(new FileWriter("g://files/animals.txt",true));
BufferedWriter bwH=new BufferedWriter(new FileWriter("g://files/habitats.txt",true));
int option=0; while(option!=3) { brA=new BufferedReader(new FileReader("g://files/animals.txt"));
brH=new BufferedReader(new FileReader("g://files/habitats.txt"));
System.out.println("Enter 1 to monitor Animals 2 for Habitats 3 to exit");
option=sc.nextInt(); String[] details=null; if(option==1) { String line; System.out.println("List of animals");
int op=0; int blankLine=0;
int seperateSection=0; int index=-1;
while((line=brA.readLine())!=null) { seperateSection=0; if(line.equals("")) { blankLine++;
if(blankLine==1) { details=new String[op];
}
seperateSection=1; index++;
}
if(blankLine==0) { op++;
System.out.println("Enter "+op+" for");
System.out.println(" "+line);
} else if(blankLine!=0 && seperateSection==0) { details[index]=details[index]+" "+line;
}
}
brA.close(); int choose=sc.nextInt();
System.out.println(details[choose-1]);
if(details[choose-1].contains("****")) { JOptionPane.showMessageDialog(null, "Alter Zookeeper Abnormal state");
}
}
else if (option==2) { String line;
System.out.println("List of Habitats");
int op=0;
int blankLine=0;
int seperateSection=0;
int index=-1;
while((line=brH.readLine())!=null) { seperateSection=0;
if(line.equals("")) { blankLine++;
if(blankLine==1) { details=new String[op];
}
seperateSection=1; index++;
}
if(blankLine==0) { op++; System.out.println("Enter "+op+" for");
System.out.println(" "+line);
}
else if(blankLine!=0 && seperateSection==0) { details[index]=details[index]+" "+line;
}
}

System.out.println(details[choose-1]);
if(details[choose-1].contains("****")) { JOptionPane.showMessageDialog(null, "Alter Zookeeper Abnormal state");
}
}
else if(option==3) System.out.println("good bye");
else System.out.println("Wrong option");
}
System.out.println("Enter 1 to Add Animal 2 to add Habitat 3 to no");
int ch=sc.nextInt(); if(ch==1) { bwA.newLine();
System.out.println("Enter animal name:");
bwA.write("Animal - "+sc.next());
System.out.println("Enter keeper name");
bwA.write(sc.next());
System.out.println("Enter age:");
bwA.write(sc.next());
System.out.println("Enter health report");
bwA.write(sc.next());
}
if(ch==2) { bwH.newLine();
System.out.println("Enter habitat name:");
bwA.write("Habitat - "+sc.next());
System.out.println("Enter keeper name");
bwA.write(sc.next());
System.out.println("Enter age:");
bwA.write(sc.next());
System.out.println("Enter health report");
bwA.write(sc.next());
}
}
}

Explanation / Answer

Commented code:

//header files
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
import javax.swing.JOptionPane;

// Monitoringsystem Class
public class Monitoringsystem {
public static void main(String[] args) throws IOException
{
//read the input from keyboard
Scanner sc=new Scanner(System.in);
//read the file "animals.txt"
BufferedReader brA=new BufferedReader(new FileReader("g://files/animals.txt"));
//read the file "habitats.txt"
BufferedReader brH=new BufferedReader(new FileReader("g://files/habitats.txt"));
//writes to the file "animals.txt"
BufferedWriter bwA=new BufferedWriter(new FileWriter("g://files/animals.txt",true));
//writes to the file "habitats .txt"
BufferedWriter bwH=new BufferedWriter(new FileWriter("g://files/habitats.txt",true));
//checks for exit condition
int option=0;
while(option!=3)
{

brA=new BufferedReader(new FileReader("g://files/animals.txt"));
brH=new BufferedReader(new FileReader("g://files/habitats.txt"));
//Menu for options
System.out.println("Enter 1 to monitor Animals 2 for Habitats 3 to exit");
//check the option
option=sc.nextInt();
String[] details=null;
//if option is 1 it displays the list of animals nd displays in the message dialogue box
if(option==1)
{
String line;
System.out.println("List of animals");
int op=0; int blankLine=0;
int seperateSection=0; int index=-1;
while((line=brA.readLine())!=null) {
seperateSection=0; if(line.equals(""))
{ blankLine++;
if(blankLine==1) { details=new String[op];
}
seperateSection=1; index++;
}
if(blankLine==0) { op++;
System.out.println("Enter "+op+" for");
System.out.println(" "+line);
} else if(blankLine!=0 && seperateSection==0) { details[index]=details[index]+" "+line;
}
}
//close the file
brA.close(); int choose=sc.nextInt();
System.out.println(details[choose-1]);
if(details[choose-1].contains("****")) { JOptionPane.showMessageDialog(null, "Alter Zookeeper Abnormal state");
}
}
//checks if choice2 it klists the habitats in the message box
else if (option==2) { String line;
System.out.println("List of Habitats");
int op=0;
int blankLine=0;
int seperateSection=0;
int index=-1;
while((line=brH.readLine())!=null) { seperateSection=0;
if(line.equals("")) { blankLine++;
if(blankLine==1) { details=new String[op];
}
seperateSection=1; index++;
}
if(blankLine==0) { op++; System.out.println("Enter "+op+" for");
System.out.println(" "+line);
}
else if(blankLine!=0 && seperateSection==0) { details[index]=details[index]+" "+line;
}
}

System.out.println(details[choose-1]);
if(details[choose-1].contains("****")) { JOptionPane.showMessageDialog(null, "Alter Zookeeper Abnormal state");
}
}
//if choice is 3 the appiication exits
else if(option==3) System.out.println("good bye");
else System.out.println("Wrong option");
}
//seperaet options for adding the animals,habitats.
System.out.println("Enter 1 to Add Animal 2 to add Habitat 3 to no");
int ch=sc.nextInt(); if(ch==1) { bwA.newLine();
//takes animal name
System.out.println("Enter animal name:");
bwA.write("Animal - "+sc.next());
//takes keeper name
System.out.println("Enter keeper name");
bwA.write(sc.next());
//takes age
System.out.println("Enter age:");
bwA.write(sc.next());
//takes health report
System.out.println("Enter health report");
bwA.write(sc.next());
}
if(ch==2) { bwH.newLine();
takes habitat name
System.out.println("Enter habitat name:");
bwA.write("Habitat - "+sc.next());
//take s keeper name
System.out.println("Enter keeper name");
bwA.write(sc.next());
System.out.println("Enter age:");
bwA.write(sc.next());
System.out.println("Enter health report");
bwA.write(sc.next());
}
}
}

Pseudocode:

1.start
2.Read the files "animals.txt" and "habitats.txt" and write to the files "animals.txt" and "habitats.txt"
3.Create menu driven code which has 3 options(1.Monitor animals, 2.Monitor habitats, 3.Exit)
4.if option is 1 read the file "animals.txt" and display the contents in dialogue box (Gui)
5.if option is 2 read the file "habitats.txt" and display the contents in dialogue box (Gui)
6.if option is 3 exit
7.Menu for adding animals,habitats
8.If choice is 1 then add the animals by saving details like animal name,keeper name,age,health report
9.If choice is 2 then add the habitats by saving details like habitat name,keeper name,age,health report
10.If choice 3 exit
11.stop