diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..ab1f416 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/lab-java-basics.iml b/.idea/lab-java-basics.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/lab-java-basics.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..188022c --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..505d07d --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/Employee.java b/src/Employee.java new file mode 100644 index 0000000..7a18fe7 --- /dev/null +++ b/src/Employee.java @@ -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); + } + } diff --git a/src/Intern.java b/src/Intern.java new file mode 100644 index 0000000..024fe92 --- /dev/null +++ b/src/Intern.java @@ -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); + } + } + } diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..d5ac69c --- /dev/null +++ b/src/Main.java @@ -0,0 +1,58 @@ +import java.util.ArrayList; + +public class Main { + public static void main(String[] args) { + + ArrayList 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); + } +} \ No newline at end of file