Modify Employee & add HR & Accountant classes.

This commit is contained in:
Stanisław Jarocki 2023-05-09 16:28:11 +02:00
parent 83b541d890
commit ed6fbf9916
9 changed files with 98 additions and 36 deletions

View File

@ -5,13 +5,12 @@
</component>
<component name="ChangeListManager">
<list default="true" id="ddee1498-b134-461c-9aaa-55fbcffaf4ea" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/school-manager.iml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/Main.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Main.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/com/school/manager/people/Human.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/school/manager/people/Human.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/com/school/manager/people/employees/Employee.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/school/manager/people/employees/Employee.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/com/school/manager/people/employees/Experience.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/school/manager/people/employees/Experience.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/com/school/manager/people/employees/Position.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/school/manager/people/employees/Position.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />

View File

@ -4,10 +4,22 @@ import com.school.manager.people.employees.Position;
public class Main {
public static void main(String[] args) {
Human human = new Human("Stan", "Jarocki", "123456789", 2002, 11, 6);
Employee owner = new Employee(human, "Manager", 5000);
Human personOne = new Human("Mike", "Vezovski", "123456789", 2002, 11, 6);
Human personTwo = new Human("John", "Doe", "220002323", 1992, 11, 6);
Human personThree = new Human("Johnny", "Smith", "123453289", 2004, 11, 6);
owner.showInfo();
Employee employeeOne = new Employee(personOne, Position.MANAGER, 5000);
Employee employeeTwo = new Employee(personTwo, Position.ACCOUNTANT, 4100);
Employee employeeThree = new Employee(personThree, Position.TEACHER, 4000);
personOne.showInfo();
employeeOne.showInfo();
System.out.println("----------------------");
personTwo.showInfo();
employeeTwo.showInfo();
System.out.println("----------------------");
personThree.showInfo();
employeeThree.showInfo();
}
}

View File

@ -31,6 +31,8 @@ public class Human {
this.surname = surname;
this.pesel = pesel;
this.birthDate = LocalDate.of(birthYear, birthMonth, birthDay);
this.updateAge();
}
public String getName() {
@ -42,9 +44,9 @@ public class Human {
}
public void showInfo() {
System.out.println("Imię: " + getName());
System.out.println("Nazwisko: " + getSurname());
System.out.println("Wiek: " + getAge());
System.out.println("Name: " + getName());
System.out.println("Surname: " + getSurname());
System.out.println("Age: " + getAge());
System.out.println("PESEL: " + getPesel());
}
@ -52,7 +54,7 @@ public class Human {
LocalDate currentDate = LocalDate.now();
Period dateDifference = Period.between(birthDate, currentDate);
int currentAge = dateDifference.getYears();
this.setAge(age);
this.setAge(currentAge);
}
public boolean checkHasBirthdayToday() {

View File

@ -7,18 +7,18 @@ import java.util.List;
import java.util.Iterator;
public class Employee extends Human {
private List<String> positions = new ArrayList<String>();
private List<Position> positions = new ArrayList<Position>();
private int salary;
public List<String> getPositions() {
public List<Position> getPositions() {
return positions;
}
public void addPosition(String newPosition) {
public void addPosition(Position newPosition) {
this.positions.add(newPosition);
}
public Employee(Human human, String position, int salary) {
public Employee(Human human, Position position, int salary) {
super(human.getName(), human.getSurname(), human.getPesel(), human.getBirthDate().getYear(), human.getBirthDate().getMonthValue(), human.getBirthDate().getDayOfMonth());
this.positions.add(position);
this.salary = salary;
@ -29,11 +29,11 @@ public class Employee extends Human {
}
public void fire() {
List<String> positions = this.getPositions();
Iterator<String> iter = positions.iterator();
List<Position> positions = this.getPositions();
Iterator<Position> iter = positions.iterator();
while(iter.hasNext()) {
String position = iter.next();
Position position = iter.next();
iter.remove();
}
}
@ -47,19 +47,19 @@ public class Employee extends Human {
}
public void showInfo() {
List<String> positions = this.getPositions();
List<Position> positions = this.getPositions();
if (positions.size() == 0) {
System.out.println("Brak Stanowiska");
System.out.println("No position");
} else if (positions.size() == 1) {
System.out.println("Stanowisko: " + positions.get(0));
System.out.println("Position: " + positions.get(0).capitalize());
} else {
System.out.println("Stanowiska: ");
for (String position : positions) {
System.out.println(" - " + position);
System.out.println("Positions: ");
for (Position position : positions) {
System.out.println(" - " + position.capitalize());
}
};
System.out.println("Płaca: " + getSalary());
System.out.println("Salary: " + getSalary());
}
}

View File

@ -2,6 +2,6 @@ package com.school.manager.people.employees;
public enum Experience {
JUNIOR,
REGULAR,
SENIOR
}

View File

@ -0,0 +1,5 @@
package com.school.manager.people.employees.HumanResourcesEmployee;
public class Accountant {
}

View File

@ -0,0 +1,37 @@
package com.school.manager.people.employees.HumanResourcesEmployee;
import com.school.manager.people.Human;
import com.school.manager.people.employees.Employee;
import com.school.manager.people.employees.Position;
import java.util.List;
public class HumanResourcesEmployee extends Employee {
public Boolean getHasAccessToCompanyVault() {
return hasAccessToCompanyVault;
}
Boolean hasAccessToCompanyVault;
public Boolean getHasAccessToSensitiveEmployeesData() {
return hasAccessToSensitiveEmployeesData;
}
Boolean hasAccessToSensitiveEmployeesData;
List<SocialMedia> activeOnSocialMediaAccounts;
public HumanResourcesEmployee(Human human, Position position, int salary, Boolean hasAccessToCompanyVault) {
super(human, position, salary);
this.hasAccessToSensitiveEmployeesData = hasAccessToCompanyVault;
this.hasAccessToCompanyVault = hasAccessToCompanyVault;
}
public void openVault() {
if(this.getHasAccessToCompanyVault()) {
System.out.println("Vault has been opened!");
} else {
System.out.println("This employee doesn't have access to the vault!");
}
}
}

View File

@ -0,0 +1,7 @@
package com.school.manager.people.employees.HumanResourcesEmployee;
public enum SocialMedia {
FACEBOOK,
INSTAGRAM,
TIKTOK
}

View File

@ -2,12 +2,12 @@ package com.school.manager.people.employees;
public enum Position {
MANAGER,
SUPERVISOR,
ENGINEER,
ANALYST,
CLERK;
TECHNICIAN,
TEACHER,
ACCOUNTANT;
public String capitalize() {
return this.name().toLowerCase();
};
String name = this.name();
return name.substring(0, 1) + name.substring(1).toLowerCase();
}
}