Question

Project description This units project builds atop of what you implemented on the previous unit. However, you will be creating the main application that makes use of all your previously classes. Follow the step-by-step instructions and submit your running code via Moodle (If you have difficulties understanding the PayrollSystem +readNewFullTime):FullTime + readNewPartTime (): PartTime +addEmployee(pArrEmp ArrayList<Employee>, pEmp :Emplovee):void +calcPayroll(pArrEmp ArrayList<Employeel :void +showMenu (): byte + getVehicle() : Vehicle Work on PayrollSystem class Working with the PayrollSystem class. This is the main application class, which makes use of all the business class like FullTime, PartTime and VehicleClass Imports for this class

Previous class code:

1) Employee.java

-------------------------------------------------------------------------------

/**

*

*/

package main.webapp;

/**

* @author sargade

*

*/

public class Employee {

private int empId;

private String empName;

private Vehicle vehicle;

public Double calculatePay() {

return null;

}

/**

* @return the empId

*/

public int getEmpId() {

return empId;

}

/**

* @param empId

* the empId to set

*/

public void setEmpId(int empId) {

this.empId = empId;

}

/**

* @return the empName

*/

public String getEmpName() {

return empName;

}

/**

* @param empName

* the empName to set

*/

public void setEmpName(String empName) {

this.empName = empName;

}

/**

* @return the vehicle

*/

public Vehicle getVehicle() {

return vehicle;

}

/**

* @param vehicle

* the vehicle to set

*/

public void setVehicle(Vehicle vehicle) {

this.vehicle = vehicle;

}

}

--------------------------------------------------------

2) Vehicle.java

------------------------------------------------------------

/**

*

*/

package main.webapp;

/**

* @author sachin.argade

*

*/

public class Vehicle {

private String plateNumber;

private String colour;

public Vehicle(String plateNumber, String colour) {

this.plateNumber = plateNumber;

this.colour = colour;

}

/**

* @return the plateNumber

*/

public String getPlateNumber() {

return plateNumber;

}

/**

* @param plateNumber

* the plateNumber to set

*/

public void setPlateNumber(String plateNumber) {

this.plateNumber = plateNumber;

}

/**

* @return the colour

*/

public String getColour() {

return colour;

}

/**

* @param colour

* the colour to set

*/

public void setColour(String colour) {

this.colour = colour;

}

}

-------------------------------------------------------------------

3) FullTime.java

------------------------------------------------------------------

/**

*

*/

package main.webapp;

/**

* @author sargade

*

*/

public class FullTime {

private double salary;

private double overTime;

public Double calculatePay() {

return null;

}

/**

* @return the salary

*/

public double getSalary() {

return salary;

}

/**

* @param salary

* the salary to set

*/

public void setSalary(double salary) {

this.salary = salary;

}

/**

* @return the overTime

*/

public double getOverTime() {

return overTime;

}

/**

* @param overTime

* the overTime to set

*/

public void setOverTime(double overTime) {

this.overTime = overTime;

}

}

------------------------------------------------------------------

4) PartTime.java

---------------------------------------------------------------------

package main.webapp;

public class PartTime {

private double rate;

private double hoursWorked;

public Double calculatePay() {

return null;

}

/**

* @return the rate

*/

public double getRate() {

return rate;

}

/**

* @param rate

* the rate to set

*/

public void setRate(double rate) {

this.rate = rate;

}

/**

* @return the hoursWorked

*/

public double getHoursWorked() {

return hoursWorked;

}

/**

* @param hoursWorked

* the hoursWorked to set

*/

public void setHoursWorked(double hoursWorked) {

this.hoursWorked = hoursWorked;

}

}

-----------------------------------------------------------------------

6) PayrollSystem.java

-------------------------------------------------------------------------

/**

*

*/

package main.webapp;

import java.util.ArrayList;

/**

* @author sargade

*

*/

public class PayrollSystem {

/**

* Read full time data

*

* @return The {@link FullTime)

*/

public FullTime readNewFullTime() {

return null;

}

/**

* Read Part time data

*

* @return The {@link PartTime)

*/

public PartTime readNewPartTime() {

return null;

}

public void addEmployee(ArrayList<Employee> pArrEmp, Employee emp) {

}

public void calcPayroll(ArrayList<Employee> pArrEmp) {

}

public byte showMenu() {

return 1;

}

public Vehicle getVehicle() {

return null;

}

}

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

