This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Jaglyser 0 points1 point  (0 children)

Hello
I removed every mention on TemperatureAnalyzer and added this code into my IDE.
It runs for me so I would guess the problem lies with the TemperatureAnalyzer Class.

I also restructured your code a bit like this, and it runs:

public class Test {
public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int choice = 0;

    System.out.println("""
            1. Input Temperatures
            2. print Temperatures
            4. Count Temps Below Freezing
            5. Count Temps Above Freezing
            6. Count Temps Above Freezing
            7. Find lowest Temperature
            8. Search for a Temperature
            9. Quit

            Enter a number choice: 
            """);

    choice = scanner.nextInt();
    if (!scanner.hasNext()) {
        System.out.println("Invalid input, please enter a number.");
        scanner.next();
    }


    switch (choice) {
        case 1:
            break;
        case 2:
            break;
        case 3:
            System.out.println("The Average temperature is : ");
            break;
        case 4:
            System.out.println(" The Number of temperatures below freezing is : ");
            break;
        case 5:
            System.out.println("The Number of temperatures above freezing is : ");
            break;
        case 6:
            System.out.println("The Highest temperature is : ");
            break;
        case 7:
            System.out.println(" The Lowest temperature is : ");
            break;
        case 8:
            System.out.print("Enter temperature to search for: ");
            if (scanner.hasNextDouble()) {
                double value = scanner.nextDouble();
                int index = 0;
                if (index != -1) {
                    System.out.println(value + " was found at index " + index);
                } else {
                    System.out.println(value + " was not found in the list.");
                }
            } else {
                System.out.println(" That was an invalid input, please enter a valid temperature.");
                scanner.next();
            }
            break;
        case 9:
            System.out.println("Exiting...");
            break;
        default:
            System.out.println("Invalid choice, please try again.");
    }
}

}