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..c90834f --- /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..4eb4f51 --- /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/out/production/lab-java-basics/ArrayLogic.class b/out/production/lab-java-basics/ArrayLogic.class new file mode 100644 index 0000000..aaad40c Binary files /dev/null and b/out/production/lab-java-basics/ArrayLogic.class differ diff --git a/out/production/lab-java-basics/Employee.class b/out/production/lab-java-basics/Employee.class new file mode 100644 index 0000000..8456c8d 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..38559f2 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..0c693c3 Binary files /dev/null and b/out/production/lab-java-basics/Main.class differ diff --git a/src/ArrayLogic.java b/src/ArrayLogic.java new file mode 100644 index 0000000..ee9ddc4 --- /dev/null +++ b/src/ArrayLogic.java @@ -0,0 +1,49 @@ +public class ArrayLogic { + + // TASK 1: Método para obtener la diferencia + public static int getDifference(int[] numbers) { + if (numbers.length < 1) return 0; + + int min = numbers[0]; + int max = numbers[0]; + + for (int i = 1; i < numbers.length; i++) { + if (numbers[i] < min) { + min = numbers[i]; + } + if (numbers[i] > max) { + max = numbers[i]; + } + } + + return max - min; + } + + // TASK 2: Encontrar el más pequeño y el segundo más pequeño + public static void printTwoSmallest(int[] numbers) { + // Validación: Necesitamos al menos 2 números para comparar + if (numbers.length < 2) { + System.out.println("The array must have at least 2 elements."); + return; + } + + // Inicializamos con el valor más alto posible en Java + int smallest = Integer.MAX_VALUE; + int secondSmallest = Integer.MAX_VALUE; + + for (int num : numbers) { + if (num < smallest) { + // El antiguo más pequeño ahora es el segundo más pequeño + secondSmallest = smallest; + // El actual es el nuevo "rey" de la pequeñez + smallest = num; + } else if (num < secondSmallest && num != smallest) { + // Si el número no es el más pequeño, pero es menor que el segundo + secondSmallest = num; + } + } + + System.out.println("The smallest is: " + smallest); + System.out.println("The second smallest is: " + secondSmallest); + } +} \ No newline at end of file diff --git a/src/Employee.java b/src/Employee.java new file mode 100644 index 0000000..b0a9c62 --- /dev/null +++ b/src/Employee.java @@ -0,0 +1,44 @@ +public class Employee { + // Atributos + private String id; + private String name; + private double salary; + private boolean isFullTime; + + // Constructor + public Employee(String id, String name, double salary, boolean isFullTime) { + setId(id); + setName(name); + setSalary(salary); + setFullTime(isFullTime); + } + + public String getRole() { + return "EMPLOYEE"; + } + + // Getters y Setters + public String getId() { return id; } + public void setId(String id) { this.id = id; } + + public String getName() { return name; } + public void setName(String name) { this.name = name; } + + public double getSalary() { return salary; } + public void setSalary(double salary) { this.salary = salary; } + + public boolean isFullTime(){ return isFullTime; } + public void setFullTime(boolean isFullTime) {this.isFullTime = isFullTime;} + + // toString() + @Override + public String toString() { + // Si es fullTime, añadimos un "badge". Si no, se queda vacío. + String statusTag = isFullTime ? " (Full-Time)" : ""; + + return "ID: '" + id + '\'' + + ", Name: '" + name + '\'' + + ", Salary: " + salary + "€ " + + getRole() + statusTag; + } +} \ No newline at end of file diff --git a/src/Intern.java b/src/Intern.java new file mode 100644 index 0000000..a63127d --- /dev/null +++ b/src/Intern.java @@ -0,0 +1,32 @@ +public class Intern extends Employee { + + // Constante para el límite de sueldo + private static final double MAX_SALARY_LIMIT = 20000.0; + + // Constructor: Al llamar a super, ponemos "false" en el booleano de Full Time + public Intern(String id, String name, double salary) { + super(id, name, salary, false); + setSalary(salary); + } + + // Sobrescribimos el Rol + @Override + public String getRole() { + return "INTERN STUDENT"; + } + + // Sobrescribimos el Setter + @Override + public void setSalary(double salary) { + validateAndSetSalary(salary); + } + + // Método interno de validación + private void validateAndSetSalary(double salary) { + if (salary > MAX_SALARY_LIMIT) { + super.setSalary(MAX_SALARY_LIMIT); + } 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..f17c563 --- /dev/null +++ b/src/Main.java @@ -0,0 +1,79 @@ +import java.util.ArrayList; +import java.util.List; + +public class Main { + public static void main(String[] args) { + + // ---> TAREAS 1 Y 2 (Lógica de arrays) + int[] data = {12, 45, 7, 33, 2, 19}; + System.out.println("--- TASKS 1 AND 2 ---"); + System.out.println("Difference (T1): " + ArrayLogic.getDifference(data)); + ArrayLogic.printTwoSmallest(data); + + // ---> TAREA 5: Lista de empleados y becarios + System.out.println("\n--- TASK 5 => Employees & Interns ---"); + + // Lista de 10 empleados + List names = new ArrayList<>(); + names.add("Manuel Candela"); + names.add("Ana García"); + names.add("Carlos Pérez"); + names.add("Lucía Fernández"); + names.add("David Jiménez"); + names.add("Elena Ruiz"); + names.add("Sergio Torres"); + names.add("Marta Luna"); + names.add("Iván Ramos"); + names.add("Sonia Castro"); + + List ids = new ArrayList<>(); + ids.add("EMP-001"); + ids.add("EMP-002"); + ids.add("EMP-003"); + ids.add("EMP-004"); + ids.add("EMP-005"); + ids.add("EMP-006"); + ids.add("EMP-007"); + ids.add("EMP-008"); + ids.add("EMP-009"); + ids.add("EMP-010"); + + List employeeList = new ArrayList<>(); + + //METODO DE CREAR EMPLEADOS ALEATORIOS BY IGOR! + + for (int i = 0; i < names.size(); i++) { + if (i % 3 == 0) { + employeeList.add(new Intern(ids.get(i), names.get(i), 18000.0)); + } else { + employeeList.add(new Employee(ids.get(i), names.get(i), 30000.0, true)); + } + } +// for (int i = 0; i < names.size(); i++) { +// double increasingSalary = 25000.0 + (i * 4000.0); +// if (i < 5) { +// employeeList.add(new Employee(ids.get(i), names.get(i), increasingSalary, true)); +// } else { +// employeeList.add(new Intern(ids.get(i), names.get(i), increasingSalary)); +// } +// } + + // Imprimimos la lista + for (Employee employee : employeeList) { + System.out.println(employee); + } + + // Tarea 4: Validación + System.out.println("\n--- Attempting to raise salaries above the limit ---"); + + // 1. Probamos con Ana García + + employeeList.get(3).setSalary(22200.0); + System.out.println("Salary of " + employeeList.get(3).getName() + " (Fixed): " + employeeList.get(3).getSalary()); + + // 2. Probamos con Iván Ramos + + employeeList.get(9).setSalary(40000.0); + System.out.println("Salary of " + employeeList.get(9).getName() + " (Intern): " + employeeList.get(9).getSalary()); + } +} \ No newline at end of file