inital commit

This commit is contained in:
gabriel venberg 2021-03-26 22:39:35 -05:00
commit d1948b0e58
67 changed files with 5280 additions and 0 deletions

View file

@ -0,0 +1,3 @@
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

View file

@ -0,0 +1,162 @@
/*
* Copyright (C) 2021 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/>.
*/
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
/**
*
* @author toric
*/
public class Client {
public static void main(String[] args) throws FileNotFoundException{
File inputFile = new File("/home/toric/Downloads/employeeList.txt"); //TODO!!! change to C:/data/EmployeeList.txt //supposedly with java you can use / on windows as well as linux.
Scanner file = new Scanner(inputFile);
Scanner scan = new Scanner(System.in);
final int maxEmployees = 20;
Employee[] employeeList = new Employee[maxEmployees];
//declaing the variables we will use in the loop.
//im not sure whether or not its best practice to declare inside a loop,
//but Im not sure its a good idea to re-instantiate the variable every loop.
char employeeType;
int id;
String name;
String titleOrPosition; // can use this for both, saving us a tiny bit of memory.
int salary;
double hourlyRate;
//each line is one object
for( int i = 0; i<maxEmployees; i++){
if(file.hasNextLine()==false){
break;
}
employeeType = file.next().charAt(0); //comparing with a single char string was giving me strange results.
id = file.nextInt();
name = file.next();
titleOrPosition = file.next();
if (employeeType == 'S'){
salary = file.nextInt();
employeeList[i]= new Salaried(name, titleOrPosition, id, salary);
}
else{
hourlyRate = file.nextDouble();
employeeList[i] = new Hourly(name, titleOrPosition, id, hourlyRate);
}
file.nextLine();
}
//WHY CANT JAVA JUST HAVE A PRINT() FUNCTION? IT WOULD SAVE ME SO MUCH TYPING!
System.out.println("creating salaried employee.");
System.out.print("enter the employees name: ");
name = scan.next();
System.out.println();
System.out.print("enter the employees title: ");
titleOrPosition = scan.next();
System.out.println();
System.out.print("enter the employees ID number: ");
id = scan.nextInt();
System.out.println();
System.out.print("enter the employees salary: ");
salary = scan.nextInt();
System.out.println();
//getting how many employees we currently have to figure out where I should put it in the array
employeeList[employeeList[0].getEmployeeCount()] =
new Salaried(name, titleOrPosition, id, salary);
System.out.println("creating hourly employee");
System.out.print("enter the employees name: ");
name = scan.next();
System.out.println();
System.out.print("enter the employees position: ");
titleOrPosition = scan.next();
System.out.println();
System.out.print("enter the employees ID number: ");
id = scan.nextInt();
System.out.println();
System.out.print("enter the employees hourly wage: ");
hourlyRate = scan.nextDouble();
System.out.println();
employeeList[employeeList[0].getEmployeeCount()] =
new Hourly(name, titleOrPosition, id, salary);
for (int i=0; i < maxEmployees; i++){
//cant just let it print the null values, it throws errors if you do.
if (employeeList[i] != null){
System.out.println(employeeList[i].toString());
}
else{
System.out.println("value is a null value");
}
}
for (int i=0; i < maxEmployees; i++){
if (employeeList[i] != null){
if (employeeList[i] instanceof Salaried){
//this FEELS hacky, but other ways Ive tried havent worked. Is there a way to 'cast in place', so to speak?
Salaried s = (Salaried) employeeList[i];
s.setSalary((int)((double)s.getSalary()*1.1));
employeeList[i] = (Employee) s;
}
else{
Hourly h = (Hourly) employeeList[i];
h.setHourlyRate(h.getHourlyRate()*1.1);
employeeList[i] = (Employee) h;
}
}
else{
break;
}
}
for (int i=0; i < maxEmployees; i++){
if (employeeList[i] != null){
System.out.println(employeeList[i].toString());
}
else{
break;
}
}
//its telling that I choose these names immediately, I read way to many crypto blogs!
Employee emp1 = new Employee("bob", 1);
Employee emp2 = new Employee("bob", 1);
Employee emp3 = new Employee("alice", 2);
System.out.println(emp1.equals(emp2)+" should be true");
System.out.println(emp2.equals(emp3)+" should be false");
Hourly hour1 = new Hourly("alice", "sysAdmin", 1, 100);
Hourly hour2 = new Hourly("alice", "sysAdmin", 1, 100);
Hourly hour3 = new Hourly("bob", "dev", 2, 100);
System.out.println(hour1.equals(hour2)+" should be true");
System.out.println(hour2.equals(hour3)+" should be false");
Salaried sal1 = new Salaried("bob", "sysAdmin", 1, 100);
Salaried sal2 = new Salaried("bob", "sysAdmin", 1, 100);
Salaried sal3 = new Salaried("alice", "dev", 2, 100);
System.out.println(sal1.equals(sal2)+" should be true");
System.out.println(sal2.equals(sal3)+" should be false");
}
}

