Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.ArrayList;
- import java.util.Scanner;
- import java.util.Arrays;
- /**
- * This program will perform the following functions:
- * A class is created for Employees in general.
- * A subclass is created for the Entire WLFU Team
- * A subclass is created for the Regional Cities
- * A subclass is created for Staff Categories
- * A subclass is created for Administrative, Doctors, Nurses, and Medical Support.
- * A integer defined as "SpecialEmployee" is used to categorize the staff within their respective Subclass as defined below:
- * Administrative: 1 - Senior Executive, 2 - Junior Executive, 3 - Support
- * Doctor: Number of Patients
- * Nurses: 1 - Clinical Nurses, 2 - Hospital Floor Nurse, 3 - Hospital Administrative Nurse
- * Medical Support: 1 - Support Type 1, 2 - Support type 2
- * An employee's Name, SSN, Race, and Category is collected.
- * Each employee's salary is calculated based on their position and if applicable other aspects (Bonuses etc.)
- * Total salary for each employee is calculated
- * State and Federal taxes are calculated.
- * All information is stored into an object
- * Once objects are created they're stored into an array.
- * That array is then added to an ArrayList and managed Generically by the WLFU Generic Manager.
- * The 3rd Element in the ArrayList is printed
- * The Entire ArrayList of Employees is sorted from Smallest to Largest based on their Salary
- * The Entire Arraylist of Employees is Printed.
- * To prove the Generic Capability of the WLFU Generic Manager a list of Ints is Read, Sorted, and Printed.
- */
- public class HospitalFrame {
- public static void main(String[] args) {
- HospitalFrame me = new HospitalFrame();
- //Create an Arraylist of Ints to contain Ints.Txt
- ArrayList<Integer> myInts = new ArrayList<Integer>();
- //Create an Arraylist of Employees to contain Staff.txt
- ArrayList<Employee> BostonEmployeeList = new ArrayList<Employee>();
- //Make a new instance of WLFU Manager for ints
- WLFUManager<Integer> genericInts = me.new WLFUManager<Integer>();
- //Make a new Instance of WLFU Manager for Employees.
- WLFUManager<Employee> genericEmployees = me.new WLFUManager<Employee>();
- //An Array to Hold the Employees of Boston
- Employee [] BostonEmployee = new Employee[4];
- try {
- int n=0;
- //Create a scanner to read the information contained within Staff.txt
- Scanner StaffInput = new Scanner(new File("src/main/Staff.txt"));
- //Gather the information from the records in Staff.txt and set them equal to their respective variables
- while (StaffInput.hasNextLine()) {
- String StaffName = StaffInput.next();
- String StaffRole = StaffInput.next();
- String StaffSSN = StaffInput.next();
- int SpecialEmployee = StaffInput.nextInt();
- String StaffRaceAbbreviation = StaffInput.next();
- //If statement that checks an employees Role, to decide which array or ArrayList to add them to.
- if(StaffRole.equals("Doctor")){
- BostonDoctor DoctorsOfBoston = me.new BostonDoctor(StaffName,StaffRole,StaffSSN,SpecialEmployee,StaffRaceAbbreviation);
- BostonEmployee[n] = DoctorsOfBoston;
- n++;
- genericEmployees.Add(BostonEmployeeList,DoctorsOfBoston);
- }
- else if(StaffRole.equals("Nurse")){
- BostonNurse NursesOfBoston = me.new BostonNurse(StaffName,StaffRole,StaffSSN,SpecialEmployee,StaffRaceAbbreviation);
- BostonEmployee[n] = NursesOfBoston;
- n++;
- genericEmployees.Add(BostonEmployeeList, NursesOfBoston);
- }
- else if (StaffRole.equals("Support")){
- BostonSupport SupportOfBoston = me.new BostonSupport(StaffName,StaffRole,StaffSSN,SpecialEmployee,StaffRaceAbbreviation);
- BostonEmployee[n] = SupportOfBoston;
- n++;
- genericEmployees.Add(BostonEmployeeList,SupportOfBoston);
- }
- else{
- BostonAdmin AdministratorsOfBoston = me.new BostonAdmin(StaffName,StaffRole,StaffSSN,SpecialEmployee,StaffRaceAbbreviation);
- BostonEmployee [n] = AdministratorsOfBoston;
- n++;
- genericEmployees.Add(BostonEmployeeList, AdministratorsOfBoston);
- }
- }
- //Calculate the Salary, State Tax, and Federal tax of the Objects within the Boston Employee Array
- for(int i=0; i < 4; i++){
- BostonEmployee[i].CalcSalary();
- BostonEmployee[i].CalcStateTax();
- BostonEmployee[i].CalculateFedTax();
- }
- //Sort the BostonEmployee Array
- Sort(BostonEmployee);
- System.out.println("\n Printing the Array Boston Employee Sorted from Smallest to Largest Based on Total Salary.");
- //Print the sorted Array
- for(int i=0; i<4; i++){
- BostonEmployee[i].Print();
- }
- //Calculate the Salary, State Tax, and Federal Tax of the Objects within the Arraylist of Boston Employees.
- for(int i=0; i<BostonEmployeeList.size(); i++){
- BostonEmployeeList.get(i).CalcSalary();
- BostonEmployeeList.get(i).CalcStateTax();
- BostonEmployeeList.get(i).CalculateFedTax();
- }
- System.out.println("\n Printing the third Element from The Boston Employee ArrayList ");
- //Print the third element in the ArrayList using the Get method from WLFU Manager
- genericEmployees.Get(BostonEmployeeList,3).Print();
- //Sort the Arraylist.
- genericEmployees.Sort(BostonEmployeeList);
- System.out.println("\n Printing the ArrayList sorted Smaller to Larger using WLFU Manager");
- //Print the ArrayList sorted Smallest to Largest
- for(int i=0; i<BostonEmployeeList.size(); i++){
- genericEmployees.Get(BostonEmployeeList,i).Print();
- }
- //Create a scanner to read the information contained with Ints.txt
- Scanner IntInput = new Scanner(new File("src/main/Ints.txt"));
- //Add the contents of Int input to their ArrayList
- while(IntInput.hasNextLine()){
- genericInts.Add(myInts, IntInput.nextInt());
- }
- //Sort the contents of Ints.txt
- genericInts.Sort(myInts);
- } catch (FileNotFoundException e) {
- System.err.println("File was not found");
- }
- System.out.println("\n Proving The Generic Nature of WLFU Manager by Sorting a list of Ints.");
- //Print the sorted contents of Ints.txt
- for(int i = 0; i < myInts.size(); i++){
- System.out.println(myInts.get(i));
- }
- }
- //Sort method to sort an Array from Smallest to Largest based on Total Salary.
- public static void Sort(Employee[] BostonEmployee) {
- //this method will sort an array of Solids objects based on their CompareTo function
- Employee xsave;
- int isw = 1;
- while (isw == 1) {
- isw = 0;
- for (int i = 0; i < 4 - 1 ; i++) {
- switch (BostonEmployee[i].compareTo(BostonEmployee[i + 1])) {
- case -1://the objects in array x are in the right order
- break;
- case 1://objects out of order, they must be changed.
- // This is where to the place holder is used to swap values
- xsave = BostonEmployee[i];
- BostonEmployee[i] = BostonEmployee[i + 1];
- BostonEmployee[i + 1] = xsave;
- isw = 1;
- break;
- default://objects are equal no change
- }
- }
- }
- }
- //Generic Manager for the WLFU system
- public class WLFUManager <T extends Comparable<T>> {
- int number = 0;
- //Generically adds an object (in this case students) to the Academic Class ArrayList
- public int Add(ArrayList<T> listName, T myGenericData) {
- listName.add(myGenericData);
- number++;
- return number;
- }
- //Getter to retrieve the record in the int location of an ArrayList
- public T Get(ArrayList<T> listName, int x){
- return listName.get(x);
- }
- //Generically sorts the object from Smaller to Larger
- public void Sort(ArrayList<T> listName) {
- T xsave;
- int isw = 1;
- while (isw == 1) {
- isw = 0;
- for (int i = 0; i < listName.size() - 1; i++) {
- switch (listName.get(i).compareTo(listName.get(i + 1))) {
- case -1://the objects in array x are in the right order
- break;
- case 1://objects out of order, they must be changed.
- // This is where to the place holder is used to swap values
- xsave = listName.get(i);
- listName.set(i, listName.get(i + 1));
- listName.set(i + 1, xsave);
- isw = 1;
- break;
- default://objects are equal no change
- }
- }
- }
- }
- public int GetNumber() {
- return number;
- }
- }
- //The Boston Medical Support class is used to assign the role of Medical Support to an employee that lives in Boston
- public class BostonSupport extends StaffCategories {
- double BaseSalary = 0;
- double StateTax = 0;
- double FedTax = 0;
- String PositionTitle;
- //Constructor for Boston Support
- public BostonSupport(String EmployeeName, String EmployeeRole, String EmployeeSSN, int SpecialEmployee, String RaceAbbreviation) {
- super(EmployeeName, EmployeeRole, EmployeeSSN, SpecialEmployee, RaceAbbreviation);
- }
- //Updates The int that defines the Special Employee. Please Note: After updating, Calculations for Salary, Tax, and Fed tax must be run again.
- public void UpdateSpecialInfo(int UpdatedInfo){
- UpdatedInfo = SpecialEmployee;
- }
- //Calculates the Position based on their Special Employee number
- public String calcPositionTitle(){
- if(SpecialEmployee == 1){
- PositionTitle = "Medical Support Type 1";
- }
- else if (SpecialEmployee == 2){
- PositionTitle = "Medical Support Type 2";
- }
- return PositionTitle;
- }
- //Calculates base salary based on Special Employee number
- public double calcBaseSalary(){
- if(SpecialEmployee == 1){
- BaseSalary = 45000;
- }
- else if (SpecialEmployee == 2){
- BaseSalary = 35000;
- }
- return BaseSalary;
- }
- //Calculates the Salary of a Support Staff
- public void CalcSalary() {
- Salary = calcBaseSalary()+ (calcBaseSalary() * BostonCOLA);
- }
- //Calculates State Taxes
- public void CalcStateTax() {
- StateTax = Salary * MassStateTax;
- }
- //Calculates the Federal taxes
- public void CalculateFedTax() {
- FedTax = Salary * FederalTax;
- }
- //Getter for State Tax
- public double getStateTax() {
- return StateTax;
- }
- //Getter for Federal Tax
- public double getFedTax() {
- return FedTax;
- }
- public void Print(){
- System.out.println("\n Name: " + EmployeeName + "\n Position: Boston " + EmployeeRole +"\n Role: "+calcPositionTitle()+"\n Race: " +EmployeeFullRace(RaceAbbreviation)+"\n SSN: "+EmployeeSSN+"\n Base Salary: $"+ calcBaseSalary()+"\n COLA (15%): $"+ (calcBaseSalary()*BostonCOLA)+"\n Total Salary: $"+getSalary()+"\n Estimated Taxes "+"\n Federal Taxes: $"+FedTax+"\n State Taxes: $"+StateTax);
- }
- }
- //The Boston Admin Class is used to assign the role of an Administrator to an employee that lives in Boston
- public class BostonAdmin extends StaffCategories {
- double BaseSalary =0;
- double Bonus = 0;
- double SalaryPostBonus =0;
- double StateTax = 0;
- double FedTax = 0;
- String PositionTitle;
- //Constructor for a Boston Admin.
- public BostonAdmin(String EmployeeName, String EmployeeRole, String EmployeeSSN, int SpecialEmployee, String RaceAbbreviation) {
- super(EmployeeName, EmployeeRole, EmployeeSSN, SpecialEmployee, RaceAbbreviation);
- }
- //Updates The int that defines the Special Employee. Please Note: After updating, Calculations for Salary, Tax, and Fed tax must be run again.
- public void UpdateSpecialInfo(int UpdatedInfo){
- UpdatedInfo = SpecialEmployee;
- }
- //Calculates the title based on the level of Executive
- public String calcPositionTitle(){
- if(EmployeeRole.equals("Senior_Exec")){
- PositionTitle = "Senior Executive";
- }
- else if(EmployeeRole.equals("Junior_Exec")){
- PositionTitle = "Junior Executive";
- }
- else if(EmployeeRole.equals("Support")){
- PositionTitle = "Support";
- }
- return PositionTitle;
- }
- //Calculates the Base Salary of an executive
- public double calcBaseSalary(){
- if(EmployeeRole.equals("Senior_Exec")){
- BaseSalary = 400000;
- }
- else if(EmployeeRole.equals("Junior_Exec")){
- BaseSalary = 175000;
- }
- else if(EmployeeRole.equals("Support")){
- BaseSalary = 40000;
- }
- return BaseSalary;
- }
- //Calculates the Bonus for an Executive (If any)
- public double calcBonus(){
- if (SpecialEmployee == 1){
- Bonus = 0.20;
- }
- else if (SpecialEmployee == 2){
- Bonus = 0.10;
- }
- else {
- Bonus = 0.0;
- }
- return Bonus;
- }
- //Calculates the Salary of an Executive
- public void CalcSalary() {
- Salary = calcBaseSalary()+ (calcBaseSalary() * BostonCOLA)+ (calcBaseSalary() * calcBonus());
- }
- //Calculates State Taxes
- public void CalcStateTax() {
- StateTax = Salary * MassStateTax;
- }
- //Calculates the Federal taxes
- public void CalculateFedTax() {
- FedTax = Salary * FederalTax;
- }
- //Getters for Boston Admin.
- public double getStateTax() {
- return StateTax;
- }
- public double getFedTax() {
- return FedTax;
- }
- public double getSalaryPostBonus(){
- return SalaryPostBonus;
- }
- //Prints a Boston Admins Information.
- public void Print(){
- System.out.println("\n Name: " + EmployeeName + "\n Boston Administrator "+"\n Position: " + calcPositionTitle()+"\n Race: "+EmployeeFullRace(RaceAbbreviation)+"\n SSN: " + EmployeeSSN + "\n Salary Base: "+calcBaseSalary() + "\n Cola (15%) " + (calcBaseSalary() * BostonCOLA)+"\n Bonus Amount: $" + (calcBaseSalary()*calcBonus())+"\n Total Salary: $" + getSalary()+"\n Estimated Taxes " +"\n Federal Taxes: $" + FedTax + "\n State Taxes: $" + StateTax);
- }
- }
- //The Boston Nurse Class is used to assign the role of a Nurse to an employee that lives in Boston
- public class BostonNurse extends StaffCategories {
- double BaseSalary = 65000;
- double Bonus = 0;
- double StateTax = 0;
- double FedTax = 0;
- String PositionTitle;
- //Constructor for a Boston Nurse.
- public BostonNurse(String EmployeeName, String EmployeeRole, String EmployeeSSN, int SpecialEmployee, String RaceAbbreviation) {
- super(EmployeeName, EmployeeRole, EmployeeSSN, SpecialEmployee, RaceAbbreviation);
- }
- //Updates The int that defines the Special Employee. Please Note: After updating, Calculations for Salary, Tax, and Fed tax must be run again.
- public void UpdateSpecialInfo(int UpdatedInfo){
- UpdatedInfo = SpecialEmployee;
- }
- //Calculates the Position Title of a Nurse, based on their Special Employee information.
- public String calcPositionTitle(){
- if(SpecialEmployee == 1){
- PositionTitle = "Clinical Nurse";
- }
- else if(SpecialEmployee == 2){
- PositionTitle = "Hospital Floor Nurse";
- }
- else if(SpecialEmployee == 3){
- PositionTitle = "Hospital Administrative Nurse";
- }
- return PositionTitle;
- }
- //Calculates The bonus a nurse recieves based on their SpecialEmployee int.
- public double calcBonus(){
- if(SpecialEmployee == 1){
- Bonus = 0.10;
- }
- else if(SpecialEmployee == 2){
- Bonus = 0.15;
- }
- else if(SpecialEmployee == 3){
- Bonus = 0.20;
- }
- return Bonus;
- }
- //Calculate the Salary of a Nurse.
- public void CalcSalary() {
- Salary = BaseSalary+(BaseSalary * BostonCOLA)+ (BaseSalary * calcBonus());
- }
- //Calculate the state taxes of a nurse.
- public void CalcStateTax() {
- StateTax = Salary * MassStateTax;
- }
- //Calculate the Federal taxes of a nurse.
- public void CalculateFedTax() {
- FedTax = Salary * FederalTax;
- }
- //Getters for Boston Nurse.
- public double getStateTax() {
- return StateTax;
- }
- public double getFedTax() {
- return FedTax;
- }
- //Prints the information for a Boston Nurse.
- public void Print(){
- System.out.println("\n Name: " + EmployeeName + "\n Position: Boston " + EmployeeRole +"\n Specialization: "+ calcPositionTitle()+ "\n Race: "+EmployeeFullRace(RaceAbbreviation) + "\n SSN: " + EmployeeSSN + "\n Base Salary: " + BaseSalary+ "\n COLA (15%) $" + (BaseSalary * BostonCOLA)+"\n Bonus Amount: $" + (BaseSalary * calcBonus())+"\n Total Salary: $"+ getSalary()+"\n Estimated Taxes "+ "\n Federal Taxes: " + FedTax + "\n State Taxes: " + StateTax);
- }
- }
- //The Boston Doctor Class is used to assign the role of a Doctor to an employee that lives in Boston.
- public class BostonDoctor extends StaffCategories{
- double BaseSalary = 155000;
- double PatientAdjustment = 0.0025;
- double StateTax = 0;
- double FedTax = 0;
- //Constructor for a Boston Doctor.
- public BostonDoctor(String EmployeeName, String EmployeeRole, String EmployeeSSN, int SpecialEmployee, String RaceAbbreviation) {
- super(EmployeeName, EmployeeRole, EmployeeSSN, SpecialEmployee, RaceAbbreviation);
- }
- //Updates The int that defines the Special Employee. Please Note: After updating, Calculations for Salary, Tax, and Fed tax must be run again.
- public void UpdateSpecialInfo(int UpdatedInfo){
- UpdatedInfo = SpecialEmployee;
- }
- //The CalcSalary Method will calculate a Boston Doctors Salary, accounting for COLA and their Individual adjusments
- public void CalcSalary() {
- Salary = BaseSalary + (BaseSalary * BostonCOLA) + (BaseSalary * PatientAdjustment * SpecialEmployee);
- }
- //Calculates the State Tax
- public void CalcStateTax() {
- StateTax = Salary * MassStateTax;
- }
- //Calculates the Federal Tax
- public void CalculateFedTax() {
- FedTax = Salary * FederalTax;
- }
- //Prints the information for a Doctor in Boston
- public void Print() {
- System.out.println("\n Name: " + EmployeeName + "\n Position: Resident Boston " + EmployeeRole + "\n Race: " + EmployeeFullRace(RaceAbbreviation) + "\n SSN: " + EmployeeSSN + "\n Patient Count: " + SpecialEmployee + "\n Salary Base: $" + BaseSalary + "\n COLA(15%): $" + (BaseSalary * BostonCOLA) + "\n Patient Adjustment: $" + (BaseSalary * PatientAdjustment * SpecialEmployee) + "\n Total Salary: $" + Salary + "\n Estimated Taxes " + "\n Federal Taxes: $" + getFedTax() + "\n Mass State Taxes: $" + getStateTax());
- }
- //Getters for Taxes
- public double getStateTax() {
- return StateTax;
- }
- public double getFedTax() {
- return FedTax;
- }
- }
- //The StaffCategories class establishes the categories that will be used when considering an employee and their pay.
- public abstract class StaffCategories extends RegionalCities {
- public int SpecialEmployee;
- //Constructor for Staff Categories. Introduces and sets the Special Employee field
- public StaffCategories(String EmployeeName, String EmployeeRole, String EmployeeSSN, int SpecialEmployee, String RaceAbbreviation) {
- super(EmployeeName,EmployeeRole, EmployeeSSN, RaceAbbreviation);
- setSpecialEmployee(SpecialEmployee);
- }
- //Setter for Special Employee
- public void setSpecialEmployee(int SpecialEmployee) {
- this.SpecialEmployee = SpecialEmployee;
- }
- //Getter for SpecialEmployee
- public int getSpecialEmployee() {
- return SpecialEmployee;
- }
- }
- //The RegionalCites class establishes the state and city taxes for each state and city.
- public abstract class RegionalCities extends The_WLFU_Team {
- public double BostonCOLA = 0.15;
- public double MassStateTax = 0.05;
- public double FederalTax = 0.25;
- //Constructor for Regional Cities.
- public RegionalCities(String EmployeeName, String EmployeeRole, String EmployeeSSN, String RaceAbbreviation) {
- super(EmployeeName, EmployeeRole, EmployeeSSN, RaceAbbreviation);
- }
- //Getters for RegionalCities
- public double getBostonCOLA() {
- return BostonCOLA;
- }
- public double getMassStateTax() {
- return MassStateTax;
- }
- public double getFederalTax() {
- return FederalTax;
- }
- }
- //The class The_WLFU_Team is an extension of Employee. If we had staff outside of Boston, they'd be held together here.
- public abstract class The_WLFU_Team extends Employee {
- //Constructor for The_WLFU_Team
- public The_WLFU_Team(String EmployeeName, String EmployeeRole, String EmployeeSSN, String RaceAbbreviation) {
- super(EmployeeName, EmployeeRole, EmployeeSSN, RaceAbbreviation);
- }
- }
- //The Employee class is the base class for the entire structure. Since everyone in hospital staff is an employee it all starts here
- public abstract class Employee implements Comparable<Employee> {
- String EmployeeName;
- String EmployeeRole;
- String EmployeeSSN;
- String RaceAbbreviation;
- double Salary;
- //Abstract Methods for their later use
- abstract void UpdateSpecialInfo(int UpdatedInfo);
- abstract void CalcSalary();
- abstract void CalcStateTax();
- abstract void CalculateFedTax();
- abstract void Print();
- //Translating RaceAbbreviation into the full race name.
- public String EmployeeFullRace(String RaceAbbreviation) {
- String FullRace = null;
- if (RaceAbbreviation.equals("AA")) {
- FullRace = "African American";
- } else if (RaceAbbreviation.equals("AS")) {
- FullRace = "Asian";
- } else if (RaceAbbreviation.equals("CA")) {
- FullRace = "Caucasian";
- } else if (RaceAbbreviation.equals("HS")) {
- FullRace = "Hispanic";
- } else if (RaceAbbreviation.equals("OT")) {
- FullRace = "Other";
- }
- return FullRace;
- }
- //CompareTo so that an Employee can be sorted from largest to smallest based on Total Salary
- public int compareTo(Employee o) {
- if (getSalary() > o.getSalary()) return 1;
- else if (getSalary() < o.getSalary()) return -1;
- else return 0;
- }
- //Constructor for an Employee
- public Employee(String EmployeeName, String EmployeeRole, String EmployeeSSN, String RaceAbbreviation) {
- setEmployeeName(EmployeeName);
- setEmployeeRole(EmployeeRole);
- setEmployeeSSN(EmployeeSSN);
- setRaceAbbreviation(RaceAbbreviation);
- setSalary(Salary);
- }
- //Setters for the Employee Class.
- public void setEmployeeName(String EmployeeName) {
- this.EmployeeName = EmployeeName;
- }
- public void setEmployeeRole(String EmployeeRole){this.EmployeeRole = EmployeeRole;}
- public void setEmployeeSSN(String EmployeeSSN) {
- this.EmployeeSSN = EmployeeSSN;
- }
- public void setRaceAbbreviation(String RaceAbbreviation) {
- this.RaceAbbreviation = RaceAbbreviation;
- }
- public void setSalary(double Salary){this.Salary = Salary;}
- //Getters for the Employee Class.
- public String getEmployeeName() {
- return EmployeeName;
- }
- public String getEmployeeSSN() {
- return EmployeeSSN;
- }
- public String getRaceAbbreviation() {
- return RaceAbbreviation;
- }
- public double getSalary() {
- return Salary;
- }
- public String getEmployeeRole(){return EmployeeRole;}
- }
- }
Add Comment
Please, Sign In to add comment