197k views
4 votes
// Program prompts a user for name, hours worked,// and hourly pay rate// then computes gross pay and displays the name and gross pay// Modify the program to use four methods named// getName(), getHours(), getPayRate(), and computeGross()

1 Answer

0 votes

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
User Peter Lenkefi
by
2.9k points