lab2
tisit 3 weeks ago
parent 7b631ed852
commit 863a001f64

BIN
._.git

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
._out

Binary file not shown.

BIN
._src

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

Binary file not shown.

@ -1,5 +1,44 @@
import base.Scientist;
import senior.SeniorScientist;
import junior.JuniorScientist;
import engineer.Engineer;
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
Scientist s1 = new SeniorScientist(1000, 10);
Scientist s2 = new SeniorScientist(1000, 10); // дубликат s1
Scientist j1 = new JuniorScientist(800, 5);
Scientist j2 = new JuniorScientist(900, 6);
Scientist j3 = new JuniorScientist(800, 5); // дубликат j1
Scientist e1 = new Engineer(700, 4);
Scientist e2 = new Engineer(700, 4); // дубликат e1
Scientist e3 = new Engineer(750, 3);
Scientist s3 = new SeniorScientist(1100, 8);
Scientist j4 = new JuniorScientist(950, 7);
// Формирование списка уникальных объектов типа Scientist
ArrayList<Scientist> uniqueScientists = new ArrayList<>();
Scientist[] allScientists = { s1, s2, j1, j2, j3, e1, e2, e3, s3, j4 };
for (Scientist sc : allScientists) {
if (!uniqueScientists.contains(sc)) {
uniqueScientists.add(sc);
}
}
// В случае если уникальных объектов больше 9, выводим первые 9
int count = Math.min(uniqueScientists.size(), 9);
System.out.println("Величина надбавок и общая зарплата для уникальных научных сотрудников:");
for (int i = 0; i < count; i++) {
Scientist sc = uniqueScientists.get(i);
double bonus = sc.computeBonus();
double totalSalary = sc.getSalary() + bonus;
System.out.println("Объект " + (i+1) + ": " +
"Надбавка = " + bonus + ", Общая зарплата = " + totalSalary);
}
}
}
}

@ -0,0 +1,66 @@
package base;
public abstract class Scientist {
protected double salary;
protected int seniority;
public Scientist(double salary, int seniority) {
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("Научный сотрудник принят на работу.");
}
public void fire() {
System.out.println("Научный сотрудник уволен.");
}
public void transfer() {
System.out.println("Научный сотрудник перемещён на новую должность.");
}
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);
}
}

@ -0,0 +1,16 @@
package engineer;
import base.Scientist;
public class Engineer extends Scientist {
public Engineer(double salary, int seniority) {
super(salary, seniority);
}
@Override
public double computeBonus() {
double x = 0.01;
return salary * seniority * x;
}
}

@ -0,0 +1,16 @@
package junior;
import base.Scientist;
public class JuniorScientist extends Scientist {
public JuniorScientist(double salary, int seniority) {
super(salary, seniority);
}
@Override
public double computeBonus() {
double x = 0.02;
return salary * seniority * x;
}
}

@ -0,0 +1,16 @@
package senior;
import base.Scientist;
public class SeniorScientist extends Scientist {
public SeniorScientist(double salary, int seniority) {
super(salary, seniority);
}
@Override
public double computeBonus() {
double x = 0.03;
return salary * seniority * x;
}
}
Loading…
Cancel
Save