SlideShare a Scribd company logo
What is the proper pseudocode for the following java code?
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 Zoo {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
//JOptionPane.showMessageDialog(null, "Alter Zookeeper Abnormal state");
//scanner class to read input from user
Scanner sc=new Scanner(System.in);
// buffered reader to read the file animal
BufferedReader brA=new BufferedReader(new FileReader("f://files/animals.txt"));
// bufferreader to read habitats
BufferedReader brH=new BufferedReader(new FileReader("f://files/habitats.txt"));
// to write to the file
BufferedWriter bwA=new BufferedWriter(new FileWriter("f://files/animals.txt",true));
BufferedWriter bwH=new BufferedWriter(new FileWriter("f://files/habitats.txt",true));
// for option
int option=0;
// loop while user exists
while(option!=3)
{
// reading animal and habitats
brA=new BufferedReader(new FileReader("f://files/animals.txt"));
brH=new BufferedReader(new FileReader("f://files/habitats.txt"));
// prompting user
System.out.println("Enter 1 to monitor Animals 2 for Habitats 3 to exit");
option=sc.nextInt();
// String to store details of animals and habitats
String[] details=null;
if(option==1)
{
//String for line
String line;
System.out.println("List of animals");
// variables for operactions and check blank lines
int op=0;
int blankLine=0;
int seperateSection=0;
int index=-1;
// loop through file
while((line=brA.readLine())!=null)
{
seperateSection=0;
// checking blank line
if(line.equals(""))
{
blankLine++;
if(blankLine==1)
{
// initializing array based on animals size
details=new String[op];
}
seperateSection=1;
// for array index
index++;
}
if(blankLine==0)
{
// printing info from file
op++;
System.out.println("Enter "+op+" for");
System.out.println(" "+line);
}
else if(blankLine!=0 && seperateSection==0)
{
// loading list to array
details[index]=details[index]+" "+line;
}
}
// closing stream
brA.close();
// printing the info
int choose=sc.nextInt();
System.out.println(details[choose-1]);
// if abnoramal alert box
if(details[choose-1].contains("****"))
{
// Alert box
JOptionPane.showMessageDialog(null, "Alter Zookeeper Abnormal state");
}
}
// For habitats same as above
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;
}
}
brH.close();
int choose=sc.nextInt();
System.out.println(details[choose-1]);
if(details[choose-1].contains("****"))
{
JOptionPane.showMessageDialog(null, "Alter Zookeeper Abnormal state");
}
}
// condition to exit
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());
}
}
}
Solution
This is a java gui code to add animals and their habitats information in the text files named
animals.txt and habitat.txt. The animals and their habitat information is stored in these files. The
user has to provide and option and depending on that the user will be adding/viewing the
contents of these files.
The pseudo code will consist of if else statements and logic to select the type of entry and
habitat.
Simple psuedo code will be
choose option 1) display 2)add
if(display)
Choose 1) animal 2)habitat and 3)exit
if (animal)
read txt animal
store into array
display
else if (habitat)
read txt habitat
store into array
display
else
exit
else
choose 1) to add animal 2) to add habitat 3) exit
if (animal)
add animal to txt
else if (habitat)
add habitat to txt
else
exit

More Related Content

PDF
JAVAAdd to the code at the bottom to do the following two things.pdf
PDF
The code you written is little bit confusing and lengthy. Here is th.pdf
PDF
Monitoring System As a zookeeper, is important to it know the activi.pdf
PDF
I need some help creating Psuedocode for a project using Java. Basic.pdf
DOCX
JAVA Please assist by providing pseudocode and functioning java
PDF
Eratosthenes Estimation of the Circumference of the Earth This que.pdf
PDF
Can we measure stress directlySolutionStress is defined as in.pdf
PDF
Find the derivative of the function y = e^xlnxSolution .pdf
JAVAAdd to the code at the bottom to do the following two things.pdf
The code you written is little bit confusing and lengthy. Here is th.pdf
Monitoring System As a zookeeper, is important to it know the activi.pdf
I need some help creating Psuedocode for a project using Java. Basic.pdf
JAVA Please assist by providing pseudocode and functioning java
Eratosthenes Estimation of the Circumference of the Earth This que.pdf
Can we measure stress directlySolutionStress is defined as in.pdf
Find the derivative of the function y = e^xlnxSolution .pdf

More from artimagein (20)

PDF
Explain which type of packet, TCP or UDP, is easier to spoof and why.pdf
PDF
Ella is a 15-year old high-school freshman. She lives in a small sub.pdf
PDF
Companies and people often buy and sell stocks. Often they buy th.pdf
PDF
What experiment could you run on fractions collected by differential.pdf
PDF
Write a C program Write functions that return the following values. .pdf
PDF
a. Name and explain the responsibilities of each MAC sub layer.b. .pdf
PDF
What is Binary Coded DecimalSolutionBinary Coded Decimal is a .pdf
PDF
What are ways in which brands cut through advertising clutterSo.pdf
PDF
What are cytoplasmic determinants What is the relevance of the yell.pdf
PDF
Urinalysis questions- What if SSA reaction tested negative What .pdf
PDF
The probability that John Doe is called to serve on a committee is ..pdf
PDF
answer sporophyte or gametophytewhich generation is a pine tree.pdf
PDF
Additional activity of this leads to reduced transport of iron to the.pdf
PDF
Significance of Discoveries in Genetics and DNA Our understanding of.pdf
PDF
Show Punnett squares for incomplete dominance in which a purple flowe.pdf
PDF
Polar populations. Suppose at each point on Earth you count the numb.pdf
PDF
Include a diagram supported by a detailed discussion explaining whic.pdf
PDF
loose one or I matching letters below. An Ill swer can be used once, .pdf
PDF
Prior to 1950, the death rate was high, which kept the numbers of hum.pdf
PDF
Please explain this in detail. Thank you.1. How would you test whe.pdf
Explain which type of packet, TCP or UDP, is easier to spoof and why.pdf
Ella is a 15-year old high-school freshman. She lives in a small sub.pdf
Companies and people often buy and sell stocks. Often they buy th.pdf
What experiment could you run on fractions collected by differential.pdf
Write a C program Write functions that return the following values. .pdf
a. Name and explain the responsibilities of each MAC sub layer.b. .pdf
What is Binary Coded DecimalSolutionBinary Coded Decimal is a .pdf
What are ways in which brands cut through advertising clutterSo.pdf
What are cytoplasmic determinants What is the relevance of the yell.pdf
Urinalysis questions- What if SSA reaction tested negative What .pdf
The probability that John Doe is called to serve on a committee is ..pdf
answer sporophyte or gametophytewhich generation is a pine tree.pdf
Additional activity of this leads to reduced transport of iron to the.pdf
Significance of Discoveries in Genetics and DNA Our understanding of.pdf
Show Punnett squares for incomplete dominance in which a purple flowe.pdf
Polar populations. Suppose at each point on Earth you count the numb.pdf
Include a diagram supported by a detailed discussion explaining whic.pdf
loose one or I matching letters below. An Ill swer can be used once, .pdf
Prior to 1950, the death rate was high, which kept the numbers of hum.pdf
Please explain this in detail. Thank you.1. How would you test whe.pdf
Ad

Recently uploaded (20)

PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Lesson notes of climatology university.
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PPTX
master seminar digital applications in india
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
RMMM.pdf make it easy to upload and study
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Complications of Minimal Access Surgery at WLH
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Cell Types and Its function , kingdom of life
PPTX
Presentation on HIE in infants and its manifestations
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Computing-Curriculum for Schools in Ghana
Lesson notes of climatology university.
102 student loan defaulters named and shamed – Is someone you know on the list?
Chinmaya Tiranga quiz Grand Finale.pdf
Final Presentation General Medicine 03-08-2024.pptx
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
master seminar digital applications in india
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
RMMM.pdf make it easy to upload and study
Microbial diseases, their pathogenesis and prophylaxis
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
Complications of Minimal Access Surgery at WLH
Supply Chain Operations Speaking Notes -ICLT Program
Cell Types and Its function , kingdom of life
Presentation on HIE in infants and its manifestations
Ad

What is the proper pseudocode for the following java codeimport j.pdf

  • 1. What is the proper pseudocode for the following java code? 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 Zoo { public static void main(String[] args) throws IOException { // TODO Auto-generated method stub //JOptionPane.showMessageDialog(null, "Alter Zookeeper Abnormal state"); //scanner class to read input from user Scanner sc=new Scanner(System.in); // buffered reader to read the file animal BufferedReader brA=new BufferedReader(new FileReader("f://files/animals.txt")); // bufferreader to read habitats BufferedReader brH=new BufferedReader(new FileReader("f://files/habitats.txt")); // to write to the file BufferedWriter bwA=new BufferedWriter(new FileWriter("f://files/animals.txt",true)); BufferedWriter bwH=new BufferedWriter(new FileWriter("f://files/habitats.txt",true)); // for option int option=0; // loop while user exists while(option!=3) { // reading animal and habitats brA=new BufferedReader(new FileReader("f://files/animals.txt")); brH=new BufferedReader(new FileReader("f://files/habitats.txt")); // prompting user System.out.println("Enter 1 to monitor Animals 2 for Habitats 3 to exit"); option=sc.nextInt();
  • 2. // String to store details of animals and habitats String[] details=null; if(option==1) { //String for line String line; System.out.println("List of animals"); // variables for operactions and check blank lines int op=0; int blankLine=0; int seperateSection=0; int index=-1; // loop through file while((line=brA.readLine())!=null) { seperateSection=0; // checking blank line if(line.equals("")) { blankLine++; if(blankLine==1) { // initializing array based on animals size details=new String[op]; } seperateSection=1; // for array index index++; } if(blankLine==0) { // printing info from file op++; System.out.println("Enter "+op+" for");
  • 3. System.out.println(" "+line); } else if(blankLine!=0 && seperateSection==0) { // loading list to array details[index]=details[index]+" "+line; } } // closing stream brA.close(); // printing the info int choose=sc.nextInt(); System.out.println(details[choose-1]); // if abnoramal alert box if(details[choose-1].contains("****")) { // Alert box JOptionPane.showMessageDialog(null, "Alter Zookeeper Abnormal state"); } } // For habitats same as above 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)
  • 4. { 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; } } brH.close(); int choose=sc.nextInt(); System.out.println(details[choose-1]); if(details[choose-1].contains("****")) { JOptionPane.showMessageDialog(null, "Alter Zookeeper Abnormal state"); } } // condition to exit else if(option==3)
  • 5. 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()); } } }
  • 6. Solution This is a java gui code to add animals and their habitats information in the text files named animals.txt and habitat.txt. The animals and their habitat information is stored in these files. The user has to provide and option and depending on that the user will be adding/viewing the contents of these files. The pseudo code will consist of if else statements and logic to select the type of entry and habitat. Simple psuedo code will be choose option 1) display 2)add if(display) Choose 1) animal 2)habitat and 3)exit if (animal) read txt animal store into array display else if (habitat) read txt habitat store into array display else exit else choose 1) to add animal 2) to add habitat 3) exit if (animal) add animal to txt else if (habitat) add habitat to txt else exit