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
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.

Binary file added out/production/lab-java-basics/ArrayLogic.class
Binary file not shown.
Binary file added out/production/lab-java-basics/Employee.class
Binary file not shown.
Binary file added out/production/lab-java-basics/Intern.class
Binary file not shown.
Binary file added out/production/lab-java-basics/Main.class
Binary file not shown.
49 changes: 49 additions & 0 deletions src/ArrayLogic.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
44 changes: 44 additions & 0 deletions src/Employee.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
32 changes: 32 additions & 0 deletions src/Intern.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
79 changes: 79 additions & 0 deletions src/Main.java
Original file line number Diff line number Diff line change
@@ -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<String> 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<String> 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<Employee> 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());
}
}