From cd85b34d3e99e93085bb5086ec6b224c1f59afb3 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 4 Apr 2026 13:40:05 +0200 Subject: [PATCH 1/4] Haciendo el lab --- src/Employee.java | 52 +++++++++++++++++++++++++++++++++++++++++++++++ src/Intern.java | 24 ++++++++++++++++++++++ src/Task1.java | 29 ++++++++++++++++++++++++++ src/Task2.java | 30 +++++++++++++++++++++++++++ 4 files changed, 135 insertions(+) create mode 100644 src/Employee.java create mode 100644 src/Intern.java create mode 100644 src/Task1.java create mode 100644 src/Task2.java diff --git a/src/Employee.java b/src/Employee.java new file mode 100644 index 0000000..b73dd77 --- /dev/null +++ b/src/Employee.java @@ -0,0 +1,52 @@ +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..22c1f4c --- /dev/null +++ b/src/Intern.java @@ -0,0 +1,24 @@ +public class Intern { + 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("Cannot exceed max salary"); + } else { + super.setSalary(salary); + } + } + } +} diff --git a/src/Task1.java b/src/Task1.java new file mode 100644 index 0000000..9c5a191 --- /dev/null +++ b/src/Task1.java @@ -0,0 +1,29 @@ +public class Task1 { + public static int getDifference(int[] array) { + if (array == null || array.length < 1) { + System.out.println("Array must have at least 1 element"); + return 0; + } + + int max = array[0]; + int min = array[0]; + + for (int i = 0; i < array.length; i++) { + if (array[i] > max) { + max = array[i]; + } + if (array[i] < min) { + min = array[i]; + } + } + + return max - min; + } + public static void main(String[] args) { + + int[] numbers = {12, 5, 8, 21, 3}; + int result = getDifference(numbers); + + System.out.println("Difference between max and min: " + result); + } +} diff --git a/src/Task2.java b/src/Task2.java new file mode 100644 index 0000000..b86752d --- /dev/null +++ b/src/Task2.java @@ -0,0 +1,30 @@ +public class Task2 { + public static void main(String[] args) { + + int[] numbers = {8, 7, 1, 9, 15, 5}; // valores inventados + + findTwoSmallest(numbers); + } + + public static void findTwoSmallest(int[] numbers) { + if (numbers == null || numbers.length < 2) { + System.out.println("Array must have at least 2 elements"); + return; + } + + 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); + } +} From 9717009605055a7926f5a18e245af152c0656cc2 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 5 Apr 2026 20:46:20 +0200 Subject: [PATCH 2/4] Lab terminado --- src/Intern.java | 4 +--- src/Main.java | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ src/Task1.java | 29 ------------------------- src/Task2.java | 30 ------------------------- 4 files changed, 59 insertions(+), 62 deletions(-) create mode 100644 src/Main.java delete mode 100644 src/Task1.java delete mode 100644 src/Task2.java diff --git a/src/Intern.java b/src/Intern.java index 22c1f4c..a74eeee 100644 --- a/src/Intern.java +++ b/src/Intern.java @@ -1,5 +1,4 @@ -public class Intern { - public class Intern extends Employee { +public class Intern extends Employee { public static final double MAX_SALARY = 20000; @@ -21,4 +20,3 @@ public void setSalary(double salary) { } } } -} diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..d2d9e78 --- /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, 32000, "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 diff --git a/src/Task1.java b/src/Task1.java deleted file mode 100644 index 9c5a191..0000000 --- a/src/Task1.java +++ /dev/null @@ -1,29 +0,0 @@ -public class Task1 { - public static int getDifference(int[] array) { - if (array == null || array.length < 1) { - System.out.println("Array must have at least 1 element"); - return 0; - } - - int max = array[0]; - int min = array[0]; - - for (int i = 0; i < array.length; i++) { - if (array[i] > max) { - max = array[i]; - } - if (array[i] < min) { - min = array[i]; - } - } - - return max - min; - } - public static void main(String[] args) { - - int[] numbers = {12, 5, 8, 21, 3}; - int result = getDifference(numbers); - - System.out.println("Difference between max and min: " + result); - } -} diff --git a/src/Task2.java b/src/Task2.java deleted file mode 100644 index b86752d..0000000 --- a/src/Task2.java +++ /dev/null @@ -1,30 +0,0 @@ -public class Task2 { - public static void main(String[] args) { - - int[] numbers = {8, 7, 1, 9, 15, 5}; // valores inventados - - findTwoSmallest(numbers); - } - - public static void findTwoSmallest(int[] numbers) { - if (numbers == null || numbers.length < 2) { - System.out.println("Array must have at least 2 elements"); - return; - } - - 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); - } -} From 9f5bf445409ea0bdb3baf2f63c6c5b8751acba45 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 5 Apr 2026 20:47:09 +0200 Subject: [PATCH 3/4] Lab end --- .idea/.gitignore | 10 ++++++++++ .idea/lab-java-basics.iml | 9 +++++++++ .idea/misc.xml | 6 ++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ 5 files changed, 39 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/lab-java-basics.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml 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 From 39d9cbab0bf833b6d33bfddf97caf161d7b1b14a Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 5 Apr 2026 20:53:17 +0200 Subject: [PATCH 4/4] Lab end --- src/Employee.java | 5 +---- src/Intern.java | 2 +- src/Main.java | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Employee.java b/src/Employee.java index b73dd77..7a18fe7 100644 --- a/src/Employee.java +++ b/src/Employee.java @@ -44,9 +44,6 @@ public void setPosition(String position) { } public void printInfo() { - System.out.println("Name: " + name + - ", Age: " + age + - ", Salary: " + salary + - ", Position: " + position); + System.out.println("Name: " + name + ", Age: " + age + ", Salary: " + salary + ", Position: " + position); } } diff --git a/src/Intern.java b/src/Intern.java index a74eeee..024fe92 100644 --- a/src/Intern.java +++ b/src/Intern.java @@ -14,7 +14,7 @@ public Intern(String name, int age, double salary, String position) { @Override public void setSalary(double salary) { if (salary > MAX_SALARY) { - System.out.println("Cannot exceed max salary"); + System.out.println("Can not exceed max salary"); } else { super.setSalary(salary); } diff --git a/src/Main.java b/src/Main.java index d2d9e78..d5ac69c 100644 --- a/src/Main.java +++ b/src/Main.java @@ -6,7 +6,7 @@ public static void main(String[] args) { ArrayList employees = new ArrayList<>(); employees.add(new Employee("Laura", 25, 30000, "Manager")); - employees.add(new Employee("Maria", 29, 32000, "HR")); + 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"));