UML Class Diagram and Implementation of a Java Payroll System

Verified

Added on  2021/06/15

|5
|722
|50
Practical Assignment
AI Summary
This assignment showcases a Java implementation of a payroll system, encompassing a UML class diagram and code for calculating employee pay. The solution includes two Java classes: `MIT162011Employee` which manages employee data such as name, phone, date of birth, sex, employee ID, base pay, and hours worked, along with getter and setter methods for each attribute. This class calculates gross pay, tax, and net pay. The `Payroll` class then utilizes the `MIT162011Employee` class to calculate and display payslips, including gross pay, net pay, and tax deductions. The `main` method in `Payroll` orchestrates the calculation and presentation of the pay information, demonstrating how the employee data is processed to generate the final pay details. The output includes a sample payslip with details like pay period, gross pay, and net pay, as well as a breakdown of earnings and deductions.
Document Page
TASK 1: UML CLASS DIAGRAM
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
TASK 2
package payroll;
/**
* The Employee class has the data for instantiating employee objects.
* The get and set methods assist in setting and retrieving values
into or from them.
* @author MIT162011
* @date 06-05-2018
**/
public class MIT162011Employee {
String name;
String phone;
String dateOfBirth;
char sex;
int empId;
double grossPay;
double netPay;
double hoursWorked;
double basePay;
double taxRate = 20;
double taxPay;
MIT162011Employee(){
this.setName("Jane Doe");
this.setPhone("1034568529");
this.setDateOfBirth("15/12/1992");
this.setSex('F');
this.setEmpId(12345);
this.setBasePay(40.50);
this.setHours(18);
}
private void setName(String n){
name = n;
}
private void setPhone(String p){
phone = p;
}
private void getDateOfBirth(String d){
dateOfBirth = d;
}
private void setSex(char s){
sex = s;
}
private void setEmpId(int e){
empId = e;
}
private void setBasePay(double b){
Document Page
basePay = b;
}
private void setHours(double h){
hoursWorked = h;
}
public void setGrossPay(double g){
grossPay=g;
}
public void setTaxPay(double t){
taxPay=t;
}
public void setNetPay(double n){
netPay=n;
}
public String getName(){
return name;
}
public String getPhone(){
return phone;
}
public String getDateOfBirth(){
return dateOfBirth;
}
public int getEmpId(){
return empId;
}
public char getSex(){
return sex;
}
public double getBasePay(){
return basePay;
}
public double getHours(){
return hoursWorked;
}
public double getGrossPay(){
return grossPay;
}
public double getTaxRate(){
return taxRate;
}
public double getTaxPay(){
return taxPay;
}
public double getNetPay(){
return netPay;
}
}
Document Page
Task 3
package payroll;
/**
* This class creates objects of the Employee types.
* Then it calculates the necessary payroll elements and displays the
pay details.
* @author MIT162011
* @date 06-05-2018
**/
public class Payroll {
static MIT162011Employee empObj;
static double gross,net;
public static void main(String[] args) {
empObj = new MIT162011Employee();
calcGross();
calcTax();
calcNet();
displayPaySlip();
}
public static void calcGross(){
gross=empObj.getBasePay()*empObj.getHours();
empObj.setGrossPay(gross);
}
public static void calcTax(){
empObj.setTaxPay((empObj.getTaxRate()/100)*empObj.getGrossPay());
}
public static void calcNet(){
net=empObj.getGrossPay()-empObj.getTaxPay();
empObj.setNetPay(net);
}
public static void displayPaySlip(){
System.out.println("\n");
System.out.println("Jhon's Cafe Ltd\t\t\t\t\t ABN:
"+empObj.getEmpId());
System.out.println("Pay Slip for: " + empObj.name + "\t\t\t\t
Payment Date: 18/06/2018");
System.out.println("Pay Period from: 01/06/2018 to
15/06/2018 \t Gross Pay: $" + empObj.getGrossPay());
System.out.println("\t\t\t\t\t\t Net Pay: $" +
empObj.getNetPay());
System.out.println("\nDescription \t\t Hours Worked \t
Calculated Rate \t Type");
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
System.out.println("--------------------------------------------------
---------------------");
System.out.println("Base Hourly @$"+empObj.getBasePay()+" \t\t
"+empObj.getHours()+" \t\t $" + empObj.getGrossPay() + "\t\t Wages");
System.out.println("PAYG Withholding \t\t\t\t -$" +
empObj.getTaxPay() + "\t Tax");
}
}
OUTPUT
chevron_up_icon
1 out of 5
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]