Question

a. Create a Payroll system in Java to do the following: Design a class employee with...

a. Create a Payroll system in Java to do the following:

Design a class employee with member’s eid, ename, basicsalary, overtime,
allowance, deduction, leave, netsal. (basicsalary, overtime, allowance, deduction,
leave , netsal are all double values).
Design the program for 3 employees(Array of Objects)
Methods:
1) Read() : Accept eid, ename and basicsalary from keyboard
2) Calculate() : Perform the following:-
o Accept overtimehours and calculate overtime =( basic / 240 ) * overtimehours
o Accept housingallowance and other allowance and calculate allowance =
housingallowance + other allowance
o Accept deductionhours and calculate deduction = (basic / 240 ) *
deductionhours
o Accept leavedays and calculate leave =(basic / 30 ) * leavedays
o Calculate net = basicsalary + overtime + allowance - deduction- leave
3) Print ():- Print all the members.
b. Compile and run the error-free program.
c. Copy the complied and executed Java program and attach a screen shot of the output
as well.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Employee.java

import java.util.Scanner;

public class Employee {
private int eId;
private String eName;
private double basicSalary, overtime, allowance, deduction, leave, netSalary;
  
public Employee()
{
this.eId = 0;
this.eName = "";
this.basicSalary = this.allowance = this.deduction = this.leave = this.netSalary = this.overtime = 0.0;
}

public Employee(int eId, String eName, double basicSalary) {
this.eId = eId;
this.eName = eName;
this.basicSalary = basicSalary;
this.allowance = this.deduction = this.leave = this.netSalary = this.overtime = 0.0;
}

public int geteId() {
return eId;
}

public void seteId(int eId) {
this.eId = eId;
}

public String geteName() {
return eName;
}

public void seteName(String eName) {
this.eName = eName;
}

public double getBasicSalary() {
return basicSalary;
}

public void setBasicSalary(double basicSalary) {
this.basicSalary = basicSalary;
}

public double getOvertime() {
return overtime;
}

public void setOvertime(double overtime) {
this.overtime = overtime;
}

public double getAllowance() {
return allowance;
}

public void setAllowance(double allowance) {
this.allowance = allowance;
}

public double getDeduction() {
return deduction;
}

public void setDeduction(double deduction) {
this.deduction = deduction;
}

public double getLeave() {
return leave;
}

public void setLeave(double leave) {
this.leave = leave;
}

public double getNetSalary() {
return netSalary;
}

public void setNetSalary(double netSalary) {
this.netSalary = netSalary;
}
  
public void Read()
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter employee id: ");
int id = Integer.parseInt(sc.nextLine().trim());
System.out.print("Enter employee name: ");
String empName = sc.nextLine().trim();
System.out.print("Enter employee basic salary: ");
double bSalary = Double.parseDouble(sc.nextLine().trim());
seteId(id);
seteName(empName);
setBasicSalary(bSalary);
}
  
public void Calculate()
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter overtime hours: ");
int nOvertime = Integer.parseInt(sc.nextLine().trim());
double over = (getBasicSalary() / 240) * nOvertime;
setOvertime(over);
System.out.print("Enter housing allowance: ");
double houseAllowance = Double.parseDouble(sc.nextLine().trim());
System.out.print("Enter other allowance: ");
double otherAllowance = Double.parseDouble(sc.nextLine().trim());
setAllowance(houseAllowance + otherAllowance);
System.out.print("Enter deduction hours: ");
int nDeductionHours = Integer.parseInt(sc.nextLine().trim());
double deduct = (getBasicSalary() / 240) * nDeductionHours;
setDeduction(deduct);
System.out.print("Enter number of leave days: ");
int nLeaveDays = Integer.parseInt(sc.nextLine().trim());
double leaveAmt = (getBasicSalary() / 30) * nLeaveDays;
setLeave(leaveAmt);
setNetSalary(getBasicSalary() + getOvertime() + getAllowance() - getDeduction() - getLeave());
}
  
public void Print()
{
System.out.println("Employee Id: " + geteId() + ", Employee Name: " + geteName() + ", Basic Salary: $" + String.format("%.2f", getBasicSalary()) + "\n"
+ "Overtime: $" + String.format("%.2f", getOvertime()) + "\n"
+ "Allowance: $" + String.format("%.2f", getAllowance()) + "\n"
+ "Deduction: $" + String.format("%.2f", getDeduction()) + "\n"
+ "Leave: $" + String.format("%.2f", getLeave()) + "\n"
+ "Net Salary: $" + String.format("%.2f", getNetSalary()) + "\n");
}
}

EmployeeMain.java (Main class)

import java.util.ArrayList;
import java.util.Scanner;

public class EmployeeMain {
  
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ArrayList<Employee> employees = new ArrayList<>();
  
System.out.print("How many employees? ");
int n = Integer.parseInt(sc.nextLine().trim());
while(n <= 0)
{
System.out.println("Number of employees should be greater than 0!\n");
System.out.print("How many employees? ");
n = Integer.parseInt(sc.nextLine().trim());
}
System.out.println();
  
for(int i = 0; i < n; i++)
{
System.out.println("EMPLOYEE " + (i + 1) + ":\n-----------");
Employee emp = new Employee();
emp.Read();
emp.Calculate();
employees.add(emp);
System.out.println();
}
  
System.out.println("\nALL EMPLOYEE:\n"
+ "-------------");
for(Employee emp : employees)
emp.Print();
System.out.println();
}
}

*********************************************************** SCREENSHOT *****************************************************

run: AA How many employees? 2 EMPLOYEE 1: OR Enter employee id: 188291 Enter employee name: John Smith Enter employee basic s

Add a comment
Know the answer?
Add Answer to:
a. Create a Payroll system in Java to do the following: Design a class employee with...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT