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
73 changes: 73 additions & 0 deletions src/Employee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
public class Employee {

//Creando los atributos de la clase employee
private String name;
private int age;
private String gender;
private double salary;
private String id;

//Creando el constructor
public Employee(String name, int age, String gender, double salary, String id) {
this.name = name;
this.age = age;
this.gender = gender;
this.salary = salary;
this.id = id;
}

//Creando getters y setters

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

public String getGender() {
return gender;
}

public void setGender(String gender) {
this.gender = gender;
}

public double getSalary() {
return salary;
}

public void setSalary(double salary) {
this.salary = salary;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

//generando toString

@Override
public String toString() {
return "Employee{" +
"name='" + name + '\'' +
", age=" + age +
", gender='" + gender + '\'' +
", salary=" + salary +
", id='" + id + '\'' +
'}';
}
}
58 changes: 58 additions & 0 deletions src/EmployeesApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import java.util.ArrayList;

public class EmployeesApp {
public static void main (String[] args) {
System.out.println("Lab1_Ironhack");

/* ==================EXERCISE #1=================== */

//Declarando el array de numeros
int[] numbers = {2, 5, 12, 24, 81};

//Ejercicio 1: Obteniendo la diferencia
int result = Exercises.diferenceMinMax(numbers);
System.out.println("The diference betwen the max and min is: " + result);

//Ejercicio 2: Saber el primer y segundo num. más pequeño
Exercises.FindSmallSeconsSmall(numbers);

//Pruebas

Intern intern1 = new Intern("Ana", 22, "female", 18000, "EI0123");
Intern intern2 = new Intern("Max", 22, "male", 24000, "EI0113");

System.out.println("============== INTERNS CREATED ==============");
System.out.println(intern1);
System.out.println(intern2);

intern1.setSalary(19000);
intern2.setSalary(30000);

System.out.println("============== INTERNS UPDATED ==============");
System.out.println(intern1);
System.out.println(intern2);

System.out.println("intern1 updated salary: " + intern1.getSalary());
System.out.println("intern2 updated salary: " + intern2.getSalary());

//Ejercicio 5: App que lista empleados
ArrayList<Employee> employees = new ArrayList<>();
employees.add(new Employee("Marc", 24, "male", 23000, "EI124"));
employees.add(new Employee("Ana", 32, "female", 28000, "EI111"));
employees.add(new Employee("David", 43, "male", 30000, "EI456"));
employees.add(new Employee("Jonny", 21, "male", 20001, "EI213"));
employees.add(new Employee("Diana", 30, "female", 29000, "EI101"));
employees.add(new Employee("Mariona", 56, "female", 33000, "EI983"));
employees.add(new Employee("Luis", 42, "male", 34000, "EI233"));
employees.add(new Employee("Marcos", 36, "male", 31020, "EI244"));
employees.add(new Employee("Uriol", 31, "male", 30800, "EI412"));
employees.add(new Employee("Hanna", 44, "female", 33000, "EI164"));

System.out.println("============== EMPLOYEE LIST ==============");
for(Employee emp : employees){
System.out.println(emp);
}
}

}

39 changes: 39 additions & 0 deletions src/Exercises.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
public class Exercises {

//Ejercicio1: Metodo para calcular diferencia min max

public static int diferenceMinMax(int[] numbers){
//Declarando variables para almacenar el min y max
int max = numbers[0];
int min = numbers[0];
//Bucle for
for(int i = 0; i < numbers.length; i++){
if(numbers[i] > max) {
max = numbers[i];
}
if(numbers[i] < min){
min = numbers[i];
}
}
return max - min;
}

//Ejercicio 2: Metodo para calcular el 1er y 2do numero menor
public static void FindSmallSeconsSmall(int [] numbers){
//variables iniciadas en el máximo posible
int min = Integer.MAX_VALUE;
int seconMin = Integer.MAX_VALUE;

//Lop para interar y saber el menor y segundo m.
for(int num : numbers){
if(num < min){
seconMin = min;
min = num;
} else if (num < seconMin && num != min) {
seconMin = num;

}
}
System.out.println("The smallest num is: " + min + " and the second smallest is : " + seconMin);
}
}
29 changes: 29 additions & 0 deletions src/Intern.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
public class Intern extends Employee {

//Constante de salario max
private static final double MAX_SALARY = 20000;

//Constructor
//Se puede usar un ternario: condicion? valor cierto : valor falso
/* super(name, age, gender, salary > MAX_SALARY ? MAX_SALARY : salary, id)
* mas limpio
* ya que el if no se usa dentro del super y hay que crear un metodo entonces
* */
public Intern(String name, int age, String gender, double salary, String id) {
super(name, age, gender, validateSalary(salary), id);
}

//metodo para validad el maximo del salario
private static double validateSalary(double salary){
if(salary > MAX_SALARY){
return MAX_SALARY;
}else {
return salary;
}
}

@Override
public void setSalary(double salary) {
super.setSalary(validateSalary(salary));
}
}