Question

In: Computer Science

Exercise 2: A company runs a small factory. You need to create apay slip for...

Exercise 2: A company runs a small factory. You need to create a pay slip for the employees of the company. The details of the Java application to be implemented is provided below.

A. The factory workers are paid one of the three hourly rates depending on their skill level.

 Write a method to that takes the skill level as a parameter and returns the hourly rate. Use the switch construct in Java.

B. Each factory worker might work any number of hours per week; any hour over 40 are paid at double rate.

 Write a method that takes the hours worked and calculates the gross pay depending on if there is overtime or not. Return the gross pay from the method.

Skill Level

Hourly Rate (dirham)

A

50

B

40

C

30

C. Factory workers have extra benefits. Only workers in skill level A can choose to participate in the Retirement Plan at 5% of their gross pay. Also, The workers in all skill levels can choose to participate in the following insurance options:

Option

Explanation

Weekly Cost to Employee (dirham)

1

Medical Insurance

73

2

Dental Insurance

35

3

Disability Insurance

20

 Write a method that takes the worker’s skill level and gross pay as parameter and asks the user the necessary questions to decide on benefits (Insurance and/or Retirement). The user must be given the choice to choose all three types of Insurances. The method must return the net pay after deducting the benefits if the worker chooses to opt for these benefits.

  1. Ask the user to enter the details of all employees. The details include: Employee ID, Name, Skill level, and Hourly Pay should entered in the main method. The Retirement and Insurance benefits should be asked from the User in the above method.

  2. Generate a pay slip for each employee i.e. if the user enters 10 employees, then 10 pay slips are to be generated. Each pay slip is written to a separate file with the name given as the employee id. For example: if the employee id is A11P9, then the file “A11P9.txt” will contain the pay slip of the employee. The pay slip for each worker must contain the following details in a neat and readable format.

    •  The ID, Name, and skill level of the Factory Worker

    •  The total number of working hours of the factory worker

    •  The overtime hours

    •  The hourly rate

    •  The gross pay of a factory worker i.e. before the deductions

    •  The total deductions i.e. the retirement and insurance benefits

    •  The net pay i.e. Gross pay – Total deductions

Solutions

Expert Solution

Code

