vendredi 24 février 2017

Java Variable counter increasing using loop statements

I need to write a program that finds the best time to meet using 4 inputs from 4 users. Each user will enter 1, 2, or 3 depending on the best time for them. 1 is 8:00-12:00, 2 is 12:00-18:00, and 3 is 18:00-23:00. At the end of the program, it will display the time that had the most inputs, or if two times had an equal amount of inputs, the earliest one. Here I'm not sure what to use really, at first I thought of using a very long series of if statements but that really doesn't work out here. I'm leaning toward using while statements but I don't know how to effectively use them and then take an input from the user and depending on that input (if it's 1, 2, or 3) adding it to a counter which will then be used to see which time had the most hits. Any help would be appreciated! Should I be using one variable for all of the inputs as well?

Scanner kbd=new Scanner(System.in);

    System.out.print("Meeting Times: \n"+"1) 8:00-12:00 2) 12:00-18:00 3) 18:00-23:00\n");
    System.out.print("\nChoose options 1, 2, or 3.\n");

    int p, morning=0, noon=0, evening=0;
    String first = "8:00-12:00", second="12:00-18:00",third="18:00-23:00";

    while (p>4){
        System.out.print("Enter the best time available for person 1.");
        p=kbd.nextInt();
        morning++;
    }kbd.close();

Aucun commentaire:

Enregistrer un commentaire