123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553 |
- <?php
- /**
- * <https://y.st./>
- * Copyright © 2017 Alex Yst <mailto:copyright@y.st>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <https://www.gnu.org./licenses/>.
- **/
- $xhtml = array(
- 'title' => '<code>package payrollsystem;</code>',
- 'subtitle' => 'Written in <span title="Programming 1">CS 1102</span> of <a href="http://www.uopeople.edu/">University of the People</a>, finalised on <del>2017-05-10</del> <del><ins>2017-05-17</ins></del> <ins>2017-05-24</ins>',
- 'copyright year' => '2017',
- 'body' => <<<END
- <h2>Employee.java</h2>
- <blockquote>
- <pre><code>/*
- * Copyright (C) 2017 Alex Yst
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package payrollsystem;
- /**
- * An abstract class for representing employee pay information
- *
- * @author Alex Yst
- */
- public abstract class Employee {
- private int empID;
- private String name;
- private Vehicle vehicle;
- /**
- * @return the empID
- */
- public int getEmpID() {
- return empID;
- }
- /**
- * @param empID the empID to set
- */
- public void setEmpID(int empID) {
- this.empID = empID;
- }
- /**
- * @return the name
- */
- public String getName() {
- return name;
- }
- /**
- * @param name the name to set
- */
- public void setName(String name) {
- this.name = name;
- }
- /**
- * @return the vehicle
- */
- public Vehicle getVehicle() {
- return vehicle;
- }
- /**
- * @param vehicle the vehicle to set
- */
- public void setVehicle(Vehicle vehicle) {
- this.vehicle = vehicle;
- }
- /**
- * A bare constructor method. Not used by the program.
- */
- public Employee() {
- this.empID = 0;
- this.name = "";
- }
- /**
- * Constructor method. This is the only one of the three constructor methods
- * actually used by the program.
- *
- * @param pEmpID The employee's ID number
- * @param pName The employee's name
- * @param pV An object representing the employee's vehicle, if any
- */
- public Employee(int pEmpID, String pName, Vehicle pV) {
- this.empID = pEmpID;
- this.name = pName;
- this.vehicle = pV;
- }
- /**
- * The most comprehensive constructor method of this class. Not used by the
- * program
- *
- * @param pEmpID The ID number of the employee
- * @param pName The name of the employee
- * @param pPlate The registration plate number of the employee's vehicle
- * @param pColour The colour of the employee's vehicle
- */
- public Employee(int pEmpID, String pName, String pPlate, String pColour) {
- this.empID = pEmpID;
- this.name = pName;
- this.vehicle = new Vehicle(pPlate, pColour);
- }
- /**
- * The rules for determining an employee's pay are determined by what type of
- * employee they are. This method must be defined in child classes.
- *
- * @return The calculated pay
- */
- public abstract double calculatePay();
- }</code></pre>
- </blockquote>
- <h2>FullTime.java</h2>
- <blockquote>
- <pre><code>/*
- * Copyright (C) 2017 Alex Yst
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package payrollsystem;
- /**
- * A class for representing full-time employees
- *
- * @author Alex Yst
- */
- public class FullTime extends Employee {
- private double salary;
- private double overtime;
- /**
- * Calculates the ammount that sould be paid to the employee
- *
- * @return The ammout of pay due to the employee
- */
- @Override
- public double calculatePay() {
- System.out.println("Full time employee.");
- return this.getSalary() + this.getOvertime();
- }
- /**
- * @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;
- }
- /**
- * Constructor method
- *
- * @param id The ID number of the employee
- * @param name The name of the employee
- * @param sal The salary of the employee
- * @param hourAndHalf unclear - might be overtime pay or might be employee bonus
- * @param vehicle an object representing the employee's vehicle, if any
- */
- public FullTime(int id, String name, double sal, double hourAndHalf, Vehicle vehicle) {
- super(id, name, vehicle);
- this.overtime = hourAndHalf;
- this.salary = sal;
- }
- }</code></pre>
- </blockquote>
- <h2>PartTime.java</h2>
- <blockquote>
- <pre><code>/*
- * Copyright (C) 2017 Alex Yst
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package payrollsystem;
- /**
- * A class for representing part-time employees
- *
- * @author Alex Yst
- */
- public class PartTime extends Employee {
- private double rate;
- private double hoursWorked;
- /**
- * Calculates the ammount that sould be paid to the employee
- *
- * @return The ammout of pay due to the employee
- */
- @Override
- public double calculatePay() {
- System.out.println("Part time employee.");
- return this.getHoursWorked() * this.getRate();
- }
- /**
- * @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;
- }
- /**
- * Constructor method
- *
- * @param id The ID number of the employee
- * @param name The name of the employee
- * @param rate The hourly rate of the employee
- * @param hoursWorked2 The number of hours the employee has worked
- * @param v1 An object representing the vehicle of the employee
- */
- public PartTime(int id, String name, double rate, double hoursWorked2, Vehicle v1) {
- super(id, name, v1);
- this.rate = rate;
- this.hoursWorked = hoursWorked2;
- }
- }</code></pre>
- </blockquote>
- <h2>PayrollSystem.java</h2>
- <blockquote>
- <pre><code>/*
- * Copyright (C) 2017 Alex Yst
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package payrollsystem;
- import java.util.ArrayList;
- import java.util.Scanner;
- /**
- * A simple program for calculating employee pay
- *
- * This program facilitates the entering of employee pay information, then adds
- * it up to show the total amount paid to employees by the company. Information
- * on employee vehicles can also be entered, but because the program doesn't
- * store any information in a database and this program doesn't use the vehicle
- * information in any way besides simply desplaying it with the employee's pay,
- * entering that information has no significant benefit.
- *
- * @author Alex Yst
- */
- public class PayrollSystem {
- /**
- * This method simply runs the main program.
- *
- * @param arguments Not implemented
- */
- public static void main(String[] arguments) {
- ArrayList<Employee> arrEmp = new ArrayList<>();
- String varCont = "N";
- byte menuOption;
- do {
- menuOption = showMenu();
- switch(menuOption) {
- case 1:
- addEmployee(arrEmp, readNewFullTime());
- break;
- case 2:
- addEmployee(arrEmp, readNewPartTime());
- break;
- case 3:
- calcPayroll(arrEmp);
- break;
- default:
- break;
- }
- } while(menuOption != 4);
- }
- /**
- * This method promps the user for an employee's information and generates an
- * object based on that information to represent the employee.
- *
- * @return An object representing the full-time employee
- */
- public static FullTime readNewFullTime() {
- Scanner kbd = new Scanner(System.in);
- System.out.print("Enter Id: ");
- int id = kbd.nextInt();
- System.out.print("\nEnter Name: ");
- String name = kbd.next();
- System.out.print("\nEnter Salary: ");
- double sal = kbd.nextDouble();
- System.out.print("\nEnter Bonus: ");
- double hourAndHalf = kbd.nextDouble();
- return new FullTime(id, name, sal, hourAndHalf, getVehicle());
- }
- /**
- * This method promps the user for an employee's information and generates an
- * object based on that information to represent the employee.
- *
- * @return An object representing the part-time employee
- */
- public static PartTime readNewPartTime() {
- Scanner kbd = new Scanner(System.in);
- System.out.print("Enter Id: ");
- int id = kbd.nextInt();
- System.out.print("\nEnter Name: ");
- String name = kbd.next();
- System.out.print("\nEnter Hourly Rate: ");
- double rate = kbd.nextDouble();
- System.out.print("\nEnter Number of Hours Worked: ");
- double hoursWorked = kbd.nextDouble();
- return new PartTime(id, name, rate, hoursWorked, getVehicle());
- }
- /**
- * This one-line method takes an employee list and an employee, and add the
- * employee to the list. On first glance, it doesn't seem like a useful method,
- * but it actually provides a layer of abstraction. In the future, employee
- * lists or employee representations may be implemented another way. If and
- * when that happens, this method can be updated instead of updating every
- * instance of adding an employee to a dist throught the code.
- *
- * @param pArrEmp The list of employees
- * @param pEmp The employee to add to the list
- */
- public static void addEmployee(ArrayList<Employee> pArrEmp, Employee pEmp) {
- pArrEmp.add(pEmp);
- }
- /**
- * This method shows the user the options and returns their input. Why is our
- * menu indexed from one instead of zero? Are we common fools that don't
- * understand zero comes before one!?
- *
- * @return A byte specified by the user
- */
- public static byte showMenu() {
- Scanner kbd = new Scanner(System.in);
- System.out.println("/* *********************************************************/");
- System.out.println("/* 1. Add FullTime */");
- System.out.println("/* 2. Add PartTime */");
- System.out.println("/* 3. Calculate Payroll */");
- System.out.println("/* 4. Exit */");
- System.out.println("/* *********************************************************/");
- System.out.print("Input: ");
- return kbd.nextByte();
- }
- /**
- * This method displays vehicle information of every employee and, more
- * importantly, calculates every employee's pay and adds the pay of all
- * employees up to show the total paid out by the company. This should be the
- * final option specified by the user before exiting the program, at least if
- * the user knows what they're doing.
- *
- * @param pArrEmp A list of employees
- */
- public static void calcPayroll(ArrayList<Employee> pArrEmp) {
- double totalCompanyPay = 0.0;
- double individualPay;
- for(int i=0; i<pArrEmp.size(); i++) {
- Employee emp = pArrEmp.get(i);
- System.out.println("\n**************************\n");
- individualPay = emp.calculatePay();
- Vehicle v = emp.getVehicle();
- String hasVehicle;
- if(v == null) {
- hasVehicle = "No";
- } else {
- hasVehicle = "Yes";
- }
- System.out.print("Employee Name: ");
- System.out.println(emp.getName());
- System.out.print("Has Vehicle: ");
- System.out.println(hasVehicle);
- if(v != null) {
- System.out.print("Plate Number: ");
- System.out.println(v.getPlateNumber());
- System.out.print("Colour: ");
- System.out.println(v.getColour());
- }
- System.out.print("Take Home Pay: ");
- System.out.println(individualPay);
- totalCompanyPay += individualPay;
- }
- System.out.print("------------------\nTotal paroll of the company: ");
- System.out.println(totalCompanyPay);
- System.out.println("------------------");
- }
- /**
- * This method promps the user for information regarding the employee's
- * vehicle. However, this information is actually useless for calculating
- * payrool and isn't stored in any database. Therefore, each pay period, the
- * vehicle information must be uselessly re-entered. A smart user of this
- * progran will simply type "N" when asked if the employee has a vehicle to
- * avoid having to look up the employee's registration plate number and vehicle
- * colour.
- *
- * @return An object representing the employee's vehicle
- */
- public static Vehicle getVehicle() {
- Scanner kbd = new Scanner(System.in);
- System.out.print("\nDoes this employee have a vehicle? Y/N :\nInput : ");
- String hasVehicle = kbd.next();
- if(hasVehicle.equalsIgnoreCase("Y")) {
- System.out.print("\nEnter plate number: ");
- String auxPlate = kbd.next();
- System.out.print("\nEnter vehicle colour: ");
- String auxColour = kbd.next();
- return new Vehicle(auxPlate, auxColour);
- } else {
- return null;
- }
- }
- }</code></pre>
- </blockquote>
- <h2>Vehicle.java</h2>
- <blockquote>
- <pre><code>/*
- * Copyright (C) 2017 Alex Yst
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package payrollsystem;
- /**
- * A class for representing employee vehicles
- *
- * @author Alex Yst
- */
- public class Vehicle {
- private String plateNumber;
- private String colour;
- /**
- * Constructor method
- *
- * @param plateNumber The registration plate number of the vehicle
- * @param colour The colour of the vehicle
- */
- 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;
- }
- }</code></pre>
- </blockquote>
- END
- );
|