Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MonitoringSystem {
- /**
- * @param args the command line arguments
- * @throws java.io.IOException
- *
- */
- public static void main(String[] args) throws IOException {
- Scanner scnr = new Scanner(System.in);
- Scanner inFS = null;
- FileInputStream animals = null;
- FileInputStream habitats = null;
- BufferedReader reader = null;
- String monitorChoice = "";
- String animalChoice = "";
- String habitatChoice = "";
- String userInput = "";
- System.out.println("Would you like to monitor an Animal, Habitat, or exit?");
- monitorChoice = scnr.nextLine();
- if (monitorChoice.equals("Animal")) {
- System.out.println("Choose an animal to monitor: Lion, Tiger, Bear, or Giraffe.");
- animals = new FileInputStream("animals.txt");
- animalChoice = scnr.nextLine();
- File file = new File("animals.txt");
- BufferedReader br = new BufferedReader(new FileReader(file));
- String currentLine = br.readLine();
- while ((currentLine = br.readLine()) != null) {
- if (currentLine.contains(animalChoice)) {
- String nameline = br.readLine();
- String ageline = br.readLine();
- String healthline = br.readLine();
- String feedline = br.readLine();
- healthline = healthline.replaceAll("[*]", "");
- feedline = feedline.replaceAll("[*]", "");
- System.out.println(currentLine);
- System.out.println(nameline);
- System.out.println(ageline);
- System.out.println(feedline);
- System.out.println(healthline);
- System.out.println("Monitor another animal, return to main menu, or exit. Use keywords: Monitor, Main menu, or exit");
- userInput = scnr.nextLine();
- if (userInput.equals("Monitor")){
- System.out.println("Choose an animal to monitor: Lion, Tiger, Bear, or Giraffe.");
- return;
- }
- else if (userInput.equals("Main menu")){
- System.out.println("Would you like to monitor an Animal, Habitat, or exit");
- }
- else if (userInput.equals("exit")){
- System.out.println("Have a great day!");
- break;
- }
Add Comment
Please, Sign In to add comment