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-basics-java.iml b/.idea/lab-basics-java.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/.idea/lab-basics-java.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..f5bd2df --- /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..87dec2e --- /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-basics-java/Employee.class b/out/production/lab-basics-java/Employee.class new file mode 100644 index 0000000..6e6da16 Binary files /dev/null and b/out/production/lab-basics-java/Employee.class differ diff --git a/out/production/lab-basics-java/Intern.class b/out/production/lab-basics-java/Intern.class new file mode 100644 index 0000000..b4f5b0b Binary files /dev/null and b/out/production/lab-basics-java/Intern.class differ diff --git a/out/production/lab-basics-java/Main.class b/out/production/lab-basics-java/Main.class new file mode 100644 index 0000000..a86c138 Binary files /dev/null and b/out/production/lab-basics-java/Main.class differ diff --git a/src/Employee.java b/src/Employee.java new file mode 100644 index 0000000..4e4f721 --- /dev/null +++ b/src/Employee.java @@ -0,0 +1,55 @@ +public class Employee { + private int id; + private String name; + private int age; + private double salary; + + public Employee(int id, String name, int age, double salary) { + setId(id); + setName(name); + setAge(age); + setSalary(salary); + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + 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 double getSalary() { + return salary; + } + + public void setSalary(double salary) { + this.salary = salary; + } + + @Override + public String toString() { + return "Employee{" + + "id=" + id + + ", name='" + name + '\'' + + ", age=" + age + + ", salary=" + salary + + '}'; + } +} diff --git a/src/Intern.java b/src/Intern.java new file mode 100644 index 0000000..685b49b --- /dev/null +++ b/src/Intern.java @@ -0,0 +1,16 @@ +public class Intern extends Employee{ + private static final double MAX_SALARY = 20000.0; + + + public Intern(int id, String name, int age, double salary) { + super(id, name, age, salary); + } + + @Override + public void setSalary(double salary) { + if (salary > MAX_SALARY) { + System.out.println("Salary exceeds maximum"); + super.setSalary(MAX_SALARY); + } else {super.setSalary(salary);} + } +} diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..50880b1 --- /dev/null +++ b/src/Main.java @@ -0,0 +1,73 @@ +import java.util.ArrayList; + +public class Main { + public static void main(String[] args) { + + //Creamos Array! + int[] misNumeros = {5, 2, 4, 6, 9, 10}; + + int resultado = getDifference(misNumeros); + System.out.println("La diferencia es: " + resultado); + findTwoSmallest(misNumeros); + + //ArrayList de empleados + ArrayList employees = new ArrayList<>(); + employees.add(new Employee(1, "JuanDeDios", 18, 500)); + employees.add(new Employee(2, "Pedro", 20, 10000)); + employees.add(new Employee(3, "Maria", 32, 15000)); + employees.add(new Employee(4, "Antonio", 45, 19000)); + employees.add(new Employee(5, "Palomino", 62, 17000)); + employees.add(new Employee(6, "Paulina", 34, 13000)); + employees.add(new Employee(7, "Paulino", 38, 20000)); + employees.add(new Employee(8, "Adolfo", 40, 11000)); + employees.add(new Intern (9, "Manuel", 39, 25000)); + employees.add(new Employee(10, "Francisco", 24, 17500)); + + System.out.println("Lista de empleados"); + + //Bucle para cada empleado + for(Employee emp: employees){ + System.out.println(emp); + } + + } + + //Creación Metod1 + public static int getDifference(int[] numbers) { + int max = numbers[0]; + int min = numbers[0]; + + //Bucle para recorrer array de números + for (int i = 0; i < numbers.length; i++) { + System.out.println(numbers[i]); + if (numbers[i] > max) { + max = numbers[i]; + } else if (numbers[i] < min) { + min = numbers[i]; + } + } + return max - min; + } + + //Metod2 + public static void findTwoSmallest(int[] numbers) { + int firstSmallest = Integer.MAX_VALUE; + int secondSmallest = Integer.MAX_VALUE; + + for (int i = 0; i < numbers.length; i++) { + if (numbers[i] < firstSmallest) { + secondSmallest = firstSmallest; + firstSmallest = numbers[i]; + } else if (numbers[i] < secondSmallest) { + secondSmallest = numbers[i]; + } + + } + System.out.println("El más pequeño es " + firstSmallest); + System.out.println("----------------"); + System.out.println("El segundo más pequeño es " + secondSmallest); + } + + + +}