diff --git a/src/Employee.java b/src/Employee.java new file mode 100644 index 0000000..80a6192 --- /dev/null +++ b/src/Employee.java @@ -0,0 +1,55 @@ +public class Employee { + private String name; + private int age; + private String position; + private double salary; + + public Employee(String name, int age, String position, double salary) { + this.name = name; + this.age = age; + this.position = position; + this.salary = salary; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + public double getSalary() { + return salary; + } + + public void setSalary(double salary) { + this.salary = salary; + } + + @Override + public String toString() { + return "Employee{" + + "name='" + name + '\'' + + ", age=" + age + + ", position='" + position + '\'' + + ", salary=" + salary + + '}'; + } +} diff --git a/src/Intern.java b/src/Intern.java new file mode 100644 index 0000000..a283b55 --- /dev/null +++ b/src/Intern.java @@ -0,0 +1,20 @@ +public class Intern extends Employee { + public static final double MAX_SALARY = 20000; + + public Intern(String name, int age, String position, double salary) { + super(name, age, position, salary); + + if (salary > MAX_SALARY) { + setSalary(MAX_SALARY); + } + } + + @Override + public void setSalary(double salary) { + if (salary > MAX_SALARY) { + super.setSalary(MAX_SALARY); + } else { + super.setSalary(salary); + } + } +} \ No newline at end of file diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..9c712db --- /dev/null +++ b/src/Main.java @@ -0,0 +1,52 @@ +public class Main { + + public static void main(String[] args) { + int[] numbers = {1, 2, 3, 4, 5}; + + int biggest = numbers[0]; + int smallest = numbers[0]; + + for (int number : numbers) { + if (number > biggest) { + biggest = number; + } + + if (number < smallest) { + smallest = number; + } + } + + int result = biggest - smallest; + System.out.println("Difference between biggest and smallest: " + result); + + int secondSmallest = biggest; + + for (int number : numbers) { + if (number > smallest && number < secondSmallest) { + secondSmallest = number; + } + } + + System.out.println("Smallest: " + smallest); + System.out.println("Second smallest: " + secondSmallest); + + Employee[] employees = new Employee[10]; + + employees[0] = new Employee("Mina", 32, "Project Manager", 52000); + employees[1] = new Employee("Jonas", 27, "Backend Developer", 46000); + employees[2] = new Employee("Sara", 29, "UX Designer", 43000); + employees[3] = new Employee("Leo", 24, "Customer Support", 31000); + employees[4] = new Employee("Nina", 38, "Team Lead", 61000); + employees[5] = new Employee("Tom", 34, "Data Analyst", 48000); + employees[6] = new Employee("Elena", 26, "Marketing Assistant", 35000); + employees[7] = new Intern("Yuna", 22, "Software Intern", 18000); + employees[8] = new Intern("Marco", 23, "Business Intern", 25000); + employees[9] = new Employee("David", 41, "Account Manager", 54000); + + System.out.println("Employee list:"); + + for (Employee employee : employees) { + System.out.println(employee); + } + } +} \ No newline at end of file