Compare commits
No commits in common. 'lab3' and 'main' have entirely different histories.
Binary file not shown.
Binary file not shown.
@ -1,8 +0,0 @@
|
|||||||
package base;
|
|
||||||
|
|
||||||
public interface EmployeeActions {
|
|
||||||
void hire();
|
|
||||||
void fire();
|
|
||||||
void transfer();
|
|
||||||
void accrueSalary();
|
|
||||||
}
|
|
@ -1,9 +1,77 @@
|
|||||||
package base;
|
package base;
|
||||||
|
|
||||||
public interface Scientist {
|
public abstract class Scientist {
|
||||||
double getSalary();
|
protected double salary;
|
||||||
void setSalary(double salary);
|
protected int seniority;
|
||||||
int getSeniority();
|
|
||||||
void setSeniority(int seniority);
|
public Scientist(double salary, int seniority) {
|
||||||
double computeBonus();
|
this.salary = salary;
|
||||||
|
this.seniority = seniority;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getSalary() {
|
||||||
|
return salary;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSalary(double salary) {
|
||||||
|
this.salary = salary;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSeniority() {
|
||||||
|
return seniority;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeniority(int seniority) {
|
||||||
|
this.seniority = seniority;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Абстрактный метод вычисления надбавки
|
||||||
|
public abstract double computeBonus();
|
||||||
|
|
||||||
|
// Методы действий
|
||||||
|
public void hire() {
|
||||||
|
System.out.println(getClass().getSimpleName() + " принят на работу.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fire() {
|
||||||
|
System.out.println(getClass().getSimpleName() + " уволен.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void transfer() {
|
||||||
|
System.out.println(getClass().getSimpleName() + " перемещён на новую должность.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void accrueSalary() {
|
||||||
|
double bonus = computeBonus();
|
||||||
|
double totalSalary = salary + bonus;
|
||||||
|
System.out.println("Начислена зарплата: " + totalSalary +
|
||||||
|
" (ставка: " + salary + ", надбавка: " + bonus + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Переопределение equals() и hashCode() для проверки уникальности объектов
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
|
||||||
|
Scientist scientist = (Scientist) o;
|
||||||
|
return Double.compare(scientist.salary, salary) == 0 &&
|
||||||
|
seniority == scientist.seniority;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return java.util.Objects.hash(getClass(), salary, seniority);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Переопределение toString() для вывода характеристик объекта
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return getClass().getSimpleName() +
|
||||||
|
" { salary = " + salary +
|
||||||
|
", seniority = " + seniority +
|
||||||
|
", bonus = " + computeBonus() +
|
||||||
|
", totalSalary = " + (salary + computeBonus()) +
|
||||||
|
" }";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,67 +1,16 @@
|
|||||||
package engineer;
|
package engineer;
|
||||||
|
|
||||||
import base.Scientist;
|
import base.Scientist;
|
||||||
import base.EmployeeActions;
|
|
||||||
|
|
||||||
public class Engineer implements Scientist, EmployeeActions {
|
public class Engineer extends Scientist {
|
||||||
private double salary;
|
|
||||||
private int seniority;
|
|
||||||
|
|
||||||
public Engineer(double salary, int seniority) {
|
public Engineer(double salary, int seniority) {
|
||||||
this.salary = salary;
|
super(salary, seniority); // вызов конструктора суперкласса
|
||||||
this.seniority = seniority;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double computeBonus() {
|
public double computeBonus() {
|
||||||
return salary * seniority * 0.01;
|
double x = 0.01;
|
||||||
}
|
return salary * seniority * x;
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getSalary() {
|
|
||||||
return salary;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setSalary(double salary) {
|
|
||||||
this.salary = salary;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getSeniority() {
|
|
||||||
return seniority;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setSeniority(int seniority) {
|
|
||||||
this.seniority = seniority;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void hire() {
|
|
||||||
System.out.println("Engineer hired.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void fire() {
|
|
||||||
System.out.println("Engineer fired.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void transfer() {
|
|
||||||
System.out.println("Engineer transferred.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void accrueSalary() {
|
|
||||||
System.out.println("Total salary: " + (salary + computeBonus()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Engineer { salary = " + salary +
|
|
||||||
", seniority = " + seniority +
|
|
||||||
", bonus = " + computeBonus() +
|
|
||||||
", totalSalary = " + (salary + computeBonus()) + " }";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,67 +1,16 @@
|
|||||||
package junior;
|
package junior;
|
||||||
|
|
||||||
import base.Scientist;
|
import base.Scientist;
|
||||||
import base.EmployeeActions;
|
|
||||||
|
|
||||||
public class JuniorScientist implements Scientist, EmployeeActions {
|
public class JuniorScientist extends Scientist {
|
||||||
private double salary;
|
|
||||||
private int seniority;
|
|
||||||
|
|
||||||
public JuniorScientist(double salary, int seniority) {
|
public JuniorScientist(double salary, int seniority) {
|
||||||
this.salary = salary;
|
super(salary, seniority); // вызов конструктора суперкласса
|
||||||
this.seniority = seniority;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double computeBonus() {
|
public double computeBonus() {
|
||||||
return salary * seniority * 0.02;
|
double x = 0.02;
|
||||||
}
|
return salary * seniority * x;
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getSalary() {
|
|
||||||
return salary;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setSalary(double salary) {
|
|
||||||
this.salary = salary;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getSeniority() {
|
|
||||||
return seniority;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setSeniority(int seniority) {
|
|
||||||
this.seniority = seniority;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void hire() {
|
|
||||||
System.out.println("Junior Scientist hired.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void fire() {
|
|
||||||
System.out.println("Junior Scientist fired.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void transfer() {
|
|
||||||
System.out.println("Junior Scientist transferred.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void accrueSalary() {
|
|
||||||
System.out.println("Total salary: " + (salary + computeBonus()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "JuniorScientist { salary = " + salary +
|
|
||||||
", seniority = " + seniority +
|
|
||||||
", bonus = " + computeBonus() +
|
|
||||||
", totalSalary = " + (salary + computeBonus()) + " }";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,67 +1,16 @@
|
|||||||
package senior;
|
package senior;
|
||||||
|
|
||||||
import base.Scientist;
|
import base.Scientist;
|
||||||
import base.EmployeeActions;
|
|
||||||
|
|
||||||
public class SeniorScientist implements Scientist, EmployeeActions {
|
public class SeniorScientist extends Scientist {
|
||||||
private double salary;
|
|
||||||
private int seniority;
|
|
||||||
|
|
||||||
public SeniorScientist(double salary, int seniority) {
|
public SeniorScientist(double salary, int seniority) {
|
||||||
this.salary = salary;
|
super(salary, seniority); // вызов конструктора суперкласса
|
||||||
this.seniority = seniority;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double computeBonus() {
|
public double computeBonus() {
|
||||||
return salary * seniority * 0.03;
|
double x = 0.03;
|
||||||
}
|
return salary * seniority * x;
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getSalary() {
|
|
||||||
return salary;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setSalary(double salary) {
|
|
||||||
this.salary = salary;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getSeniority() {
|
|
||||||
return seniority;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setSeniority(int seniority) {
|
|
||||||
this.seniority = seniority;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void hire() {
|
|
||||||
System.out.println("Senior Scientist hired.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void fire() {
|
|
||||||
System.out.println("Senior Scientist fired.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void transfer() {
|
|
||||||
System.out.println("Senior Scientist transferred.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void accrueSalary() {
|
|
||||||
System.out.println("Total salary: " + (salary + computeBonus()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "SeniorScientist { salary = " + salary +
|
|
||||||
", seniority = " + seniority +
|
|
||||||
", bonus = " + computeBonus() +
|
|
||||||
", totalSalary = " + (salary + computeBonus()) + " }";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue