Developing a java program to show class design


Question:

Developing a Java program to show class design

Create a non-GUI based Java application that calculates weekly pay for an employee. The application should display text that requests the user input the name of the employee, the hourly rate, and the number of hours worked for that week. The application should then print out the name of the employee and the weekly pay amount. In the printout, display the dollar symbol ($) to the left of the weekly pay amount and format the weekly pay amount to display currency.

Pseudocodes:

import java.util.Scanner

start the main method
create a String variable to hold the value of the employee's name
create a double variable to hold the value of the hourly pay rate
create a double variable to hold the value of the number of hours worked
create a double variable to hold the result of the weekly pay calculation
create an instance of the Scanner and give it a name
using the System.out.print method, display a statement asking the user to enter
the employee's name
capture the name from the screen
using the System.out.print method, display a statement asking the user to enter
the hourly pay rate
capture the hourly pay rate from the screen
using the System.out.print method, display a statement asking the user to enter
the number of hours worked
capture the hours worked from the screen
calculate the weekly pay by multiplying the hourly pay rate times the number of
hours worked
using the System.out.printf method and format specifiers, display the
employee's name and weekly pay

//Payroll Program

import java.util.Scanner;

{

public static void main(String args[])
{
Employee emp = new Employee ();

// create Scanner to obtain input from command window
Scanner input = new Scanner(System.in);
String name;
double rate;
double hours;

System.out.print("Enter name: ");
emp.setName(input.next());
while (!emp.getName().equalsIgnoreCase("stop")) {
System.out.print("Enter payrate: "); // prompt
emp.setpayRate(input.nextDouble()); // read first number from user
while (emp.getpayRate() <= 0) {
System.out.println("Invalid, must be a positive number");
System.out.print("Please re-enter payrate: ");
emp.setpayRate(input.nextDouble());
}
System.out.print("Enter hours: "); // prompt
emp.sethours(input.nextDouble()); // read second number from user
while (emp.gethours() <= 0) {
System.out.println ("Invalid, must be a positive number");
System.out.print("Please re-enter hours: ");
emp.sethours(input.nextDouble());
}
System.out.printf("\n%s's weekly pay is $%.2f\n", emp.getName(), emp.getPay());
System.out.print("Enter name: ");
emp.setName(input.next());
}// end method main
} // end class Payroll

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Developing a java program to show class design
Reference No:- TGS01936406

Now Priced at $20 (50% Discount)

Recommended (94%)

Rated (4.6/5)