In: Computer Science
Company ARC Inc. is a medium sized civil engineering firm with 150 employees in offices in Ontario, Alberta, and British Columbia. The design of the payroll system calculates the hourly, bi-weekly, and monthly compensation wages for temporary, contract, and full-time engineering employees. The company wants to revamp its payroll system with consideration of multiple employee type groups mentioned above. You are assigned to create this payroll system that calculates the correct wages for each employee and report the total wage value before and after taxes. You must consider the following: • Temporary employees: hourly wage only, no benefits, income taxed at 15%. • Contract employees: bi-weekly wage only, no benefits, income taxed at 18%. • Fulltime employees: monthly wage only, benefits deducted at 10%, income taxed at 20%. Create a payroll system using Java with at least two classes: Payroll.java and Employee.java. You can add more classes if you think it is necessary. The application is executed by command line only. (No need for GUI or web application forms.) You must add comments to all the classes and methods. Employee.java technical details: Constructor’s parameters • Employee’s Name, Employee ID, Work Type (T, C, F), Wage Assignment 2 – OOP Payroll Part 1 INFO-6094 – Programming 2 Page: 2 Instant variables • String - Employee Name • int - Employee ID • char - Work Type • double - Wage Methods Use setter and getter methods to manipulate the values inputted. For methods, they should be verbs, mixed case with first letter lowercase, and the first letter of each internal word is capitalized (ie. getEmployeeName(String eName) ). Payroll.java technical details: • You can use a data structure such as an Array to store employee information. • The program should continue to execute unless the optional number value “0” is inputted as an answer. • The system must ask and validate the following for the command line values inputted: Option ‘1’: Which option would you like? ____ What is the employee name? ____ What is the employee ID? ____ What is the employee’s work type? ____ What is the employee’s wage? ____ Employee’s wage after tax: # ********************************************** Then the program will loop back and ask, ‘Which option to choose now?’ It will only exit the loop if input is not 1. Option ‘0’: When the user has inputted 0, the following is displayed: Employee name, employee ID, Work Type, Total Wage before tax, Total Wage after tax 1. William White, 234354, C, $4500.00, $3690.00 2. Christy Carpenter, 045644, F, $5500.00, $3850.00 Etc…. Total employees: # Work types: (#) Temporary, (#) Contract, (#) Full-time Assignment 2 – OOP Payroll Part 1 INFO-6094 – Programming 2 Page: 3 Total wages before tax: # Total wages after tax: # Exit program. If an option value that is NOT ‘0’ or ‘1’ is inputted, then the program exists completely. The user must start again. • To validate errors and report them in the command prompt, consider the following: o the hourly pay cannot exceed 90.00 but can be 0 o the bi-weekly pay cannot be below 1000.00 or more than 3500.00 o the monthly pay cannot be less than 3000.00 o employee name must have at least one space and cannot be less than 5 characters o employee ID must be a positive integer o pay must be a positive value
///////////////// Employee. java //////////////
public class Employee {
private String employeename;
private int employeeId;
private char worktype;
private double wage;
/**
* getters and setters
*/
Employee(String employeename,int employeeId,char worktype,double wage){
this.employeeId=employeeId;
this.employeename=employeename;
this.worktype=worktype;
this.wage=wage;
}
public String getEmployeename() {
return employeename;
}
public int getEmployeeId() {
return employeeId;
}
public double getWage() {
return wage;
}
public char getWorktype() {
return worktype;
}
public void setEmployeename(String employeename){
this.employeename = employeename;
}
public void setEmployeeId(int employeeId) {
this.employeeId = employeeId;
}
public void setWage(double wage) {
this.wage = wage;
}
public void setWorktype(char worktype) {
this.worktype = worktype;
}
}
////////////////////////////// Payroll.java /////////////////
public class Payroll {
/**
* creating an employee array of 100 capacity for demo purposes
*/
Employee[] employee =new Employee[100];
private int count=0;
void addEmployee(Employee e){
employee[count++]=e;
}
/**
* returns no of elements in employee array
*/
int count(){
return count;
}
/** Calculates wages of employee according to workType and incometax */
double wageAfterTaxCalulator(Employee employee){
if(employee.getWorktype()=='T'){
return employee.getWage()-0.15*employee.getWage();
}
else if(employee.getWorktype()=='C'){
return employee.getWage()-0.18*employee.getWage();
}
else{
return employee.getWage()-0.30*employee.getWage();
}
}
/**
* validations for input of data
*
*/
boolean validatePay(char workType,double amount){
if(workType =='T'){
if(amount<=90 && amount >=0){
return true;
}
return false;
}
else if(workType =='C'){
if(amount<=3000 && amount >=1000){
return true;
}
return false;
}
else{
if(amount>=3000){
return true;
}
return false;
}
}
boolean validateName(String name){
name=name.trim();
if(name.contains(" ") && name.length()>=5){
return true;
}
else{
return false;
}
}
boolean validateId(int id){
if(id>0){
return true;
}
return false;
}
boolean validatePay(double id){
if(id>0){
return true;
}
return false;
}
}
////////////////////// Main .java (for testing of code) //////////////////
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
/** creating a scanner for input */
Scanner sc=new Scanner(System.in);
Payroll payroll =new Payroll(); // creating new payroll object
while(true){
System.out.println("Which option Would you like? _____ (0 or 1) ");
int option = sc.nextInt();
/** if option is 1 or 0 proceeds or else exits */
if(option ==0 || option ==1){
if(option ==1){
System.out.println("what is Employee name? ______");
String name;
sc.nextLine();
name=sc.nextLine();
while(!payroll.validateName(name)){
System.out.println(" Entered name must have a white space in between and atleast 5 chars .... Try again");
System.out.println("Enter Empoyee name");
name=sc.nextLine();
}
System.out.println("Enter an option for worktype");
System.out.println("1. Contract 2. Temporary 3.Fulltime");
option=sc.nextInt();
while(option!=1 && option!=2 && option!=3){
System.out.println(" Please enter a Valid option");
option=sc.nextInt();
}
char workType;
if(option ==1){ workType = 'C';}
else if(option ==2){ workType = 'T';}
else { workType = 'F';}
System.out.println("Enter an Employee id");
int employeeId;
employeeId=sc.nextInt();
while(!payroll.validateId(employeeId)){
System.out.println(" Please enter positive value");
employeeId=sc.nextInt();
}
System.out.println("Enter Employee wage");
int wage;
wage=sc.nextInt();
while(!payroll.validatePay(workType, wage)){
System.out.println("wage entered is not following rules........");
System.out.println("Enter according to following rules");
System.out.println("1. Hourly wage cannot be greater than $90");
System.out.println("2. Biweekly pay should be between $1000 to $3000");
System.out.println("1. Monthly pay cannot be less than $3000");
System.out.println("Enter Employee wage");
wage =sc.nextInt();
}
payroll.addEmployee(new Employee(name, employeeId, workType, wage));
}
else{ //if option is 0 prints all the data in employee array
if(payroll.count()==0){
System.out.println("No data exists");
}
else{
System.out.println("Employee name,Employee Id ,Work Type, Total Wage before tax, Total Wage after tax ");
for(int i=0;i<payroll.count();i++){
System.out.println(payroll.employee[i].getEmployeename() + ","+payroll.employee[i].getEmployeeId()+","+payroll.employee[i].getWorktype()+ ",$"+payroll.employee[i].getWage()+",$"+payroll.wageAfterTaxCalulator(payroll.employee[i]) );
}
}
sc.close();
System.exit(0);
}
}
else{
sc.close();
System.exit(0);
}
}
}
}