lundi 7 novembre 2016

How to get program to loop user input?

So in this program i am writing for class is to check flight dates and such. I have it nearly done theres just one part that stumping me. I'm supposed to make a while loop to keep a prompt that keeps asking until the flight day matches the current day. My while loop doesnt seem to work and I am confused as to what I am doing wrong.

        public static void main(String[] args)
        {
                Scanner stdIn = new Scanner(System.in);
                String dayOfFlight; //Day of your flight
                String currentDay; //What day it is now
                int hourOfFlight; //when flight is
                int currentHour; // current hour 
                
                
                System.out.print("When is the day of your flight? (Monday - Friday): ");
                dayOfFlight = stdIn.next();
                System.out.print("What hour does your flight leave? (Military Time): ");
                hourOfFlight = stdIn.nextInt();
                System.out.print("What is the current day?: ");
                currentDay = stdIn.next();
                

                while (currentDay != dayOfFlight)
                {
                        if (currentDay != dayOfFlight)
                        {
                                System.out.println("Today isn't your flight, keep checking.");
                        }
                        System.out.print("What is the current day?: ");
                        currentDay = stdIn.next();
                        break;
                }
                System.out.print("What is the current the current hour? ");
                currentHour = stdIn.nextInt();
                
                switch (hourOfFlight - currentHour)
                {
                        case 17: case 18: case 19: case 20: case 21: case 22: case 23:
                                System.out.println("Are you seriously checking this early?");
                                break;
                        case 16: case 15: case 14: case 13: case 12: case 11: case 10:
                        case 9: case 8: case 7: case 6: case 5: 
                                System.out.println("Plenty of time, no need to rush.");
                                break;
                        case 4: case 3: 
                                System.out.println("Better be heading to the airport.");
                                break;
                        case 2:
                                System.out.println("Hope you are at the airport.");
                                break;
                        case 1:
                                System.out.println("You best be at the airport, security lines are long.");
                                break;
                        default:
                                System.out.println("Hopefully you made your flight.");
                } //end switch
                System.out.println("Thanks for planning your trip with us.");
        } //end main

When I run it the != doesn't seem to work and it gives me the "Today isn't your flight" regardless of what I put in and then it prompts me input the current day again which I type random stuff and it accepts it and moves on to the next question. What am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire