diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cb74bf6 Binary files /dev/null and b/.gitignore differ diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..30cf57e --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml 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..0280eb4 --- /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/Notes.md b/Notes.md new file mode 100644 index 0000000..7fb3845 --- /dev/null +++ b/Notes.md @@ -0,0 +1,164 @@ +# Lab Notes | Java Basics + +## Purpose + +Practice Java fundamentals through the implementation of array algorithms, class design with inheritance and data validation, applying object-oriented programming principles. + +## Scope + +- Array search algorithms (maximum, minimum, second minimum) +- `Employee` class design with encapsulation (getters/setters) +- Inheritance with `Intern` class and salary limit validation +- Object instantiation and display in a collection + +--- + +## Timeline + +- **Date:** 2026-05-18 +- **Start:** 11:14 +- **End:** 13:14 +- **Total:** 120 min + +| Task | Estimated time | +|-------------------------------------|----------------| +| Setup (GitHub, IntelliJ, structure) | 35 min | +| T1 — getDifference | 10 min | +| T2 — findTwoSmallest | 15 min | +| T3 — Employee | 20 min | +| T4 — Intern | 25 min | +| T5 — EmployeeList | 15 min | +| **Total** | **120 min** | + +--- + +## Versioning + +### Index + +| Version | Date | Description | +|---------|------------|------------------------------------------| +| v1.0.0 | 2026-05-18 | Initial submission. 5 tasks completed. | +| v1.1.0 | 2026-05-18 | Comments added to all classes. | + +--- + +#### v1.0.0 + +### Feedback received + +- T1: Excellent. Solid and efficient implementation. +- T2: Excellent. Optimal solution using two variables and a single loop. +- T3: Fantastic. Well-structured class with a useful toString() method. +- T4: Well done. Correct inheritance and salary limit validated. +- T5: Excellent. Correct use of both employee types. + +--- + +#### v1.1.0 + +### Feedback received + +- T1: Excellent. Efficient implementation using a single loop for both max and min. +- T2: Excellent. Impeccable logic handling equal or similar values. +- T3: Fantastic. Well-structured class with clean encapsulation and readable toString(). +- T4: Well done. Correct inheritance, salary cap enforced with informative warning. +- T5: Excellent. Polymorphism demonstrated with both Employee and Intern types. Great attention to detail. + +--------------------------------------------------------- + +--------------------------------------------------------- + +--------------------------------------------------------- + +--------------------------------------------------------- + +--------------------------------------------------------- + +--------------------------------------------------------- + +--------------------------------------------------------- + +--------------------------------------------------------- + +--------------------------------------------------------- + +--------------------------------------------------------- + +--------------------------------------------------------- + +--------------------------------------------------------- + + +# Lab Notes | Fundamentos de Java + +## Objeto + +Practicar fundamentos de Java mediante la implementación de algoritmos con arrays, diseño de clases con herencia y validación de datos, aplicando programación orientada a objetos. + +## Alcance + +- Algoritmos de búsqueda en arrays (máximo, mínimo, segundo mínimo) +- Diseño de clase `Employee` con encapsulamiento (getters/setters) +- Herencia con clase `Intern` y validación de límite salarial +- Instanciación y visualización de objetos en colección + +--- + +## Temporalización + +- **Fecha:** 2026-05-18 +- **Inicio:** 11:14 +- **Fin:** 13:14 +- **Total:** 120 min + +| Tarea | Tiempo estimado | +|------------------------------------|-----------------| +| Setup (GitHub, IntelliJ, estructura) | 35 min | +| T1 — getDifference | 10 min | +| T2 — findTwoSmallest | 15 min | +| T3 — Employee | 20 min | +| T4 — Intern | 25 min | +| T5 — EmployeeList | 15 min | +| **Total** | **120 min** | + +--- + +## Versionado + +### Índice + +| Versión | Fecha | Descripción | +|---------|------------|------------------------------------------| +| v1.0.0 | 2026-05-18 | Entrega inicial. 5 tareas completadas. | +| v1.1.0 | 2026-05-18 | Comentarios añadidos a todas las clases. | + +--- + +#### v1.0.0 + +### Feedback recibido + +- T1: Excelente. Implementación sólida y eficiente. +- T2: Excelente. Solución óptima con dos variables y un solo bucle. +- T3: Fantástico. Clase bien estructurada con toString() útil. +- T4: Bien hecho. Herencia correcta y límite salarial validado. +- T5: Excelente. Uso correcto de ambos tipos de empleados. + +--- + +#### v1.1.0 + +### Feedback recibido + +- T1: Excelente. Implementación eficiente con un solo bucle para máximo y mínimo. +- T2: Excelente. Lógica impecable que maneja valores iguales o similares. +- T3: Fantástico. Clase bien estructurada con encapsulamiento limpio y toString() legible. +- T4: Bien hecho. Herencia correcta, límite salarial aplicado con advertencia informativa. +- T5: Excelente. Polimorfismo demostrado con ambos tipos de empleados. Gran atención al detalle. + +--------------------------------------------------------- + +--------------------------------------------------------- + +--------------------------------------------------------- \ No newline at end of file diff --git a/out/production/lab-java-basics/A01_Main.class b/out/production/lab-java-basics/A01_Main.class new file mode 100644 index 0000000..3a37716 Binary files /dev/null and b/out/production/lab-java-basics/A01_Main.class differ diff --git a/out/production/lab-java-basics/A02_ArrayUtils.class b/out/production/lab-java-basics/A02_ArrayUtils.class new file mode 100644 index 0000000..aed2eb9 Binary files /dev/null and b/out/production/lab-java-basics/A02_ArrayUtils.class differ diff --git a/out/production/lab-java-basics/A03_Employee.class b/out/production/lab-java-basics/A03_Employee.class new file mode 100644 index 0000000..7ace838 Binary files /dev/null and b/out/production/lab-java-basics/A03_Employee.class differ diff --git a/out/production/lab-java-basics/A04_Intern.class b/out/production/lab-java-basics/A04_Intern.class new file mode 100644 index 0000000..ba90af3 Binary files /dev/null and b/out/production/lab-java-basics/A04_Intern.class differ diff --git a/out/production/lab-java-basics/A05_EmployeeList.class b/out/production/lab-java-basics/A05_EmployeeList.class new file mode 100644 index 0000000..22d64ab Binary files /dev/null and b/out/production/lab-java-basics/A05_EmployeeList.class differ diff --git a/src/A01_Main.java b/src/A01_Main.java new file mode 100644 index 0000000..61fb6c7 --- /dev/null +++ b/src/A01_Main.java @@ -0,0 +1,22 @@ +/** + * A01_Main — Entry point of the Java Basics Lab. + * Orchestrates the execution of all tasks. + */ +public class A01_Main { + + public static void main(String[] args) { + + // Task 1: Calculate the difference between the largest and smallest value in an array + int[] numbers = {3, 1, 7, 2, 9, 4}; + System.out.println("=== Task 1 ==="); + System.out.println("Difference: " + A02_ArrayUtils.getDifference(numbers)); + + // Task 2: Find and print the smallest and second smallest elements + System.out.println("=== Task 2 ==="); + A02_ArrayUtils.findTwoSmallest(numbers); + + // Task 5: Create 10 employees (including interns) and print all their properties + System.out.println("=== Task 5 ==="); + A05_EmployeeList.printEmployees(); + } +} \ No newline at end of file diff --git a/src/A02_ArrayUtils.java b/src/A02_ArrayUtils.java new file mode 100644 index 0000000..0c84d22 --- /dev/null +++ b/src/A02_ArrayUtils.java @@ -0,0 +1,48 @@ +/** + * A02_ArrayUtils — Utility class for array operations. + * Contains methods for Tasks 1 and 2. + */ +public class A02_ArrayUtils { + + /** + * Task 1: Returns the difference between the largest and smallest value in an array. + * Uses a single loop to find max and min simultaneously. + * @param array integer array with length >= 1 + * @return difference between max and min values + */ + public static int getDifference(int[] array) { + int max = array[0]; + int min = array[0]; + + for (int i = 1; i < array.length; i++) { + if (array[i] > max) max = array[i]; // update max if current value is greater + if (array[i] < min) min = array[i]; // update min if current value is smaller + } + + return max - min; + } + + /** + * Task 2: Finds and prints the smallest and second smallest elements in an array. + * Uses two variables initialized to MAX_VALUE and a single loop. + * @param array integer array with length >= 2 + */ + public static void findTwoSmallest(int[] array) { + int smallest = Integer.MAX_VALUE; + int secondSmallest = Integer.MAX_VALUE; + + for (int i = 0; i < array.length; i++) { + if (array[i] < smallest) { + // New smallest found: shift current smallest to second position + secondSmallest = smallest; + smallest = array[i]; + } else if (array[i] < secondSmallest && array[i] != smallest) { + // New second smallest found (must differ from smallest) + secondSmallest = array[i]; + } + } + + System.out.println("Smallest: " + smallest); + System.out.println("Second smallest: " + secondSmallest); + } +} \ No newline at end of file diff --git a/src/A03_Employee.java b/src/A03_Employee.java new file mode 100644 index 0000000..a8cfbaa --- /dev/null +++ b/src/A03_Employee.java @@ -0,0 +1,48 @@ +/** + * A03_Employee — Represents an employee of a company. + * Contains personal and professional properties with getters and setters. + */ +public class A03_Employee { + + private String firstName; + private String lastName; + private String department; + private double salary; + + /** + * Constructor with all properties. + */ + public A03_Employee(String firstName, String lastName, String department, double salary) { + this.firstName = firstName; + this.lastName = lastName; + this.department = department; + this.salary = salary; + } + + // --- Getters and Setters --- + + public String getFirstName() { return firstName; } + public void setFirstName(String firstName) { this.firstName = firstName; } + + public String getLastName() { return lastName; } + public void setLastName(String lastName) { this.lastName = lastName; } + + public String getDepartment() { return department; } + public void setDepartment(String department) { this.department = department; } + + public double getSalary() { return salary; } + public void setSalary(double salary) { this.salary = salary; } + + /** + * Returns a readable string with all employee properties. + */ + @Override + public String toString() { + return "Employee{" + + "firstName='" + firstName + '\'' + + ", lastName='" + lastName + '\'' + + ", department='" + department + '\'' + + ", salary=" + salary + + '}'; + } +} \ No newline at end of file diff --git a/src/A04_Intern.java b/src/A04_Intern.java new file mode 100644 index 0000000..03eed8a --- /dev/null +++ b/src/A04_Intern.java @@ -0,0 +1,46 @@ +/** + * A04_Intern — Represents an intern. Extends A03_Employee. + * Interns have a maximum salary cap of 20000. + * If a higher salary is set, it is automatically capped and a warning is printed. + */ +public class A04_Intern extends A03_Employee { + + // Maximum salary allowed for any intern (constant) + public static final double MAX_SALARY = 20000; + + /** + * Constructor — validates salary on creation. + */ + public A04_Intern(String firstName, String lastName, String department, double salary) { + super(firstName, lastName, department, 0); // initialize with 0, then validate + setSalary(salary); + } + + /** + * Overrides setSalary to enforce the salary cap. + * If salary exceeds MAX_SALARY, it is set to MAX_SALARY and a warning is printed. + */ + @Override + public void setSalary(double salary) { + if (salary > MAX_SALARY) { + System.out.println("Warning: Intern salary cannot exceed " + MAX_SALARY + ". Setting to max."); + super.setSalary(MAX_SALARY); + } else { + super.setSalary(salary); + } + } + + /** + * Returns a readable string including the salary cap for debugging purposes. + */ + @Override + public String toString() { + return "Intern{" + + "firstName='" + getFirstName() + '\'' + + ", lastName='" + getLastName() + '\'' + + ", department='" + getDepartment() + '\'' + + ", salary=" + getSalary() + + ", maxSalary=" + MAX_SALARY + + '}'; + } +} \ No newline at end of file diff --git a/src/A05_EmployeeList.java b/src/A05_EmployeeList.java new file mode 100644 index 0000000..c5fd1f8 --- /dev/null +++ b/src/A05_EmployeeList.java @@ -0,0 +1,28 @@ +/** + * A05_EmployeeList — Creates a list of 10 employees (including interns) + * and prints all their properties. + * Demonstrates polymorphism: both Employee and Intern objects stored in the same array. + */ +public class A05_EmployeeList { + + public static void printEmployees() { + // Array of 10 employees — mix of regular employees and interns + A03_Employee[] employees = { + new A03_Employee("Alice", "Smith", "Engineering", 55000), + new A03_Employee("Bob", "Jones", "Marketing", 48000), + new A03_Employee("Carlos", "Garcia", "Engineering", 62000), + new A03_Employee("Diana", "Lee", "HR", 45000), + new A03_Employee("Eva", "Muller", "Finance", 70000), + new A04_Intern("Frank", "Brown", "Engineering", 18000), + new A04_Intern("Grace", "Wilson", "Marketing", 25000), // exceeds cap → set to 20000 + new A03_Employee("Hana", "Kim", "Finance", 67000), + new A03_Employee("Ivan", "Petrov", "Engineering", 58000), + new A04_Intern("Julia", "Rossi", "HR", 15000) + }; + + // Print all properties using each class's toString() method + for (A03_Employee e : employees) { + System.out.println(e); + } + } +} \ No newline at end of file