import java.util.Scanner;
import java.util.Scanner;
/**
This program demonstrates a solution to the
Payroll Class
*/
public class PayrollDemo
{
public static void main(String[] args)
{
// Variables for input
String name; // An employee's name
int id; // An employee's ID number
double payRate; // An employee's pay rate
double hoursWorked; // The number of hours worked
// Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);
// Get the employee's name.
System.out.print("Enter the employee's name: ");
name = keyboard.nextLine();
// Get the employee's ID number.
System.out.print("Enter the employee's ID number: ");
id = keyboard.nextInt();
// Get the employee's pay rate.
System.out.print("Enter the employee's hourly pay rate: ");
payRate = keyboard.nextDouble();
// Get the number of hours worked by the employee.
System.out.print("Enter the number of hours worked " +
" by the employee: ");
hoursWorked = keyboard.nextDouble();
// Create a Payroll object and store the data in it.
Payroll worker = new Payroll(name, id);
worker.setPayRate(payRate);
worker.setHoursWorked(hoursWorked);
// Display the employee's payroll data.
System.out.println("\nEmployee Payroll Data");
System.out.println("Name: " + worker.getName());
System.out.println("ID Number: " + worker.getIdNumber());
System.out.println("Hourly pay rate: " + worker.getPayRate());
System.out.println("Hours worked: " + worker.getHoursWorked());
System.out.println("Gross pay: $" + worker.getGrossPay());
}
}
can you do these following this instruction. Homework assignment 2: Page 756 in the testbook, problem number 5. Each of the exceptions should have a statement indicating what the error is so that when the getMessage() method is called in the Demo program it will printout which exception was thrown. Each exception class should be in a separate file.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps