Answer:
Here is the code to solve this question written in Java programming language.
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int hours;
float hourly_fee, payment;
System.out.println("Enter the amount of hours worked");
hours = in.nextInt();
System.out.println("Enter the fee per hour");
hourly_fee = in.nextFloat();
if(hours >= 0 && hours <= 40){
payment = straighttime(hours, hourly_fee);
}else{
payment = overtime(hours, hourly_fee);
}
printPayment(payment);
}
public static float overtime(int hours, float fee){
return(hours*fee*Float.parseFloat("1.25"));
}
public static float straighttime(int hours, float fee){
return(hours * fee);
}
public static void printPayment(float payment){
System.out.println("Your total payment is: "+payment);
}
}
Step-by-step explanation:
The commented code to solve this question is given below:
//Import the Scanner package to manage input from console.
import java.util.Scanner;
//Create the Main class
class Main {
//Create the static void method to execute the logic of the program
public static void main(String[] args) {
/*
Create an "in" object that manage the console inputs, declare the
variables to manage the hours and the payment. "int" and "float"
*/
Scanner in = new Scanner(System.in);
int hours;
float hourly_fee, payment;
System.out.println("Enter the amount of hours worked");
hours = in.nextInt();
System.out.println("Enter the fee per hour");
hourly_fee = in.nextFloat();
// Evaluate the conditions to call overtime or straighttime given that the hours are greater than 40.
if(hours >= 0 && hours <= 40){
payment = straighttime(hours, hourly_fee);
}else{
payment = overtime(hours, hourly_fee);
}
printPayment(payment);
}
public static float overtime(int hours, float fee){
/*
This method is of type float and returns the total payment multplied by 1.25 that is the extra fee for overtime.
*/
return(hours*fee*Float.parseFloat("1.25"));
}
public static float straighttime(int hours, float fee){
/*
This method is of type float and returns the total payment of straight hours.
*/
return(hours * fee);
}
public static void printPayment(float payment){
/*
This methods print out in the console the total payment.
*/
System.out.println("Your total payment is: "+payment);
}
}