Answer:
import java.util.Scanner;
public class num3 {
public static void main(String[] args) {
// Calling ComputeGross pay and getName
System.out.println("Gross pay is for "+getName()+" is "+computGross());
}
// The method getName returns a string
public static String getName(){
System.out.println("Enter your name");
Scanner in = new Scanner(System.in);
String name = in.nextLine();
return name;
}
//method getHours returns an int
public static int getHours(){
System.out.println("Enter your hours");
Scanner in = new Scanner(System.in);
int hours = in.nextInt();
return hours;
}
//Method getPayRate returns a double
public static double getPayRate(){
System.out.println("Enter your pay rate");
Scanner in = new Scanner(System.in);
double payRate = in.nextDouble();
return payRate;
}
//Calculates and returns the gross pay by multiplying payrate by hours worked
public static double computGross(){
double gross = getHours()*getPayRate();
return gross;
}
}
Step-by-step explanation:
- This is solved in Java programming language
- Pay detailed attention to the comments in the solution
- A main method is created where getName and computGross are called inside the output statement
- Observe that the method computGross calls getHours and getPayRate within itself