View file

@ -0,0 +1,96 @@
/*
* Copyright (C) 2021 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
* @version 01/25/2021
*/
public class Employee {
private static int employeeCount =0;
private int id;
private String name;
/**
*
* @param name
* @param id
*/
public Employee (String name, int id){
this.id = id;
this.name = name;
employeeCount++;
}
/**
*
* @return id
*/
public int getID(){return id;}
/**
*
* @return name
*/
public String getName(){return name;}
/**
*
* @return employeeCount
*/
public int getEmployeeCount(){return employeeCount;}
/**
*
* @param id sets id
*/
public void setID(int id){
this.id = id;
}
/**
*
* @param name sets name
*/
public void setName(String name){
this.name = name;
}
/**
*
* @param o the object to be compared against
* @return true if the objects are equal
*/
public boolean equals( Object o )
{
if (!(o instanceof Employee)){
return false;
}
Employee e=(Employee)o;
return id == e.id
&& name.equals( e.name );
}
/**
*
* @return contents of the instance
*/
public String toString(){
return getClass().getName() + '@' + ':'+name+':'+id+':'+employeeCount;
}
}

View file

@ -0,0 +1,99 @@
/*
* Copyright (C) 2021 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 Hourly extends Employee{
private String position;
private double hourlyRate;
private static int hourlyCount = 0;
/**
*
* @param name
* @param position
* @param id
* @param hourlyRate
*/
public Hourly(String name, String position, int id, double hourlyRate){
super(name, id);
this.position = position;
this.hourlyRate = hourlyRate;
hourlyCount++;
}
/**
*
* @return position
*/
public String getPosition(){return position;}
/**
*
* @return hourlyRate
*/
public double getHourlyRate(){return hourlyRate;}
/**
*
* @return hourlyCount
*/
public int getHourlyCount(){return hourlyCount;}
/**
*
* @param position sets position
*/
public void setPosition(String position){
this.position = position;
}
/**
*
* @param hourlyRate sets hourlyRate
*/
public void setHourlyRate(double hourlyRate){
this.hourlyRate = hourlyRate;
}
/**
*
* @param o object to compare against
* @return true if contents of object are equal
*/
public boolean equals (Object o){
if (!(o instanceof Hourly)){
return false;
}
Hourly h = (Hourly) o;
return super.equals(h)
&& position.equals(h.position)
&& hourlyRate == h.hourlyRate;
}
/**
*
* @return contents of instance
*/
public String toString(){
return super.toString()+':'+getClass().getName()+'@'+position+':'+hourlyRate;
}
}

View file

@ -0,0 +1,99 @@
/*
* Copyright (C) 2021 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/>.
*/
/**
*@version 01/26/2021
* @author toric
*/
public class Salaried extends Employee {
private String title;
private int salary;
private static int salariedCount;
/**
*
* @param name
* @param title
* @param id
* @param salary
*/
public Salaried(String name, String title, int id, int salary){
super(name,id);
this.title = title;
this.salary = salary;
salariedCount++;
}
/**
*
* @return title
*/
public String getTitle(){return title;}
/**
*
* @return salary
*/
public int getSalary(){return salary;}
/**
*
* @return salariedCount
*/
public int getSalariedCount(){return salariedCount;}
/**
*
* @param title sets title
*/
public void setTitle(String title){
this.title = title;
}
/**
*
* @param salary sets salary
*/
public void setSalary(int salary){
this.salary = salary;
}
/**
*
* @param o the object to comapre against
* @return true if the objects are equal
*/
public boolean equals (Object o){
if (!(o instanceof Salaried)){
return false;
}
Salaried s = (Salaried)o;
return super.equals(s)
&& title.equals(s.title)
&& salary == s.salary;
}
/**
*
* @return String contents of instance
*/
public String toString(){
return super.toString()+':'+getClass().getName()+'@'+title+':'+salary;
}
}