In: Computer Science
Write and submit a test driver program employeeTest.java, the pseudocode is below.
start instantiate a Employee object get input from user for worker name loop while user does not enter "" Set workers name get input from user for employeeId set workers employeeId get input from user for shift (day/night) set workers shift (input "day" = true , input "night" = false) get input from user workers hourly pay set workers hourly pay get input from user total hours worked call workers PrintPayStub method get input from user for next worker name end loop end program
import java.util.Scanner;
class Employee
{
private String worker_name;
private int employeeId;
public Boolean shift;
public int hourly_pay;
public int total_hours;
public String getWorker_name() {
return worker_name;
}
public void setWorker_name(String worker_name) {
this.worker_name = worker_name;
}
public int getEmployeeId() {
return employeeId;
}
public void setEmployeeId(int employeeId) {
this.employeeId = employeeId;
}
public Boolean getShift() {
return shift;
}
public void setShift(Boolean shift) {
this.shift = shift;
}
public int getHourly_pay() {
return hourly_pay;
}
public void setHourly_pay(int hourly_pay) {
this.hourly_pay = hourly_pay;
}
public int getTotal_hours() {
return total_hours;
}
public void setTotal_hours(int total_hours) {
this.total_hours = total_hours;
}
public void printPayStub()
{
System.out.println("Worker Name:"+worker_name);
System.out.println("Worker id:"+employeeId);
int TotalPay=total_hours*hourly_pay;
System.out.println("Total pay:"+TotalPay);
}
}
public class EmployeeTest {
public static void main(String[] args)
{
String en,eShift;
int eid,etotal,ehourly;
Employee e=new Employee();
System.out.print("Enter worker name:");
Scanner sc=new Scanner(System.in);
en=sc.nextLine();
do
{
e.setWorker_name(en);
System.out.print("Enter employee id:");
eid=sc.nextInt();
e.setEmployeeId(eid);
Scanner sc1=new Scanner(System.in);
System.out.print("Enter worker shift (day/night):");
eShift=sc1.nextLine();
if(eShift=="day")
e.setShift(true);
else
e.setShift(false);
System.out.print("Enter worker Hourly pay:");
ehourly=sc1.nextInt();
e.setHourly_pay(ehourly);
System.out.print("Enter worker Total Hours:");
etotal=sc1.nextInt();
e.setTotal_hours(etotal);
e.printPayStub();
Scanner sc2=new Scanner(System.in);
System.out.print("Enter worker name:");
en=sc2.nextLine();
}while(en.equals(""));
}
}
In the printPayStub method i am printing employee name and employee id along with total pay.
Output
When worker name is "" , the program will gets terminated.