jeudi 4 février 2016

Don't know where the issue is?

I'm having an issue with the output with this program. I'm getting an error message about converting from boolean to int, even though I don't see it. Is there a way I can use doubles in a switch statement or change over to if statements?

Scanner input = new Scanner(System.in);

    int hourlyWage = 0;
    int hour = 0;
    int grossPay = 0;

    System.out.print("Please enter the employee name: ");
    String name = input.nextLine();

    System.out.print("Please enter an hourly wage:$ ");
    hourlyWage = input.nextInt();

    System.out.println("Please enter the number of hours worked: ");
    hour = input.nextInt();

    final double OVERTIME = 1.5;
    final double REG_HOUR = 40;

    switch(hourlyWage){
    case (hourlyWage >= 7.25):
        if(hour <= 40){
            grossPay = hour * hourlyWage;
        }
        else if(hour > 40){
            grossPay = (int) ((int) (hour * hourlyWage) + ((hour - REG_HOUR) * (hourlyWage * OVERTIME)));
        }
        break;
    default:
        System.out.println("The wage entered is too low. Please try again.");
        System.exit(1);
        break;
    }

    System.out.println("");
    System.out.println("ABC Manufacturing Company");
    System.out.println("Name  Hours  Pay");
    System.out.printf("%s  %.2f  $%.2f", name, hour, grossPay);
}

}

Aucun commentaire:

Enregistrer un commentaire