Assignment:
Q: Modify the Payroll Program so that it uses a class to store and retrieve the employee's name, the hourly rate, and the number of hours worked. Use a constructor to initialize the employee information, and a method within that class to calculate the weekly pay. Once stop is entered as the employee name, the application should terminate. Make sure the program maintains all the functionality
Code:
CheckPoint: Payroll Program Part 1
Author: John Banks
Course: IT 215
Name: PPP1.java
Creation Date: December 07, 2008
Discription: The program uses the name of an employee, hourly rate and the working hours per week,
then calculate the weekly payment.
ref. chapter 2 page 37: Multiple -line comment
*/
import java.util.Scanner;public class PPP1 //Chapter 2 page 72:enables a program to read data for use in a program
//Chapter 2 page 48:program uses class Scanner
{
// main method begins execution of Java application chptr 2 page 37
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String name = null; //primitive types or built-in types chptr 2 page 49
double rate = 0.0; //primitive types or built-in types chptr 2 page 49
double hours = 0.0; //primitive types or built-in types chptr 2 page 49
while (true) {
System.out.print("Name of the employee: ");
name = scanner.nextLine();
if (name.equals("stop")) break;
do {
System.out.print("Hourly rate: ");
rate = scanner.nextDouble();
if (rate <= 0) System.out.println("You should input a positive number");
} while (rate<=0);
do {
System.out.print("Number of hours working: ");
hours = scanner.nextDouble();
if (hours <= 0) System.out.println("You should input a positive number");
} while (hours<=0);
double payment = rate * hours;
System.out.println("********* Result ********");
System.out.println("Name: " + name);
System.out.printf("Weekly payment: $%.2f\n", payment);
scanner.nextLine();
}
}
}