inital commit

This commit is contained in:
gabriel venberg 2021-03-26 22:45:38 -05:00
commit aa37ae1eec
55 changed files with 3927 additions and 0 deletions

View file

@ -0,0 +1,54 @@
/*
* Copyright (C) 2020 Gabriel Venberg
*
* 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/>.
*/
/**
*
* @author toric
*/
public class BasePlusCommissionEmployee extends CommissionEmployee{
public double baseSalary;
public BasePlusCommissionEmployee(String startFirstName, String startLastName, int startSSN, double startGrossSales, double startCommissionRate, double startBaseSalary){
//we simply set minWage as baseSalary (or something lower, but it doesnt matter), as we wont run into that problem with this type of employee.
super(startFirstName, startLastName, startSSN, startGrossSales, startCommissionRate, startBaseSalary);
setBaseSalary(startBaseSalary);
}
public double getBaseSalary(){return baseSalary;}
public void setBaseSalary(double newBaseSalary){
if (newBaseSalary > 0){
baseSalary = newBaseSalary;
}
else{
throw new IllegalArgumentException("Base salary must be > 0");
}
}
public String toString(){
return super.toString()+", Min wage same as base salary";
}
public boolean equals(BasePlusCommissionEmployee testEmployee){
//dont actually need to test baseSalary, as it is set equal to minWage.
return super.equals(testEmployee);
}
public double getEarnings(){
return this.getCommissionRate()*this.getGrossSales()+baseSalary;
}
}

View file

@ -0,0 +1,86 @@
/*
* Copyright (C) 2020 Gabriel Venberg
*
* 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/>.
*/
/**
*
* @author toric
*/
/*going a bit above on this one.
in the US and europe (any country with a minimum wage), even commissioned employees are gaurenteed a minimum wage
no matter how little they sell on a given week. I will be implementing sutch a system.
Note this is different from a base+commission because it uses a floor, rather than an addition.
in the US, Every employee that recives commission must also recive a base pay, actually. The only weird thing is that the min base pay for tipped employees is lower.
But they still get a base pay. (The more you know!)
*/
public class CommissionEmployee extends Employee{
private double grossSales;
private double commissionRate;
private double minWage;
public CommissionEmployee(String startFirstName, String startLastName, int startSSN, double startGrossSales, double startCommissionRate, double startMinWage){
super(startFirstName, startLastName, startSSN);
setGrossSales(startGrossSales);
setCommissionRate(startCommissionRate);
setMinWage(startMinWage);
}
public double getGrossSales(){return grossSales;}
public double getCommissionRate(){return commissionRate;}
public double getMinWage(){return minWage;}
public void setGrossSales(double newGrossSales){
if (newGrossSales >= 0){
grossSales = newGrossSales;
}
else{
throw new IllegalArgumentException("grossSales cannot be negative");
}
}
public void setCommissionRate(double newCommissionRate){
if (newCommissionRate > 0){
commissionRate = newCommissionRate;
}
else{
throw new IllegalArgumentException("commissionRate must be >0");
}
}
public void setMinWage(double newMinWage){
if (newMinWage > 0){
minWage = newMinWage;
}
else{
throw new IllegalArgumentException("minWage must be > 0, and, legaly speaking, above or equal to your local minimum wage");
}
}
public String toString(){
return super.toString()+", Gross sales: $"+grossSales+", commissionRate: "+commissionRate+"%, minimum wage: $"+minWage;
}
public boolean equals(CommissionEmployee testEmployee){
return super.equals(testEmployee) && grossSales == testEmployee.getGrossSales() && commissionRate == testEmployee.getCommissionRate()
&& minWage == testEmployee.getMinWage();
}
public double getEarnings(){
return Math.max(minWage, (grossSales*commissionRate));
}
}

52
home07/src/Employee.java Normal file
View file

@ -0,0 +1,52 @@
/*
* Copyright (C) 2020 Gabriel Venberg
*
* 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/>.
*/
/**
*
* @author toric
*/
public abstract class Employee {
private String firstName;
private String lastName;
private int SSN;
public Employee(String startFirstName, String startLastName, int startSSN){
firstName = startFirstName;
lastName=startLastName;
SSN = startSSN;
}
public String getFirstName(){return firstName;}
public String getLastName(){return lastName;}
public int getSSN(){return SSN;}
public void setFirstName(String newFirstName){firstName = newFirstName;}
public void setLastName(String newLastName){lastName = newLastName;}
/*SSN's dont change, names do. But you told me to implement this. Im not sure why, and am actually quite curious to know.
* Did you intend the set method to be public? Am I supposed to be calling the set methods in the constructor (dispite the data not needing validation)?
*/
private void setSSN(int newSSN){SSN = newSSN;}
public abstract double getEarnings();
public String toString(){
return lastName+", "+firstName+", SSN: "+SSN;
}
public boolean equals(Employee testEmployee){
return firstName == testEmployee.getFirstName() && lastName == testEmployee.getLastName() && SSN == testEmployee.getSSN();
}
}

View file

@ -0,0 +1,54 @@
/*
* Copyright (C) 2020 Gabriel Venberg
*
* 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/>.
*/
/**
*
* @author toric
*/
import java.util.ArrayList;
public class EmployeesClient {
public static ArrayList<Employee> GenerateEmployees(){
ArrayList<Employee> employeeList = new ArrayList<Employee>();
int empType;
for (int i=0; i<10; i++){
empType = (int)(Math.random()*4);
//the random numbers are a bit of a mess, I should really write a random number method.
switch(empType){
case 0:
employeeList.add(new SalariedEmployee("Clone"+(i+1), "Venberg", (int)Math.random()*900000000+100000000, Math.random()*2701+300));
break;
case 1:
employeeList.add(new HourlyEmployee("Clone"+i, "Venberg", (int)Math.random()*900000000+100000000, Math.random()*41+10, Math.random()*51+10));
break;
case 2:
employeeList.add(new CommissionEmployee("Clone"+i, "Venberg", (int)Math.random()*900000000+100000000, Math.random()*10000, Math.random()*.1, Math.random()*701+300));
break;
case 3:
employeeList.add(new BasePlusCommissionEmployee("Clone"+i, "Venberg", (int)Math.random()*900000000+100000000, Math.random()*10000, Math.random()*.1, Math.random()*2701+300));
break;
}
}
return employeeList;
}
public static void main(String[] args){
ArrayList<Employee> employeeList = GenerateEmployees();
for (int i=0; i<employeeList.size(); i++){
System.out.println(employeeList.get(i).toString()+", Earning $"+employeeList.get(i).getEarnings()+" this week.");
}
}
}

View file

@ -0,0 +1,69 @@
/*
* Copyright (C) 2020 Gabriel Venberg
*
* 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/>.
*/
/**
*
* @author toric
*/
public class HourlyEmployee extends Employee{
private double wage;
private double hours;
public HourlyEmployee(String startFirstName, String startLastName, int startSSN, double startWage, double startHours){
super(startFirstName, startLastName, startSSN);
setWage(startWage);
setHours(startHours);
}
public double getWage(){return wage;}
public double getHours(){return hours;}
public void setWage(double newWage){
if (newWage > 0){
wage = newWage;
}
else{
throw new IllegalArgumentException("Wage must be > 0");
}
}
public void setHours(double newHours){
if (newHours > 0){
hours = newHours;
}
else{
throw new IllegalArgumentException("Hours must be > 0");
}
}
public String toString(){
return super.toString()+", Hourly Wage: $"+wage+"/hr, Weekly Hours: "+hours;
}
public boolean equals(HourlyEmployee testEmployee){
return super.equals(testEmployee) && hours == testEmployee.getHours() && wage == testEmployee.getWage();
}
public double getEarnings(){
if (hours > 40){
return 40*wage+(hours-40)*wage;
}
else{
return hours*wage;
}
}
}

View file

@ -0,0 +1,53 @@
/*
* Copyright (C) 2020 Gabriel Venberg
*
* 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/>.
*/
/**
*
* @author toric
*/
public class SalariedEmployee extends Employee{
private double weeklySalary;
public SalariedEmployee(String startFirstName, String startLastName, int startSSN, double startWeeklySalary){
super(startFirstName, startLastName, startSSN);
setWeeklySalary(startWeeklySalary);
}
public double getWeeklySalary(){return weeklySalary;}
public void setWeeklySalary(double newWeeklySalary){
if (newWeeklySalary > 0){
weeklySalary = newWeeklySalary;
}
else{
throw new IllegalArgumentException("Salary must be > 0");
}
}
public String toString(){
return super.toString()+", Weekly Salary: $"+weeklySalary;
}
public boolean equals(SalariedEmployee testEmployee){
return super.equals(testEmployee) && weeklySalary == testEmployee.getWeeklySalary();
}
//Im assuming you want getEarnings to return weekly earnings.
public double getEarnings(){
return weeklySalary;
}
}