diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/copilot.data.migration.ask2agent.xml b/.idea/copilot.data.migration.ask2agent.xml new file mode 100644 index 0000000..1f2ea11 --- /dev/null +++ b/.idea/copilot.data.migration.ask2agent.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/lab-java-basics.iml b/.idea/lab-java-basics.iml new file mode 100644 index 0000000..d8d3b6f --- /dev/null +++ b/.idea/lab-java-basics.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..8bfcdb7 --- /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/src/Employee.java b/.idea/src/Employee.java new file mode 100644 index 0000000..6a55057 --- /dev/null +++ b/.idea/src/Employee.java @@ -0,0 +1,39 @@ +public class Employee { + private String name; + private int id; + private double salary; + + + public Employee(String name, int id, double salary) { + setName(name); + this.id = id; + this.salary = salary; + } + + public String getName() { + return name; + } + public void setName(String name) { + if (name == null || name.isEmpty()) { + throw new NullPointerException("Name cannot be null or empty!!!!!"); + } + this.name = name; + } + + public int getId() { + return id; + } + public void setId(int id) { + this.id = id; + } + public double getSalary() { + return salary; + } + public void setSalary(double salary) { + this.salary = salary; + } + + public void printInfo() { + System.out.println("ID: " + id + ", Nombre: " + name + ", Salario: " + salary); + } +} diff --git a/.idea/src/Intern.java b/.idea/src/Intern.java new file mode 100644 index 0000000..41e3e75 --- /dev/null +++ b/.idea/src/Intern.java @@ -0,0 +1,20 @@ +class Intern extends Employee { + public static final double MAX_SALARY = 20000; + + public Intern(String name, int id, double salary) { + super(name, id, validateSalary(salary)); + } + + private static double validateSalary(double salary) { + if (salary > MAX_SALARY) { + System.out.println("Salario excede el máximo permitido para interns. Ajustando a " + MAX_SALARY); + return MAX_SALARY; + } + return salary; + } + + @Override + public void setSalary(double salary) { + super.setSalary(validateSalary(salary)); + } +} \ No newline at end of file diff --git a/.idea/src/Main.java b/.idea/src/Main.java new file mode 100644 index 0000000..ba69110 --- /dev/null +++ b/.idea/src/Main.java @@ -0,0 +1,34 @@ +import java.util.Random; + +public class Main { + public static void main(String[] args) { + + // --- Test arrays --- + int[] numbers = {5, 2, 9, 1, 7}; + + int diff = Utils.differenceMaxMin(numbers); + System.out.println("Diferencia entre mayor y menor: " + diff); + + Utils.findTwoSmallest(numbers); + + System.out.println("\n--- Empleados ---"); + + // Crear 10 empleados + Employee[] employees = new Employee[10]; + Random random = new Random(); + + for (int i = 0; i < employees.length; i++) { + if (i % 3 == 0) { + // Algunos serán interns + employees[i] = new Intern("Intern_" + i, i, 15000 + random.nextInt(10000)); + } else { + employees[i] = new Employee("Employee_" + i, i, 25000 + random.nextInt(20000)); + } + } + + // Imprimir todos los empleados + for (int i = 0; i < employees.length; i++) { + employees[i].printInfo(); + } + } +} \ No newline at end of file diff --git a/.idea/src/Utils.java b/.idea/src/Utils.java new file mode 100644 index 0000000..41cfba1 --- /dev/null +++ b/.idea/src/Utils.java @@ -0,0 +1,46 @@ +class Utils { + + // 1. Diferencia entre el mayor y el menor valor + public static int differenceMaxMin(int[] array) { + if (array.length < 1) { + throw new IllegalArgumentException("El array debe tener al menos un elemento"); + } + + int max = array[0]; + int min = array[0]; + + for (int i = 1; i < array.length; i++) { + if (array[i] > max) { + max = array[i]; + } + if (array[i] < min) { + min = array[i]; + } + } + + return max - min; + } + + // 2. Encontrar el menor y segundo menor + public static void findTwoSmallest(int[] array) { + if (array.length < 2) { + System.out.println("El array debe tener al menos dos elementos"); + return; + } + + int smallest = Integer.MAX_VALUE; + int secondSmallest = Integer.MAX_VALUE; + + for (int i = 0; i < array.length; i++) { + if (array[i] < smallest) { + secondSmallest = smallest; + smallest = array[i]; + } else if (array[i] < secondSmallest && array[i] != smallest) { + secondSmallest = array[i]; + } + } + + System.out.println("Menor: " + smallest); + System.out.println("Segundo menor: " + secondSmallest); + } +} 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/out/production/lab-java-basics/Employee.class b/out/production/lab-java-basics/Employee.class new file mode 100644 index 0000000..2a07464 Binary files /dev/null and b/out/production/lab-java-basics/Employee.class differ diff --git a/out/production/lab-java-basics/Intern.class b/out/production/lab-java-basics/Intern.class new file mode 100644 index 0000000..6603281 Binary files /dev/null and b/out/production/lab-java-basics/Intern.class differ diff --git a/out/production/lab-java-basics/Main.class b/out/production/lab-java-basics/Main.class new file mode 100644 index 0000000..c7a4df6 Binary files /dev/null and b/out/production/lab-java-basics/Main.class differ diff --git a/out/production/lab-java-basics/Utils.class b/out/production/lab-java-basics/Utils.class new file mode 100644 index 0000000..db84da9 Binary files /dev/null and b/out/production/lab-java-basics/Utils.class differ