Employee DRIVER import java.util.Scanner; import java.text.NumberFormat; public
ID: 3772604 • Letter: E
Question
Employee DRIVER
import java.util.Scanner;
import java.text.NumberFormat;
public class Employee
{
//class constants
//class variable
private String name;
private int IdNumber;
private double HoursWorked;
private double HourlyRate;
private double GrossPay;
int[] empTotal = new int[3];
//*******************************************************************************************/
//Method Name : Employee(constructor)
//Author :
//Due Date : December 14, 2015
//Course/Section : CSC 111
//Program Description: This constructor will intialize the instance data
//to values passed in via the parameter list.
//
// BEGIN Employee
// initialize all instance data
// END Employee
//**********************************************************************************************/
public Employee( String inName, int inIdNumber, double inHoursWorked, double inHourlyRate)
{
//Initialize all instance data
name = inName;
IdNumber = inIdNumber;
HoursWorked = inHoursWorked;
HourlyRate = inHourlyRate;
}//end constructor
/*********************************************************************************************/
//Method Name : Calculate Pay
//Author :
//Due Date : December 14, 2015
//Course/Section : CSC 111
//Program Description: This constructor will calculate the pay
//
// BEGIN calculatePay
// Calculate Pay
// END calculatePay
//**********************************************************************************************/
public void calculatePay()
{
//local constants
//local variables
//***********************************************************************************************/
//Calculate Pay
if(HoursWorked <= 40)
GrossPay = HourlyRate * HoursWorked;
else if (HoursWorked <= 60)
GrossPay = 40 * HourlyRate + HourlyRate * 1.50 * (HoursWorked - 40);
else
GrossPay = HourlyRate + 20 * 1.20 * HourlyRate + HourlyRate * 2 * (HoursWorked - 60);
}
//*********************************************************************************************/
//Method Name : String toString
//Author :
//Due Date : December 14, 2015
//Course/Section : CSC 111
//Program Description: This constructor will intialize the instance data
//to values passed in via the parameter list.
//
// BEGIN toString
// Output String
// END toString
//**********************************************************************************************/
public String toString()
{
//local constants
//local variables
NumberFormat fmt = NumberFormat.getCurrencyInstance();
//***********************************************************************************************/
//Output String
return "Employeename " + name + " IdNumber :" +
IdNumber + " HoursWorked :" + HoursWorked +
" HourlyRate :" + fmt.format (HourlyRate)
+ " GrossPay :" + fmt.format(GrossPay);
}
}
Explanation / Answer
Answer:
Program code to copy:
//SalesPerson.java
import java.text.NumberFormat;
public class SalesPerson
{
private String name;
private int IdNumber;
private double BasicSalary;
private double TotalSales;
private double GrossPay;
public SalesPerson(String inName, int inIdNumber, double inBasicSalary,
double inTotalSales)
{
// Initialize all instance data
name = inName;
IdNumber = inIdNumber;
BasicSalary = inBasicSalary;
TotalSales = inTotalSales;
}// end constructor
public void calculatePay()
{
// Calculate Pay
if (TotalSales <= 1000)
GrossPay = TotalSales * 15 / 100 + BasicSalary;
else if (TotalSales > 1000 && TotalSales < 2000)
GrossPay = TotalSales * 20 / 100 + BasicSalary;
else
GrossPay = TotalSales * 25 / 100 + BasicSalary;
}
public String toString()
{
// Output String
NumberFormat fmt = NumberFormat.getCurrencyInstance();
return "Employeename " + name + " IdNumber :" + IdNumber
+ " BasicSalary :" + BasicSalary + " TotalSales :"
+ fmt.format(TotalSales) + " GrossPay :"
+ fmt.format(GrossPay);
}
public double getGrossPay()
{
return GrossPay;
}
public String getName()
{
return name;
}
public double getTotalSales()
{
return TotalSales;
}
public int getIdNumber()
{
return IdNumber;
}
}
//Employee.java
import java.text.NumberFormat;
public class Employee
{
private String name;
private int IdNumber;
private double HoursWorked;
private double HourlyRate;
private double GrossPay;
public Employee(String inName, int inIdNumber, double inHoursWorked,
double inHourlyRate)
{
// Initialize all instance data
name = inName;
IdNumber = inIdNumber;
HoursWorked = inHoursWorked;
HourlyRate = inHourlyRate;
}// end constructor
public void calculatePay()
{
// Calculate Pay
if (HoursWorked <= 40)
GrossPay = HourlyRate * HoursWorked;
else if (HoursWorked <= 60)
GrossPay = 40 * HourlyRate + HourlyRate * 1.50
* (HoursWorked - 40);
else
GrossPay = HourlyRate + 20 * 1.20 * HourlyRate + HourlyRate * 2
* (HoursWorked - 60);
}
public String toString()
{
// Output String
NumberFormat fmt = NumberFormat.getCurrencyInstance();
return "Employeename " + name + " IdNumber :" + IdNumber
+ " HoursWorked :" + HoursWorked + " HourlyRate :"
+ fmt.format(HourlyRate) + " GrossPay :"
+ fmt.format(GrossPay);
}
public double getGrossPay()
{
return GrossPay;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public int getIdNumber()
{
return IdNumber;
}
public void setIdNumber(int idNumber)
{
IdNumber = idNumber;
}
}
//MenuDriven.java
import java.util.Scanner;
public class MenuDriven
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
Employee e[] = new Employee[10];
SalesPerson sp[] = new SalesPerson[10];
menu(in, e, sp);
}
public static void menu(Scanner in, Employee e[], SalesPerson sp[])
{
String choice = "";
String name;
int cho = 0;
int IdNumber;
double HoursWorked;
double HourlyRate;
double BasicSalary;
double TotalSales;
int empcount = 0, salescount = 0;
Employee emp;
SalesPerson sperson;
double totalpayEmp = 0, totalpaySales = 0;
do
{
System.out.println(" Patty's Payroll Program");
System.out.println("Please choose from the following ");
System.out.println(" 1. Input Employee Data");
System.out.println(" 2. Input Sales Person Data");
System.out.println(" 3. Compute Total Payroll");
System.out.println(" 4. Print Report");
System.out.print(" Enter your choice: ");
cho = in.nextInt();
switch (cho)
{
case 1:
System.out
.println(" Enter the following Employee data: ");
System.out.print("Enter employee name: ");
name = in.next();
System.out.print("Enter employee id: ");
IdNumber = in.nextInt();
System.out.print("Enter employee hours worked: ");
HoursWorked = in.nextDouble();
System.out.print("Enter employee hourly rate: ");
HourlyRate = in.nextDouble();
emp = new Employee(name, IdNumber, HoursWorked,
HourlyRate);
emp.calculatePay();
e[empcount] = emp;
empcount++;
break;
case 2:
System.out
.println(" Enter the following Sales Person data: ");
System.out.print("Enter Sales Person name: ");
name = in.next();
System.out.print("Enter Sales Person id: ");
IdNumber = in.nextInt();
System.out.print("Enter Sales Person Basic salary: ");
BasicSalary = in.nextDouble();
System.out
.print("Enter Sales Person total items sold: ");
TotalSales = in.nextDouble();
sperson = new SalesPerson(name, IdNumber, BasicSalary,
TotalSales);
sperson.calculatePay();
sp[salescount] = sperson;
salescount++;
break;
case 3:
totalpayEmp = totalPayroll(e, empcount);
totalpaySales = totalPayroll(sp, salescount);
System.out.println(" Employees total pay roll is: "
+ totalpayEmp);
System.out.println("Sales person total pay roll is: "
+ totalpaySales);
break;
case 4:
printReport(e, empcount, sp, salescount);
break;
}
System.out.print("Would to like to continue: Press(y/Y)");
choice = in.next();
System.out.println();
} while (choice.equalsIgnoreCase("Y"));
}
public static void printReport(Employee[] e, int count, SalesPerson[] sp,
int scount)
{
System.out.println(" Employee details: ");
System.out.printf("%-20s %10s %13s($) %23s($) ", "Name", "IDNumber",
" GrossPay", "Pay roll for week ");
for (int i = 0; i < count; i++)
{
System.out.printf("%-20s %10d %15.2f %15.2f ", e[i].getName(),
e[i].getIdNumber(), e[i].getGrossPay(), e[i]
.getGrossPay() / 4);
}
System.out.println(" Sales Person details: ");
System.out.printf("%-20s %10s %13s($) %23s($) ", "Name", "IDNumber",
" GrossPay", "Pay roll for week ");
for (int i = 0; i < scount; i++)
{
System.out.printf("%-20s %10d %15.2f %15.2f ",
sp[i].getName(), sp[i].getIdNumber(), sp[i]
.getGrossPay(), sp[i].getGrossPay() / 4);
}
}
public static double totalPayroll(Employee[] e, int count)
{
double total = 0;
for (int i = 0; i < count; i++)
total += e[i].getGrossPay();
return total;
}
public static double totalPayroll(SalesPerson[] sp, int count)
{
double total = 0;
for (int i = 0; i < count; i++)
total += sp[i].getGrossPay();
return total;
}
}
Sample output:
Patty's Payroll Program
Please choose from the following
1. Input Employee Data
2. Input Sales Person Data
3. Compute Total Payroll
4. Print Report
Enter your choice: 1
Enter the following Employee data:
Enter employee name: Timothy
Enter employee id: 1234
Enter employee hours worked: 100
Enter employee hourly rate: 200
Would to like to continue: Press(y/Y)y
Patty's Payroll Program
Please choose from the following
1. Input Employee Data
2. Input Sales Person Data
3. Compute Total Payroll
4. Print Report
Enter your choice: 1
Enter the following Employee data:
Enter employee name: William
Enter employee id: 1902
Enter employee hours worked: 55
Enter employee hourly rate: 150
Would to like to continue: Press(y/Y)y
Patty's Payroll Program
Please choose from the following
1. Input Employee Data
2. Input Sales Person Data
3. Compute Total Payroll
4. Print Report
Enter your choice: 1
Enter the following Employee data:
Enter employee name: Quency
Enter employee id: 1900
Enter employee hours worked: 60
Enter employee hourly rate: 145
Would to like to continue: Press(y/Y)y
Patty's Payroll Program
Please choose from the following
1. Input Employee Data
2. Input Sales Person Data
3. Compute Total Payroll
4. Print Report
Enter your choice: 2
Enter the following Sales Person data:
Enter Sales Person name: Edward
Enter Sales Person id: 2233
Enter Sales Person Basic salary: 20000
Enter Sales Person total items sold: 1500
Would to like to continue: Press(y/Y)y
Patty's Payroll Program
Please choose from the following
1. Input Employee Data
2. Input Sales Person Data
3. Compute Total Payroll
4. Print Report
Enter your choice: 2
Enter the following Sales Person data:
Enter Sales Person name: WilliMarker
Enter Sales Person id: 2243
Enter Sales Person Basic salary: 30000
Enter Sales Person total items sold: 2500
Would to like to continue: Press(y/Y)y
Patty's Payroll Program
Please choose from the following
1. Input Employee Data
2. Input Sales Person Data
3. Compute Total Payroll
4. Print Report
Enter your choice: 3
Employees total pay roll is: 40525.0
Sales person total pay roll is: 50925.0
Would to like to continue: Press(y/Y)y
Patty's Payroll Program
Please choose from the following
1. Input Employee Data
2. Input Sales Person Data
3. Compute Total Payroll
4. Print Report
Enter your choice: 4
Employee details:
Name IDNumber GrossPay Pay roll for week
Timothy 1234 21000.00 5250.00
William 1902 9375.00 2343.75
Quency 1900 10150.00 2537.50
Sales Person details:
Name IDNumber GrossPay Pay roll for week
Edward 2233 20300.00 5075.00
WilliMarker 2243 30625.00 7656.25
Would to like to continue: Press(y/Y)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.