PayrollSystem.java
---------------------------------------------------------
import java.util.ArrayList;
import java.util.Scanner;

public class PayrollSystem {

    public static void main(String[] args) {
        ArrayList<Employee> arrEmp = new ArrayList<>();
        String varCount = "N";
        byte menuOption = 0;

        do {
            menuOption = showMenu();
            switch (menuOption) {
                case 1:
                    FullTime ft;
                    ft = readNewFullTime();
                    addEmployee(arrEmp, ft);
                    break;
                case 2:
                    PartTime pt;
                    pt = readNewPartTime();
                    addEmployee(arrEmp, pt);
                    break;
                case 3:
                    calcPayroll(arrEmp);
                    break;
                default:
                    break;
            }
        } while (menuOption != 4);

    }

    private static FullTime readNewFullTime() {
        int id = 0;
        String name = null;
        double sal = 0.0;
        double hourAndHalf = 0.0;
        Scanner kbd = new Scanner(System.in);
        System.out.println("Enter Id: ");
        id = kbd.nextInt();
        System.out.println("\n Enter Name: ");
        name = kbd.next();
        System.out.println("\n Enter Salary: ");
        sal = kbd.nextDouble();
        System.out.println("\n Enter Bonus: ");
        hourAndHalf = kbd.nextDouble();

        FullTime ft1 = new FullTime(id, name, sal, hourAndHalf, getVehicle());

        return ft1;
    }

    private static PartTime readNewPartTime() {
        int id = 0;
        String name = null;
        double rate = 0.0;
        double hoursWorked = 0.0;
        Scanner kbd = new Scanner(System.in);
        System.out.println("Enter Id: ");
        id = kbd.nextInt();
        System.out.println("\n Enter Name: ");
        name = kbd.next();
        System.out.println("\n Hourly Rate: ");
        rate = kbd.nextDouble();
        System.out.println("\n Enter Number of Hours Worked: ");
        hoursWorked = kbd.nextDouble();

        PartTime pt1 = new PartTime(id, name, rate, hoursWorked, getVehicle());

        return pt1;
    }

    public static void addEmployee(ArrayList<Employee>pArrEmp, Employee pEmp){
        pArrEmp.add(pEmp);
    }

    public static byte showMenu(){

        byte menuOption = 0;
        Scanner kbd = new Scanner(System.in);

        System.out.println(""
                + "/*********************************************/"
                + "\n/* 1. Add FullTime                         */"
                + "\n/* 2. Add PartTime                         */"
                + "\n/* 3. Calculate Payroll                    */"
                + "\n/* 4. Exit                                 */"
                + "\n/*********************************************/"
        );
        System.out.println("Input: ");
        menuOption = kbd.nextByte();

        return menuOption;
    }

    public static void calcPayroll(ArrayList<Employee>pArrEmp){
        double totalCompanyPay = 0.0;
        double individualPay;

        for(int i = 0; i < pArrEmp.size(); i++){
            System.out.println("\n*********************************************\n");
            individualPay =(pArrEmp.get(i)).calculatePay();
            Vehicle v =(pArrEmp.get(i)).getVehicle();
            String hasVehicle;

            if(v==null){
                hasVehicle = "No";
            }
            else{
                hasVehicle = "Yes";
            }

            System.out.println("Employee Name: " +(pArrEmp.get(i)).getName());
            System.out.println("Has Vehicle: " + hasVehicle);

            if(v != null){
                System.out.println("Plate Number: " + v.getPlateNumber());
                System.out.println("Colour: " + v.getColour());
            }

            System.out.println("Take Home Pay: " +individualPay);

            totalCompanyPay += individualPay;
        }
        System.out.println("Total payroll of the compnay: " +totalCompanyPay);
    }

    public static Vehicle getVehicle(){
        Scanner kbd = new Scanner(System.in);
        String hasVehicle = "N";

        System.out.println("Does this employee have a vehicle? Y/N: \n Input:");
        hasVehicle = kbd.next();

        if(hasVehicle.equalsIgnoreCase("Y")){
            System.out.println("Enter plate number: ");
            String auxPlate = kbd.next();
            System.out.println("Enter vehicle colour: ");
            String auxColour = kbd.next();
            return (new Vehicle(auxPlate, auxColour));
        }
        else{
            return(null);
        }
    }

}
--------------------------------------------------------------------------------------------
Vehicle.java
-----------------------------
public class Vehicle{

    private String plateNumber = "";
    private String colour = "";

