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,113 @@
/*
* 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.GregorianCalendar;
import java.util.Calendar;
public class Date {
private int day, month, year;
public Date (int startDay, int startMonth, int startYear){
setYear(startYear);
setMonth(startMonth);
setDay(startDay);
}
/**
* returns day
* @return
*/
public int getDay(){
return day;
}
/**
* returns month
* @return
*/
public int getMonth(){
return month;
}
/**
* returns year
* @return
*/
public int getYear(){
return year;
}
/**
* sets the day, throws error if day is impossible under the gregorian calander.
* @param newDay
*/
private void setDay(int newDay){
GregorianCalendar checker = new GregorianCalendar(year, month, day);
//found in javadoc for gregoriancalander. will also take into account leap years.
int daysInMonth = checker.getActualMaximum(Calendar.DAY_OF_MONTH);
if (newDay<=daysInMonth){
day=newDay;
}
else {
throw new IllegalArgumentException("newDay out of range for set month and year");
}
}
/**
* sets month, throws error if month is above 12.
* @param newMonth
*/
private void setMonth(int newMonth){
if (newMonth<=12){
month=newMonth;
}
else {
throw new IllegalArgumentException("newMonth must be <= 12");
}
}
/**
* sets year, returns error if year is before 1582
* @param newYear
*/
private void setYear(int newYear){
if (newYear>=1582){
year=newYear;
}
else {
throw new IllegalArgumentException("newYear must be >= 1582, the year the gregorian calander was adopted.");
}
}
/**
* outputs a string representation of the date in mm/dd/yyyy format.
* @return
*/
public String toString(){
return (month+"/"+day+"/"+year);
}
/**
* tests if date obgect is equal to another date object.
* @param testDate
* @return
*/
public boolean equals(Date testDate){
return testDate.getDay()==day&testDate.getMonth()==month&testDate.getYear()==year;
}
}

View file

@ -0,0 +1,132 @@
/*
* 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 Employee {
private int emplID;
private static int nextID = 1000;
private static int noOfEmployees = 0;
private String firstName;
private String lastName;
private Date birthDate;
private Date hireDate;
/**
* Constructor that assigns full name, birthdate, hiredate, as well as automatically assigning an ID.
* @param startFirstName
* @param startLastName
* @param startBirthDate
* @param startHireDate
*/
public Employee(String startFirstName, String startLastName, Date startBirthDate, Date startHireDate){
setFirstName(startFirstName); // what does overridable method call in constructor mean?
setLastName(startLastName);
setBirthDate(startBirthDate);
setHireDate(startHireDate);
emplID=nextID;
nextID++;
noOfEmployees++;
}
//normally would go multiline, but get methods are so formulaic and short its just as readable on one line.
/**
* returns emplID
* @return
*/
public int getemplID(){return emplID;}
/**
* returns firstName
* @return
*/
public String getFirstName(){return firstName;}
/**
* returns lastName
* @return
*/
public String getLastName(){return lastName;}
/**
* returns birthDate
* @return
*/
public Date getBirthDate(){return birthDate;}
/**
* returns hireDate
* @return
*/
public Date getHireDate(){return hireDate;}
//names change, so they are public.
/**
* sets firstName
* @param newFirstName
*/
public void setFirstName(String newFirstName){
firstName=newFirstName;
}
/**
* sets lastName
* @param newLastName
*/
public void setLastName(String newLastName){
lastName=newLastName;
}
//birth dates and hire dates dont change, so these are private.
/**
* sets birthDate
* @param newBirthDate
*/
private void setBirthDate(Date newBirthDate) {
birthDate=newBirthDate;
}
/**
* sets hireDate
* @param newHireDate
*/
private void setHireDate(Date newHireDate){
hireDate=newHireDate;
}
/**
* tests if all values are equal to another instance of Employee
* @param testEmployee
* @return
*/
public boolean equals(Employee testEmployee){
return testEmployee.getFirstName().equals(firstName)&testEmployee.getLastName().equals(lastName)& //multiline for readability. if statements would be slower, I think.
testEmployee.getBirthDate().equals(birthDate)&testEmployee.getHireDate().equals(hireDate)&
testEmployee.getemplID()==emplID;
}
/**
* returns a human readable string representing Employee.
* @return
*/
public String toString(){
return (firstName+" "+lastName+", born "+birthDate.toString()+", hired "+hireDate.toString()+
" employee ID: "+emplID);
}
/**
* returns the number of times an instance of Employee has been created.
* @return
*/
static public int getEmployeeCount(){
return noOfEmployees;
}
}

View file

@ -0,0 +1,41 @@
/*
* 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 EmployeeTest {
public static void main(String[] args){
System.out.println("you have "+Employee.getEmployeeCount()+" employees.");
//turns out you can declare a new object inside declaring an object!
Employee bob = new Employee("Bob", "Ross", new Date(1,1,1995), new Date(20,9,2007));
Employee doug = new Employee("Douglass", "Mcdonell", new Date(5,7,1968), new Date(23,4,1992));
Employee linus = new Employee("Linus", "Torvalds", new Date(28,12,1969), new Date(30,6,1985));
//do I really have to explain these things?
System.out.println(bob.toString());
System.out.println(doug.toString());
System.out.println(linus.toString());
System.out.println("you have "+Employee.getEmployeeCount()+" employees.");
System.out.println("is bob the same as doug? T/F: "+bob.equals(doug));
}
}