import java.io.FileWriter;
import java.util.Scanner;
public class EmployeePayslip
{   
private String id,name,skillLevel;
private int hours,rate;
private double netPay,deduction,grossPay;
public EmployeePayslip() {
  
  
}
  
public void setNetPay(double netPay) {
this.netPay = netPay;
}
  
public void setDeduction(double deduction) {
this.deduction = deduction;
}

public void setGrossPay(double grossPay) {
this.grossPay = grossPay;
}

public double getNetPay() {
return netPay;
}

public double getDeduction() {
return deduction;
}

public double getGrossPay() {
return grossPay;
}
  
public EmployeePayslip(String id, String name, String skillLevel, int hours) {
this.id = id;
this.name = name;
this.skillLevel = skillLevel;
this.hours = hours;
}

public String getId() {
return id;
}

public String getName() {
return name;
}

public String getSkillLevel() {
return skillLevel;
}

public int getHours() {
return hours;
}
  
  
public static void main(String[] args)
{
int totalEmployee,hr;
String name,id;
String lvl;
Scanner sc=new Scanner(System.in);
EmployeePayslip []emp;
System.out.print("Enter the total number of emplyee worked: ");
totalEmployee=sc.nextInt();
emp=new EmployeePayslip[totalEmployee];
for(int i=0;i {
System.out.print("Enter the Employee id: ");
id=sc.next();
System.out.print("Enter the Employee name: ");
name=sc.next();
System.out.print("Enter the Employee skill Level(A,B or C): ");
lvl=sc.next();
System.out.print("Enter the Employee's number of hours per week: ");
hr=sc.nextInt();
emp[i]=new EmployeePayslip(id, name, lvl, hr);
emp[i].setGrossPay(calculateGrosspay(emp[i]));
double netPay=calculateNetPay(emp[i].getSkillLevel(),emp[i].getGrossPay());
emp[i].setNetPay(netPay);
emp[i].setDeduction(emp[i].getGrossPay()-emp[i].getNetPay());
System.out.println("");
}
printPaySlip(emp);
}
private static void printPaySlip(EmployeePayslip[] emp)
{
for(int i=0;i {
try
{
FileWriter fw=new FileWriter(emp[i].getId()+".txt");
fw.write(emp[i].getId()+" "+emp[i].getName()+" "+emp[i].getSkillLevel()+"\r\n");
fw.write(emp[i].getHours()+"\r\n");
if(emp[i].getHours()>40)
fw.write((emp[i].getHours()-40)+"\r\n");
else
fw.write(0+"\r\n");
fw.write( emp[i].rate+"\r\n");
fw.write(emp[i].getGrossPay()+"\r\n");
fw.write(emp[i].getDeduction()+"\r\n");
fw.write(emp[i].getNetPay()+"\r\n");
fw.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
System.out.println("\nAll payslip are genrated.......");
}
  
private static double calculateGrosspay(EmployeePayslip emp)
{
int hourlyPay=getHourRate(emp.getSkillLevel());
emp.rate=hourlyPay;
double grosspay;
if(emp.hours>40)
{
grosspay=40*hourlyPay+((emp.hours-40)*2*hourlyPay);
}
grosspay=emp.getHours()*hourlyPay;
return grosspay;
}
private static int getHourRate(String skillLevel)
{
int payRate=0;
switch(skillLevel)
{
case "A":
payRate= 50;
break;
case "B":
payRate= 40;
break;
case "C":
payRate= 30;
break;
}
return payRate;
}
private static double calculateNetPay(String lvl,double grossPay)
{
double netPay=grossPay;
double totalDeduction=0;
String choice;
Scanner sc=new Scanner(System.in);
if(lvl.equalsIgnoreCase("A"))
{
System.out.print("Do you want retirement Plan that is 5% of your gross pay?(y/n): ");
choice=sc.next();
if(choice.equalsIgnoreCase("y"))
totalDeduction+=grossPay*0.05;
}
System.out.print("Do you want Medical Insurancet Plan that is cost 73 per week?(y/n): ");
choice=sc.next();
if(choice.equalsIgnoreCase("y"))
totalDeduction+=73;
System.out.print("Do you want Dental Insurancet Plan that is cost 35 per week?(y/n): ");
choice=sc.next();
if(choice.equalsIgnoreCase("y"))
totalDeduction+=35;
System.out.print("Do you want Disability Insurancet Plan that is cost 20 per week?(y/n): ");
choice=sc.next();
if(choice.equalsIgnoreCase("y"))
totalDeduction+=20;
return grossPay-totalDeduction;
}
}

output

txt file genrated


Related Solutions

In this exercise, you create a program for the sales manager at Computer Haven, a small...
In this exercise, you create a program for the sales manager at Computer Haven, a small business that offers motivational seminars to local companies. Figure 7-53 shows the charge for attending a seminar. Notice that the charge per person depends on the number of people the company registers. For example, the cost for four registrants is $400; the cost for two registrants is $300. The program should allow the sales manager to enter the number of registrants for as many...
Consumer Behavior Exercise 2. For this exercise you need to refer to the consumer product you...
Consumer Behavior Exercise 2. For this exercise you need to refer to the consumer product you are developing for Consumer Behavior course (Marketplace Simulation product – BIKES). What will be the consumers’ likely needs and motivations for purchasing your product? (The products are Bikes for recreation, mountain, and speed). Use the Maslow’s hierarchy of needs and McGuire’s Psychological Motives to identify them. Explain each motivation and its impacts on the purchase decision of your new product.
For this coding exercise, you need to create a new Java project in Eclipse and finish...
For this coding exercise, you need to create a new Java project in Eclipse and finish all the coding in Eclipse. Run and debug your Eclipse project to make sure it works. Then you can just copy and paste the java source code of each file from Eclipse into the answer area of the corresponding box below. The boxes will expand once you paste your code into them, so don’t worry about how it looks J All data members are...
Imagine that you are opening a small company You need to staff this company depending on...
Imagine that you are opening a small company You need to staff this company depending on the nature of the company, the industry and what your strategies are Please tell me how many people you need to hire what qualifications they need to have and how do they help you achieve your strategic objectives for hr subject
joe runs a small boat factory. he can make ten boats ler year and sell them...
joe runs a small boat factory. he can make ten boats ler year and sell them each at $35,000. it cost joe 250,000 for the raw materials to build ten boats. joe has invested 500,000 dollars in the boat factory building. ( 200,000 from saving and 300,000 from small business loans at an annual rate of 10%) joe can work at a competing factory working on boats for an annual salary of 80,000 per year. what is the total revenue...
Mark runs a small boat factory. He can make ten boats per year and sell them...
Mark runs a small boat factory. He can make ten boats per year and sell them each at 50,000 each. It cost Mark 275,000 for the raw materials to build the ten boats. Mark has invested 500,000 dollars in the boat factory building. (200,000 from saving and 300,000 from small business loans at an annual rate of 5 percent=he just refinanced his business loan). Mark can work at a competing factory working on boats for an annual salary of 80,000...
You work in a factory that runs 24 hr a day, 7 days a week. The...
You work in a factory that runs 24 hr a day, 7 days a week. The boss insists that all 10 of the machines in the factory get a good servicing before he goes on vacation. Each of these machines has a part replaced that has an MTTF(µ) of 10,000hrs. The boss will then take the next 2 months (60 days) off for his “well deserved” vacation. The purchasing department will not purchase any expensive items while the boss is...
You will create a program that runs in one of two modes, interactive mode and test...
You will create a program that runs in one of two modes, interactive mode and test mode. The mode will determined by the command line, passing in a "-i" flag for interactive or "-t" for test mode. Require the user to pass in a flag. $> ./lab02 -i Make a selection: 1) Insert value at position 2) Remove at position 3) Replace value at position 4) Print length 5) Print list 6) Exit Choice: $> ./lab02 -t <output from your...
function exerciseOne(){ // Exercise One: In this exercise you will create a variable called 'aboutMe' //...
function exerciseOne(){ // Exercise One: In this exercise you will create a variable called 'aboutMe' // This variable should be assigned a new object // In this object create three key:value pairs // The keys should be: 'name', 'city', 'favoriteAnimal' // The values should be strings associated with the keys. // return the variable 'aboutMe' } function exerciseTwo(animal){ // Exercise Two: In this exercise you will be given an object called 'animal' // Create a new variable called 'animalName' //...
Chris runs a small company in Melbourne and had a contract with Web Warriors Pty Ltd...
Chris runs a small company in Melbourne and had a contract with Web Warriors Pty Ltd that has offices in Perth and Sydney to supply computer services for Chris’s business at $200 a month. The contract was to expire at the end of December 2019. Before the expiry of the contract Chris said by mobile phone that he would pay $400 a month for the next six months so that Web Warriors Pty Ltd could upgrade the cloud services for...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT