Our teacher asks us to create a java program about the situation given which is the pay rate per hour using if/else this is what I came out with and Im happy about it (Im just a beginner). Then the next instruction is to replace the if/else with switch statements. He hasn't discussed switch statements yet. I try to search them but I couldn't understand. Please help. Much appreciated.
This is the exact instruction: 1.Using an if/else construct write a program that will calculate a persons pay based on the number of hours worked. Take note of the ff: The pay rate is Php 35 per hour. Any hours worked after 40 hours is paid at the rate of 1.5 times the normal hour rate. Calculate and display the normal pay, the overtime pay and the total pay. 2. Modify your previous work by replacing the if/else construct with the switch statement.
import java.util.Scanner;
public class Payment2 {
public static void main (String [] args){
Scanner input=new Scanner(System.in);
double hours;
double Prph = 35; //Prph means Pay rate per hour//
System.out.println("Enter your working hours:");
hours=input.nextDouble();
if (hours <= 40){
System.out.println("Your pay rate for the day is Php "+hours * Prph);
}
else if (hours > 40){
double Ovtime= hours - 40;
double NPay= hours * Prph;
double OvPay= Ovtime * 52.5;
System.out.println("Normal Pay: Php "+ NPay);
System.out.println("Overtime Pay: Php " + OvPay);
System.out.println("\nYour total pay rate is: Php "+ (NPay+OvPay));
}
}
}