Skip to content
Snippets Groups Projects
Commit 31687d6b authored by Jungsu Kim's avatar Jungsu Kim
Browse files

Merge branch 'Refactor-1' into 'main'

Refactor 1 adding comments to all the classes

See merge request !1
parents ed3488ad 54339e20
Branches
No related tags found
1 merge request!1Refactor 1 adding comments to all the classes
......@@ -3,18 +3,24 @@ package Assign1;
import java.util.ArrayList;
public class Company {
//Global Variables
//Name of the company
private String NAME;
//Names of the employees in the company
private ArrayList<String> EMPLOYEES;
//Constructor to initialize the Company Object
public Company(String name) {
this.NAME = name;
this.EMPLOYEES = new ArrayList<>();
}
//Returns the name of the Company
public String getCompanyName() {
return NAME;
}
//Add the name of the employee into the Arraylist
public void addEmployee(String name) {
this.EMPLOYEES.add(name);
System.out.println("Employee added: " + name);
......@@ -23,6 +29,7 @@ public class Company {
}
}
//Removes the name of the employee in the company
public void removeEmployee(String name) {
this.EMPLOYEES.remove(name);
System.out.println("Employee removed: " + name);
......
package Assign1;
public class Employee {
//Global Variables
//Name of the employee
public String NAME;
//Unique ID of the employee
public int ID;
//Constructor to initialize the Employee Object
public Employee(String name, int id) {
this.NAME = name;
this.ID = id;
......
package Assign1;
public class FullTimeEmployee {
//Global Variables
//Employee Object
private Employee EMP;
//Salary of the employee
private double SALARY;
//Constructor to initialize the FullTimeEmployee object
public FullTimeEmployee(String name, int id, double SALARY) {
//Creating a new employee object with the given Name and ID
this.EMP = new Employee(name, id);
this.SALARY = SALARY;
}
//Returns the Salary of the employee
public double getSalary() {
return SALARY;
}
//Returns the name of the employee
public String getName() {
return this.EMP.NAME;
}
......
......@@ -2,21 +2,31 @@ package Assign1;
public class Main {
public static void main(String[] args) {
//Driver Code
//Initialize the Company
Company comp = new Company("Macdonald");
//Creating all the employees
//FullTimeEmployees
FullTimeEmployee Alice = new FullTimeEmployee("Alice", 1, 80000);
FullTimeEmployee Bob = new FullTimeEmployee("Bob", 2, 100000);
//PartTimeEmployees
PartTimeEmployee Sam = new PartTimeEmployee("Sam", 3, 20, 100);
PartTimeEmployee Joe = new PartTimeEmployee("Joe", 4, 15, 80);
//Adding all the employees into the Company
comp.addEmployee(Alice.getName());
comp.addEmployee(Bob.getName());
comp.addEmployee(Sam.getName());
comp.addEmployee(Joe.getName());
//Getting the Payrolls of all the employees
Payroll.processPayroll(Alice);
Payroll.processPayroll(Bob);
Payroll.processPayroll(Sam);
Payroll.processPayroll(Joe);
//Removing an employee from the company
comp.removeEmployee(Alice.getName());
}
}
package Assign1;
public class PartTimeEmployee {
//Global Variables
//Employee Object
private Employee EMPLOYEE;
//Hourly rate of the PartTimeEmployee
private double HOURLYRATE;
//The amount of hours the employee works in a month
private int HOURS;
//Constructor to initialize a PartTimeEmployee object
public PartTimeEmployee(String name, int id, double hourlyRate, int hours) {
//Creating a new Employee object with the given name and ID
this.EMPLOYEE = new Employee(name, id);
this.HOURLYRATE = hourlyRate;
this.HOURS = hours;
}
//Getting the total pay of the PartTimeEmployee
public double getPay() {
return this.HOURLYRATE * this.HOURS;
}
//Returns the name of the employee
public String getName() {
return this.EMPLOYEE.NAME;
}
......
package Assign1;
public class Payroll {
//Function to process the pay for a FullTimeEmployee
public static void processPayroll(FullTimeEmployee employee) {
//Using the TaxCalculator class to get the amount of taxes need to be paid
double tax = TaxCalculator.calculateTax(employee.getSalary());
//Deducting the taxes from the employee's salary
double netSalary = employee.getSalary() - tax;
//Print statements
System.out.println("Full Time Employee Payroll for: " + employee.getName());
System.out.println("Gross Salary: $" + employee.getSalary());
System.out.println("Tax Deducted: $" + tax);
System.out.println("Net Salary: $" + netSalary);
}
//Function to process the pay for a PartTimeEmployee
public static void processPayroll(PartTimeEmployee employee) {
//Using the TaxCalculator to process how much the employee needs to pay
double tax = TaxCalculator.calculateTax(employee.getPay());
//Deducting the taxes from the employee pay
double netSalary = employee.getPay() - tax;
//Print statements
System.out.println("Part Time Employee Payroll for: " + employee.getName());
System.out.println("Gross Salary: $" + employee.getPay());
System.out.println("Tax Deducted: $" + tax);
......
......@@ -2,6 +2,8 @@ package Assign1;
public class TaxCalculator {
//Function to calculate the taxes
//Going off a flat 20% tax rate
public static double calculateTax(double salary) {
return salary * 0.2; // Assuming a flat 20% tax rate
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment