Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .gitignore
Binary file not shown.
10 changes: 10 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/lab-java-basics.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

164 changes: 164 additions & 0 deletions Notes.md
Original file line number Diff line number Diff line change
@@ -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.

---------------------------------------------------------

---------------------------------------------------------

---------------------------------------------------------
Binary file added out/production/lab-java-basics/A01_Main.class
Binary file not shown.
Binary file not shown.
Binary file added out/production/lab-java-basics/A03_Employee.class
Binary file not shown.
Binary file added out/production/lab-java-basics/A04_Intern.class
Binary file not shown.
Binary file not shown.
22 changes: 22 additions & 0 deletions src/A01_Main.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
48 changes: 48 additions & 0 deletions src/A02_ArrayUtils.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
48 changes: 48 additions & 0 deletions src/A03_Employee.java
Original file line number Diff line number Diff line change
@@ -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 +
'}';
}
}
46 changes: 46 additions & 0 deletions src/A04_Intern.java
Original file line number Diff line number Diff line change
@@ -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 +
'}';
}
}
Loading