Guest User

Untitled

a guest
Oct 19th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. public class MonitoringSystem {
  2.  
  3.  
  4. /**
  5. * @param args the command line arguments
  6. * @throws java.io.IOException
  7. *
  8. */
  9. public static void main(String[] args) throws IOException {
  10. Scanner scnr = new Scanner(System.in);
  11. Scanner inFS = null;
  12. FileInputStream animals = null;
  13. FileInputStream habitats = null;
  14. BufferedReader reader = null;
  15. String monitorChoice = "";
  16. String animalChoice = "";
  17. String habitatChoice = "";
  18. String userInput = "";
  19.  
  20.  
  21. System.out.println("Would you like to monitor an Animal, Habitat, or exit?");
  22. monitorChoice = scnr.nextLine();
  23.  
  24.  
  25. if (monitorChoice.equals("Animal")) {
  26. System.out.println("Choose an animal to monitor: Lion, Tiger, Bear, or Giraffe.");
  27. animals = new FileInputStream("animals.txt");
  28. animalChoice = scnr.nextLine();
  29. File file = new File("animals.txt");
  30. BufferedReader br = new BufferedReader(new FileReader(file));
  31.  
  32. String currentLine = br.readLine();
  33. while ((currentLine = br.readLine()) != null) {
  34. if (currentLine.contains(animalChoice)) {
  35. String nameline = br.readLine();
  36. String ageline = br.readLine();
  37. String healthline = br.readLine();
  38. String feedline = br.readLine();
  39.  
  40. healthline = healthline.replaceAll("[*]", "");
  41. feedline = feedline.replaceAll("[*]", "");
  42.  
  43. System.out.println(currentLine);
  44. System.out.println(nameline);
  45. System.out.println(ageline);
  46. System.out.println(feedline);
  47. System.out.println(healthline);
  48.  
  49. System.out.println("Monitor another animal, return to main menu, or exit. Use keywords: Monitor, Main menu, or exit");
  50. userInput = scnr.nextLine();
  51.  
  52. if (userInput.equals("Monitor")){
  53. System.out.println("Choose an animal to monitor: Lion, Tiger, Bear, or Giraffe.");
  54. return;
  55. }
  56. else if (userInput.equals("Main menu")){
  57. System.out.println("Would you like to monitor an Animal, Habitat, or exit");
  58. }
  59. else if (userInput.equals("exit")){
  60. System.out.println("Have a great day!");
  61. break;
  62. }
Add Comment
Please, Sign In to add comment