Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, I am working on a java zoo monitoring program and I keep getting an error. can someone help? here is my code... /* *

Hello, I am working on a java zoo monitoring program and I keep getting an error. can someone help?

here is my code...

/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package zoomonitor;

//ZooMonitor.java import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; import javax.swing.JOptionPane;

public class ZooMonitor {

//Create an instance of Scanner class private static Scanner scanner = new Scanner(System.in);

public static void main(String[] args) {

while (true) {

//calling menu method int ch = menu();

Scanner filereader = null;

//For animals if (ch == 1) { //calling selectanimal int animal = selectanimal(); String animalType = ""; String animalName = ""; try {

//opening animals.txt file filereader = new Scanner(new File("C:\\Users\\arpec\\Documents\\NetBeansProjects\\ZooMonitor\\src\\zoomonitor\\animals.txt"));

switch (animal) { case 1: animalName = "Animal-Lion"; break; case 2: animalName = "Animal-Tiger"; break; case 3: animalName = "Animal-Bear"; break; case 4: animalName = "Animal-Giraffe"; break; }

boolean repeat = true; while (filereader.hasNextLine() && repeat) { animalType = filereader.nextLine(); if (animalType.equals(animalName)) { repeat = false; } }

String name = filereader.nextLine(); String age = filereader.nextLine();

String health = filereader.nextLine(); String feed = filereader.nextLine();

//checking if health or feed contains any concerns if (health.contains("*****")) { JOptionPane.showMessageDialog(null, health, "Warning : " + animalType, JOptionPane.INFORMATION_MESSAGE); } else if (feed.contains("*****")) { JOptionPane.showMessageDialog(null, feed, "Warning : " + animalType, JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane.showMessageDialog(null, "No health concerns"); }

} catch (FileNotFoundException e) { System.out.println(e.getMessage()); } } //For habitats else if (ch == 2) { int animal = selecthabitat(); String animalType = ""; String animalName = ""; try {

filereader = new Scanner(new File("C:\\Users\\arpec\\Documents\\NetBeansProjects\\ZooMonitor\\src\\zoomonitor\\habitats.txt"));

switch (animal) { case 1: animalName = "Habitat - Penguin"; break; case 2: animalName = "Habitat - Bird"; break; case 3: animalName = "Habitat - Aquarium"; break; }

boolean repeat = true; while (filereader.hasNextLine() && repeat) { animalType = filereader.nextLine(); if (animalType.equals(animalName)) { repeat = false; } }

String temperature = filereader.nextLine(); String food = filereader.nextLine(); String cleanliness = filereader.nextLine();

//checking if temperature,food or cleaniness contains any concerns if (temperature.contains("*****")) { JOptionPane.showMessageDialog(null, temperature, "Warning : " + animalType, JOptionPane.INFORMATION_MESSAGE); } else if (food.contains("*****")) { JOptionPane.showMessageDialog(null, food, "Warning : " + animalType, JOptionPane.INFORMATION_MESSAGE); } else if (cleanliness.contains("*****")) { JOptionPane.showMessageDialog(null, cleanliness, "Warning : " + animalType, JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane.showMessageDialog(null, "No health concerns"); }

} catch (FileNotFoundException e) { System.out.println(e.getMessage()); } } else { //close the appliation System.out.println("Good Bye!"); System.exit(0);

} } }

//Method to select a habitat private static int selecthabitat() { System.out.println("1.Habitat - Penguin "); System.out.println("2.Habitat - Bird"); System.out.println("3.Habitat - Aquarium");

System.out.println("Enter your choice"); int choice = Integer.parseInt(scanner.nextLine());

return choice;

}

//method to select an animal private static int selectanimal() {

System.out.println("1.Animal - Lion"); System.out.println("2.Animal - Tiger"); System.out.println("3.Animal - Bear"); System.out.println("4.Animal - Giraffe");

System.out.println("Enter your choice"); int choice = Integer.parseInt(scanner.nextLine());

return choice; }

private static int menu() {

System.out.println("1.Monitor animal"); System.out.println("2.Monitor habitat"); System.out.println("3.Exit");

int choice = Integer.parseInt(scanner.nextLine());

return choice;

}

}

my error is...

Exception in thread "main" java.util.NoSuchElementException: No line found at java.util.Scanner.nextLine(Scanner.java:1540) at zoomonitor.ZooMonitor.main(ZooMonitor.java:62) C:\Users\arpec\AppData\Local\NetBeans\Cache\8.2\executor-snippets un.xml:53: Java returned: 1 BUILD FAILED (total time: 2 seconds)

Thanks for your help

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

1 2 3 Data Base Techniques

Authors: Dick Andersen

1st Edition

0880223464, 978-0880223461

More Books

Students also viewed these Databases questions