    public Vehicle(String plateNumber, String colour){

        this.plateNumber = plateNumber;
        this.colour = colour;
    }


    public String getPlateNumber() {
        return plateNumber;
    }

  
    public void setPlateNumber(String plateNumber) {
        this.plateNumber = plateNumber;
    }


    public String getColour() {
        return colour;
    }


    public void setColour(String colour) {
        this.colour = colour;
    }

}


----------------------------------------------------------------------------------------
Employee.java
------------------------------------------
import java.math.BigInteger;
import java.security.SecureRandom;
import java.util.*;

public abstract class Employee {
    private static Map<String, String>employeeList = new HashMap<>();
    private int empId;
    private String name;
    private Vehicle vehicle;

    public Employee(){
        empId = 0;
        name ="";
    }

    public Employee(int empId, String name, Vehicle pV){
        this.empId = empId;
        this.name = name;
        this.vehicle = pV;
    }

    public Employee(int empId, String name, String plate, String colour){
        this.empId = empId;
        this.name = name;
        this.vehicle = new Vehicle(plate, colour);
    }

    public String genEmpId(){
        SecureRandom rand = new SecureRandom();

        return new BigInteger(50, rand).toString(32);
    }

    public abstract double calculatePay();


    public int getEmpId() {
        return empId;
    }

  
    public void setEmpId(int empId) {
        this.empId = empId;
    }


    public String getName() {
        return name;
    }

  
    public void setName(String name) {
        this.name = name;
    }


    public Vehicle getVehicle() {
        return vehicle;
    }


    public void setVehicle(Vehicle vehicle) {
        this.vehicle = vehicle;
    }


}
---------------------------------------------------------------------------
FullTime.java
----------------------------------
public class FullTime extends Employee{

    private double salary = 0;
    private double overtime = 0;

    public FullTime(int id, String name, Vehicle vehicle, double Salary,
                    double overtime){
        super(id,name,vehicle);
        this.salary = salary;
        this.overtime = overtime;
    }

    @Override
    public double calculatePay() {

        System.out.println("Full time employee ");

        return (salary + overtime);
    }


    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    public double getOvertime() {
        return overtime;
    }


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

    FullTime(int id, String name, double sal, double hourAndHalf, Vehicle vehicle) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

}
-------------------------------------------------------------------------
PartTime.java
-------------------------------
public class PartTime extends Employee{

    private double rate = 0;
    private double hoursWorked = 0;

    public PartTime(int id, String name, double rate, double hoursWorked, Vehicle vehicle){
        super(id,name,vehicle);
        this.rate = rate;
        this.hoursWorked = hoursWorked;
    }

    @Override
    public double calculatePay() {
        System.out.println("Part time employee.");
        return(this.getHoursWorked() * this.getRate());
    }


    public double getRate() {
        return rate;
    }

  
    public void setRate(double rate) {
        this.rate = rate;
    }

  
    public double getHoursWorked() {
        return hoursWorked;
    }

  
    public void setHoursWorked(double hoursWorked) {
        this.hoursWorked = hoursWorked;
    }

}

