Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/lab-java-basics.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions src/Employee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
public class Employee {
private String name;
private int age;
private double salary;
private String position;

public Employee(String name, int age, double salary, String position) {
this.name = name;
this.age = age;
this.salary = salary;
this.position = position;
}

public String getName() {
return name;
}

public int getAge() {
return age;
}

public double getSalary() {
return salary;
}

public String getPosition() {
return position;
}

public void setName(String name) {
this.name = name;
}

public void setAge(int age) {
this.age = age;
}

public void setSalary(double salary) {
this.salary = salary;
}

public void setPosition(String position) {
this.position = position;
}

public void printInfo() {
System.out.println("Name: " + name + ", Age: " + age + ", Salary: " + salary + ", Position: " + position);
}
}
22 changes: 22 additions & 0 deletions src/Intern.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
public class Intern extends Employee {

public static final double MAX_SALARY = 20000;

public Intern(String name, int age, double salary, String position) {
super(name, age, salary, position);

if (salary > MAX_SALARY) {
System.out.println("Salary too high, adjusted to max");
setSalary(MAX_SALARY);
}
}

@Override
public void setSalary(double salary) {
if (salary > MAX_SALARY) {
System.out.println("Can not exceed max salary");
} else {
super.setSalary(salary);
}
}
}
58 changes: 58 additions & 0 deletions src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import java.util.ArrayList;

public class Main {
public static void main(String[] args) {

ArrayList<Employee> employees = new ArrayList<>();

employees.add(new Employee("Laura", 25, 30000, "Manager"));
employees.add(new Employee("Maria", 29, 31000, "HR"));
employees.add(new Employee("Dani", 33, 28000, "Developer"));
employees.add(new Employee("Ivan", 36, 31000, "Designer"));
employees.add(new Employee("Fofo", 33, 35000, "Team Lead"));

employees.add(new Intern("Paco", 57, 18000, "Intern"));
employees.add(new Intern("Juanca", 27, 22000, "Intern"));
employees.add(new Intern("Edu", 34, 17000, "Intern"));
employees.add(new Intern("Raul", 30, 16000, "Intern"));
employees.add(new Intern("Alex", 30, 15000, "Intern"));

for (int i = 0; i < employees.size(); i++) {
employees.get(i).printInfo();
}

int[] numbers = {12, 5, 8, 21, 3};

System.out.println("Difference: " + getMaxMinDifference(numbers));
findTwoSmallest(numbers);
}

public static int getMaxMinDifference(int[] numbers) {
int max = numbers[0];
int min = numbers[0];

for (int i = 0; i < numbers.length; i++) {
if (numbers[i] > max) max = numbers[i];
if (numbers[i] < min) min = numbers[i];
}

return max - min;
}

public static void findTwoSmallest(int[] numbers) {
int smallest = Integer.MAX_VALUE;
int secondSmallest = Integer.MAX_VALUE;

for (int i = 0; i < numbers.length; i++) {
if (numbers[i] < smallest) {
secondSmallest = smallest;
smallest = numbers[i];
} else if (numbers[i] < secondSmallest && numbers[i] != smallest) {
secondSmallest = numbers[i];
}
}

System.out.println("Smallest: " + smallest);
System.out.println("Second smallest: " + secondSmallest);
}
}