lundi 15 février 2021

Why is my program command failing to execute? [closed]

My program is built to have the user input the day of the week and the time. My if/else algorithm should produce an output based off the answers from the user input. It's a simple program, but I am struggling so hard with this... What should I fix?

I think up until the if/else statements, I'm golden. There seems to be an error in the if/else statements.

public static void main(String[] args) {
    Scanner keyboard = new Scanner(System.in);
    String UserInput;
    
  String dayOfTheWeek;
    //Prompt the user for the day of the week
    System.out.println("Enter the day of the week:");
    // Get the day of the week
    dayOfTheWeek = keyboard.nextLine();
    
    //Prompt user for the time of day
    System.out.println("Enter a time (XX:XXam/pm):");
    // Ge the time of day
    //Declare String variable for time
    String time = keyboard.nextLine();
    
    String shour = time.substring(0,2);
    String smin = time.substring(3,5);
    String am_pm = time.substring(5,7);
    
    System.out.println(shour = ":" +smin + "" + am_pm);
    
    //Now convert shour to int hours, and smin to int min

    int hour = Integer.parseInt(shour);
    int min = Integer.parseInt(smin);

    

    
    // Separate the time of day into hour, min, am or pm
     if (time.equalsIgnoreCase ( "pm")) {
        if (dayOfTheWeek.equalsIgnoreCase ("Monday") || dayOfTheWeek.equalsIgnoreCase("Mon")) { // include multiple statements
    // this ready hour is greater than or equal to 3 and hour is less than 5. for Min is great than or equal to 0 and less than of equal to 59 minutes
    if ((hour >= 3 && hour < 5) && (min >= 0 && min <=59)) {
        System.out.println("Monday");
        System.out.println("Available");
    } // end if
            }else if (dayOfTheWeek.equalsIgnoreCase ("Thursday") || dayOfTheWeek.equalsIgnoreCase("Thurs")); {
    if ((hour >= 3 && hour < 5) && (min >= 0 && min <=59)) {
        // need one more test
        // this needs to be less than 30 and it would be unavailable
        if ((hour == 3) && (min < 30)) {
        System.out.println("Thursday");
        System.out.println("Time not available");
        } else {
        System.out.println("Thursday");
        System.out.println("Available");
        }   
    } else { // else hours are out of range
        System.out.println("Thursday");
        System.out.println("Time not available");
    }
            } if (dayOfTheWeek.equalsIgnoreCase ("Friday") || dayOfTheWeek.equalsIgnoreCase("Fri")) {
    // need to test hour == 3 or hour == 4
    if ((hour == 3 || hour == 4) && (min >= 0 && min <=59)) {
        // need one more test
        //if (hour) == 4 and the min greater or equal 30 unavailable
        if ((hour == 4) && (min >= 30)) {
        System.out.println("Friday");
        System.out.println("Time not available");
            
        } else {
        System.out.println("Friday");
        System.out.println("Available");
        }   
    } else { // else hours are out of range
        System.out.println("Friday");
        System.out.println("Time not available");
    }
            } else { // the user enter day other than mon, thurs, or fri
        System.out.println("Days: Tuesday, Wednesday, Saturday, and Sunday");
        System.out.println("Time not available");
            }
            } else { // the user entered am
        System.out.println("Morning");
        System.out.println("Time not available");
            }
   
    
   
   
}

}

Aucun commentaire:

Enregistrer un commentaire