What is the proper pseudocode for the following java code im

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

What is the proper pseudocode for the following java code? import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; i
What is the proper pseudocode for the following java code? import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; i
What is the proper pseudocode for the following java code? import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; i
What is the proper pseudocode for the following java code? import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; i

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site