dimanche 16 décembre 2018

Java Final Project Animal Monitoring System

Alright so I've built this code for my final project in this Java class. The instructions given are as follows:

Option 2: Monitoring System As a zookeeper, it is important to know the activities of the animals in your care and to monitor their living habitats. Create a monitoring system that does all of the following:

Asks a user if they want to monitor an animal, monitor a habitat, or exit Displays a list of animal/habitat options (based on the previous selection) as read from either the animals or habitats file

Asks the user to enter one of the options

  • Displays the monitoring information by finding the appropriate section in the file

  • Separates sections by the category and selection (such as “Animal - Lion” or “Habitat -Penguin”)

  • Uses a dialog box to alert the zookeeper if the monitor detects something out of the normal range (These will be denoted in the files by a new line starting with *****. Do not display the asterisks in the dialog.)

  • Allows a user to return to the original options

The code I've developed is as follows:

import java.util.Scanner;



public class Final {


static final Scanner scan = new Scanner(System.in);


public static void main(String args[]) {

    System.out.println("Menu:");

    System.out.println("Monitor Animal");

    System.out.println("Monitor Habitat");

    System.out.println("Exit");



Scanner input1 = new Scanner(System.in);

String userInput1 = input1.nextLine();



    if (userInput1.equals("Monitor Animal")); {

        System.out.println("Details on lions");

        System.out.println("Details on tigars");

        System.out.println("Details on bears");

        System.out.println("Details on giraffes");

        System.out.println("Exit");



        Scanner input2 = new Scanner(System.in);

        String userInput2 = input2.nextLine();



        switch(userInput2) {

            case 1: userInput2 = "Details on lions";

                System.out.println("Animal - Lion");

                System.out.println("Name: Leo");

                System.out.println("Age: 5");

                System.out.println("Health concerns: Cut on left front paw");

                System.out.println("Feeding schedule: Twice daily");

                break;



            case 2: userInput2 = "Details on tigers";

                System.out.println("Animal - Tigar");

                System.out.println("Name: Maj");

                System.out.println("Health concerns: None");

                System.out.println("Feeding schedule: 3x daily");

                break;



            case 3: userInput2 = "Details on bears";

                System.out.println("Animal - Bear");

                System.out.println("Name: Baloo");

                System.out.println("Age: 1");

                System.out.println("Health concerns: None");

                System.out.println("Feeding schedule: None on record");

                break;



            case 4: userInput2 = "Details on giraffes";

                System.out.println("Animal - Giraffe");

                System.out.println("Name: Spots");

                System.out.println("Age: 12");

                System.out.println("Health concerns: None");

                System.out.println("Feeding schedule: Grazing");

                break;



            case 5: userInput2 = "Exit";

                break;



            default: userInput2 = System.out.println("Error: Invalid Animal");

                break;

            }



    if (userInput1.equals("Monitor Habitat")); {

        System.out.println("Details on penguin habitat");

        System.out.println("Details on bird house");

        System.out.println("Details on aquarium");

        System.out.println("Exit");



        Scanner input3 = new Scanner(System.in);

        String userInput3 = input3.nextLine();



        switch(userInput3) {



            case 1: userInput3 = "Details on penguin habitat";

                System.out.println("Habitat - Penguin");

                System.out.println("Temperature: Freezing");

                System.out.println("Food source: Fish in water running low");

                System.out.println("Cleanliness: Passed");

                break;



            case 2: userInput3 = "Details on bird house";

                System.out.println("Habitat - Bird");

                System.out.println("Temperature: Moderate");

                System.out.println("Food source: Natural from environment");

                System.out.println("Cleanliness: Passed");

                break;



            case 3: userInput3 = "Details on aquarium";

                System.out.println("Habitat - Aquarium");

                System.out.println("Temperature: Varies with output temperature");

                System.out.println("Food source: Added daily");

                System.out.println("Cleanliness: Needs cleaning from algae");

                break;



            case 4: userInput3 = "Exit";

                break;



            default: System.out.println("Error: Invalid Habitat");

                break;
    }



    if (userInput1.equals("Exit")); {

        System.out.println("Goodbye!");


    }

  }
}

It won't compile and I can't figure out what I'm doing wrong. Is there a better way to do this? I've been trying for a day and a half and now it's due in about 3 hours. Any help will be appreciated!

Aucun commentaire:

Enregistrer un commentaire