Create a project which will accept information about employee pay and then displ
ID: 3594100 • Letter: C
Question
Create a project which will accept information about employee pay and then display calculated results. The project should contain at least your executable class with the main method, as well as an Employee class. The classes should be submitted via Canvas. Your executable class should ask the user for the following information: Employee First Name Employee Last Name Annual Salary And it should allow the user to enter information about one or more taxes; tax rate(in %) and tax name. It should continue to prompt the user for another tax until the user enters -1 for the tax rate. The main program should then display the employee name and the following information: Biweekly gross pay (before taxes), Total biweekly taxes, Biweekly net pay (after taxes). Note: biweekly means a 2 week period. Extra credit (5 points): Also display monthly gross pay, total monthly taxes, monthly net payThe First and Last names should be from 1 to 20 characters each. The salary and tax amounts should be checked so that only meaningful, reasonable values are accepted.
Give the whole program step by step and plz give the output as well.
Explanation / Answer
Employee.java
package taxCalc;
/**
* @author
*/
public class Employee {
private String firstName;
private String lastName;
private double annualSalary;
private double biweeklyGrossPay;
/**
* @param firstName
* @param lastName
* @param annualSalary
*/
public Employee(String firstName, String lastName, double annualSalary){
this.firstName=firstName;
this.lastName=lastName;
this.annualSalary=annualSalary;
}
/**
* @return FirstName
*/
public String getFirstName() {
return firstName;
}
/**
*
* @param firstName
*/
public void setFirstName(String firstName) {
this.firstName = firstName;
}
/**
* @return lastName
*/
public String getLastName() {
return lastName;
}
/**
* @param lastName
*/
public void setLastName(String lastName) {
this.lastName = lastName;
}
/**
* @return
*/
public double getAnnualSalary() {
return annualSalary;
}
/**
* @param annualSalary
*/
public void setAnnualSalary(double annualSalary) {
this.annualSalary = annualSalary;
}
/**
* @return
*/
public double getBiweeklyGrossPay() {
//as year has 52 weeks, bi weekly grosspay is calculated based on annualsalary divided by 52 weeks multiplied by 2 for biweekly
biweeklyGrossPay=(annualSalary/52)*2;
return biweeklyGrossPay;
}
/**
* @param biweeklyGrossPay
*/
public void setBiweeklyGrossPay(double biweeklyGrossPay) {
this.biweeklyGrossPay = biweeklyGrossPay;
}
}
Main Program:
EmployeeTest.java
package taxCalc;
import java.util.Scanner;
public class EmployeeTest {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// ask the name for the first time
System.out.println("======Provide Emplyee Details=====");
System.out.println("Enter Employee First Name: ");
String firstName = scanner.nextLine();
System.out.println("Enter Employee Last Name: ");
String lastName = scanner.nextLine();
System.out.println("Enter Employee Annual Salary: ");
double annualSalary=0;
int id = 0;
// check if entered value for salary is a number or not
while (id != -1) {
if (!scanner.hasNextDouble()) {
scanner.nextLine();
System.out.println("Please enter valid value for salary : ");
} else {
annualSalary = scanner.nextDouble();
id = -1;
}
}
System.out.println("Enter the details of taxes to be paid: ");
int noOfTaxes = 0;
double[] taxes = new double[10];
String[] taxNames = new String[10];
id = 0;
while (id != -1) {
System.out.println("Enter Name of the tax: ");
taxNames[noOfTaxes] = scanner.next();
System.out.println("Enter Tax Rate: ");
taxes[noOfTaxes] = Double.parseDouble(scanner.next());
noOfTaxes++;
System.out.println("Enter (0) to provide another tax details or -1 to exit");
id = scanner.nextInt();
}
Employee employee=new Employee(firstName, lastName, annualSalary);
System.out.println("Employee First Name: "+employee.getFirstName());
System.out.println("Employee last Name: "+employee.getLastName());
System.out.println("Employee Annual salary "+employee.getAnnualSalary());
System.out.println("=======Details Biweekly==========");
System.out.println("Employee biweekly Gross Pay: "+employee.getBiweeklyGrossPay());
double totalbiweeklyTax=0;
double biweeklyNetPay=0;
for(int i=0;i<noOfTaxes;i++){
totalbiweeklyTax+=(taxes[i]*employee.getBiweeklyGrossPay())/100;
}
biweeklyNetPay=employee.getBiweeklyGrossPay()-totalbiweeklyTax;
System.out.println("Total Biweekly tax : "+totalbiweeklyTax);
System.out.println("Biweekly net pay (after taxes): "+biweeklyNetPay);
System.out.println("=======Details Monthly==========");
double monthlyGrossPay=annualSalary/12;
System.out.println("Employee Monthly gross Pay"+monthlyGrossPay);
double totalmonthlyTax=0;
double monthlyNetPay=0;
for(int i=0;i<noOfTaxes;i++){
totalmonthlyTax+=(taxes[i]*monthlyGrossPay)/100;
}
monthlyNetPay=monthlyGrossPay-totalmonthlyTax;
System.out.println("Total Monthly tax : "+totalmonthlyTax);
System.out.println("Monthly net pay (after taxes): "+monthlyNetPay);
scanner.close();
}
}
Sample output:
======Provide Emplyee Details=====
Enter Employee First Name:
First
Enter Employee Last Name:
Last
Enter Employee Annual Salary:
12000
Enter the details of taxes to be paid:
Enter Name of the tax:
direct
Enter Tax Rate:
10
Enter (0) to provide another tax details or -1 to exit
0
Enter Name of the tax:
Indirect
Enter Tax Rate:
5
Enter (0) to provide another tax details or -1 to exit
-1
Employee First Name: First
Employee last Name: Last
Employee Annual salary 12000.0
Employee biweekly Gross Pay: 461.53846153846155
Total Biweekly tax : 69.23076923076923
Biweekly net pay (after taxes): 392.3076923076923
=======Details Monthly==========
Employee Monthly gross Pay1000.0
Total Monthly tax : 150.0
Monthly net pay (after taxes): 850.0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.