/** * The java Payroll that prompts user to enter * hourly rate of pay and number of hours worked. * Then calculates the gross pay and net pay * and print to console. * */ //Payroll.java import java.util.Scanner; public class Payroll { public static void main(String[] args) { //declare variables for hourly rate and hours worked double hourlyRate; int hoursWorked; //Set tax rate as 0.15 (15 percent ) final double WITH_HOLD_TAX=0.15; //Set grossPay=0 double grossPay=0; //Set tax =0 double tax=0; //Set netPay=0 double netPay=0; //Create an instance of Scanner class Scanner inputScanner =new Scanner(System.in); System.out.println(\"Enter hourly rate of pay\"); //prompt for hourly rate hourlyRate=Integer.parseInt(inputScanner.nextLine()); System.out.println(\"Enter number of hours worked\"); //prompt for number of hours hoursWorked=Integer.parseInt(inputScanner.nextLine()); //Calculate grossPay //multiply hoursWorked by hourlyRate grossPay=hoursWorked*hourlyRate; //calculate with hold tax tax=grossPay*WITH_HOLD_TAX; //calculate netPay //subtract tax from grossPay netPay=grossPay-tax; //print gross pay and net pay to console System.out.println(\"Gross Pay : \"+grossPay); System.out.println(\"Net pay : \"+netPay); } } --------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------- Sample output: Enter hourly rate of pay 10 Enter number of hours worked 50 Gross Pay : 500.0 Net pay : 425.0 Solution /** * The java Payroll that prompts user to enter * hourly rate of pay and number of hours worked. * Then calculates the gross pay and net pay * and print to console. * */ //Payroll.java import java.util.Scanner; public class Payroll { public static void main(String[] args) { //declare variables for hourly rate and hours worked double hourlyRate; int hoursWorked; //Set tax rate as 0.15 (15 percent ) final double WITH_HOLD_TAX=0.15; //Set grossPay=0 double grossPay=0; //Set tax =0 double tax=0; //Set netPay=0 double netPay=0; //Create an instance of Scanner class Scanner inputScanner =new Scanner(System.in); System.out.println(\"Enter hourly rate of pay\"); //prompt for hourly rate hourlyRate=Integer.parseInt(inputScanner.nextLine()); System.out.println(\"Enter number of hours worked\"); //prompt for number of hours hoursWorked=Integer.parseInt(inputScanner.nextLine()); //Calculate grossPay //multiply hoursWorked by hourlyRate grossPay=hoursWorked*hourlyRate; //calculate with hold tax tax=grossPay*WITH_HOLD_TAX; //calculate netPay //subtract tax from grossPay netPay=grossPay-tax; //print gross pay and net pay to console System.out.println(\"Gross Pay : \"+grossPay); System.out.println(\"Net pay : \"+netPay); } } --------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------- Sample output: E.