Add a comment
Know the answer?
Add Answer to:
Previous class code: 1) Employee.java ------------------------------------------------------------------------------- /** * */ package main.webapp; /** * @author sargade *...
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
  • By editing the code below to include composition, enums, toString; must do the following: Prompt the...

    By editing the code below to include composition, enums, toString; must do the following: Prompt the user to enter their birth date and hire date (see Fig. 8.7, 8.8 and 8.9 examples) in addition to the previous user input Create a new class that validates the dates that are input (can copy date class from the book) Incorporate composition into your class with these dates Use enums to identify the employee status as fulltime (40 or more hours worked for...

  • HospitalEmployee Inheritance help please. import java.text.NumberFormat; public class HospitalEmployee {    private String empName;    private...

    HospitalEmployee Inheritance help please. import java.text.NumberFormat; public class HospitalEmployee {    private String empName;    private int empNumber;    private double hoursWorked;    private double payRate;       private static int hospitalEmployeeCount = 0;    //-----------------------------------------------------------------    // Sets up this hospital employee with default information.    //-----------------------------------------------------------------    public HospitalEmployee()    { empName = "Chris Smith"; empNumber = 9999; hoursWorked = 0; payRate =0;               hospitalEmployeeCount++;    }       //overloaded constructor.    public HospitalEmployee(String eName,...

  • Please fill in the remaining code necessary and follow the instructions below this is an abstract...

    Please fill in the remaining code necessary and follow the instructions below this is an abstract class; it represents an department in the company. This class cannot be instantiated (objects created), but it serves as the parent for other classes. Department – This class represents a department within the company. 1. Provide the implementation (the body) for the following methods: public int getDepartmentID()) public String getDepartmentName()) public Manager getManager()) 2. Fix the implementation for the following method– substitute “blah” with...

  • departmentstore: package departmentstorepkg; import java.util.ArrayList; public class DepartmentStore {    private static final int DEFAULT_SIZE =...

    departmentstore: package departmentstorepkg; import java.util.ArrayList; public class DepartmentStore {    private static final int DEFAULT_SIZE = 10; private StaffMember [] myEmployees; private int myNumberEmployees; private String myFileName; private StaffMember[] employee; public DepartmentStore (String filename){ myFileName = filename; myEmployees = employee;    } public String toString(){ return this.getClass().toString() + ": " + myFileName; } public void addEmployee(Employee emp){ } /** * prints out all the employees in the array list held in this class */ public void print(){ for(int i =...

  • Below are the Car class and Dealership class that I created In the previous lab import...

    Below are the Car class and Dealership class that I created In the previous lab import java.util.ArrayList; class Car { private String make; private String model; private int year; private double transmission; private int seats; private int maxSpeed; private int wheels; private String type; public Car() { } public Car(String make, String model, int year, double transmission, int seats, int maxSpeed, int wheels, String type) { this.make = make; this.model = model; this.year = year; this.transmission = transmission; this.seats =...

  • DataSetEmployee Can you please help me the JAVA program? Here is the requirement. Rewrite DataSetBook to...

    DataSetEmployee Can you please help me the JAVA program? Here is the requirement. Rewrite DataSetBook to be DataSetEmployee. DataSetEmployee should extend ArrayList<Employee> and have no instance variables. You'll have to decide what replaces the getPages concept for getMax/getMin. As a hint, what method of Employee returns a numeric value? Make a package com.acme.midmanager. This package should contain the Manager class. Make a package com.acme.personnel. This package should contain the DataSetEmployee class. Make a package com.acme.topmanagement. This package should contain the...

  • C# Hey I am having trouble implementing additonal function to this assignment: Problem: Implement three IComparer classes on Employee - NameComparer, AgeComparer, and PayComparer - that allow Employee...

    C# Hey I am having trouble implementing additonal function to this assignment: Problem: Implement three IComparer classes on Employee - NameComparer, AgeComparer, and PayComparer - that allow Employees to be compared by the Name, Age, and Pay, respectively. Code: Employee.Core.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Employees { partial class Employee { // Field data. private string empName; private int empID; private float currPay; private int empAge; private string empSSN = ""; private string empBene...

  • In the processLineOfData method, write the code to handle case "H" of the switch statement such...

    In the processLineOfData method, write the code to handle case "H" of the switch statement such that: • An HourlyEmployee object is created using the firstName, lastName, rate, and hours local variables. Notice that rate and hours need to be converted from String to double. You may use parseDouble method of the Double class as follows: Double.parseDouble(rate) Call the parsePaychecks method in this class passing the Hourly Employee object created in the previous step and the checks variable. Call the...

  • PLEASE COMPLETE THE CODES. package javaprogram; import java.io.PrintStream; import java.util.ArrayList; import java.util.Scanner; /** * Movie class...

    PLEASE COMPLETE THE CODES. package javaprogram; import java.io.PrintStream; import java.util.ArrayList; import java.util.Scanner; /** * Movie class definition. * * @author David Brown * @version 2019-01-22 */ public class Movie implements Comparable { // Constants public static final int FIRST_YEAR = 1888; public static final String[] GENRES = { "science fiction", "fantasy", "drama", "romance", "comedy", "zombie", "action", "historical", "horror", "war" }; public static final int MAX_RATING = 10; public static final int MIN_RATING = 0; /** * Converts a string of...

  • In the processLineOfData, write the code to handle case "H" of the switch statement such that:...

    In the processLineOfData, write the code to handle case "H" of the switch statement such that: An HourlyEmployee object is created using the firstName, lastName, rate, and hours local variables. Notice that rate and hours need to be converted from String to double. You may use parseDouble method of the Double class as follows:               Double.parseDouble(rate) Call the parsePaychecks method in this class passing the HourlyEmployee object created in the previous step and the checks variable. Call the findDepartment method...

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
Active Questions
ADVERTISEMENT