diff --git a/funcionarios/Employee.java b/funcionarios/Employee.java new file mode 100644 index 0000000..7b83c06 --- /dev/null +++ b/funcionarios/Employee.java @@ -0,0 +1,51 @@ +package funcionarios; + +public class Employee { + + private int id; + private String name; + private double salary; + + public Employee () {} + + public Employee(int id, String name, double salary) { + this.id = id; + this.name = name; + this.salary = 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 double getSalary() { + return salary; + } + + public void setSalary(double salary) { + this.salary = salary; + } + + public void increaseSalary (Double percentage) { + salary += salary * percentage / 100; + + } + + public String toString() { + return id + ", " + name + ", " + String.format("%.2f", salary); + } + + +} diff --git a/funcionarios/Program.java b/funcionarios/Program.java new file mode 100644 index 0000000..5ea802c --- /dev/null +++ b/funcionarios/Program.java @@ -0,0 +1,78 @@ +package funcionarios; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.Scanner; + +public class Program { + + public static void main(String[] args) { + + Locale.setDefault(Locale.US); + Scanner sc = new Scanner(System.in); + + List list = new ArrayList<>(); + + System.out.print("How many employees will be registered?"); + int n = sc.nextInt(); + + //List id = new ArrayList<>(); + //List name = new ArrayList<>(); Nao serao necessarios. + //List salary = new ArrayList<>(); Instanciar um nome objeto com os 3 atributos. + + for (int i = 0; i < n; i++) { + System.out.println(); + System.out.println("Employee #" + (i+1) + " :"); + System.out.print("Id: "); + Integer id = sc.nextInt(); + System.out.print("Name: "); + sc.nextLine(); + String name = sc.nextLine(); + System.out.print("Salary: "); + Double salary = sc.nextDouble(); + + // Criar um funcionario para instanciar os objetos. Dentro do 'for'. + + Employee emp = new Employee (id, name, salary); + list.add(emp); + } + + System.out.println("Enter the employee id that will have salary increase:"); + int idsalary = sc.nextInt(); + + Integer pos = position(list, idsalary); + + // Outra forma de encontrar o id escrito em 'idsalary' dentro da lista 'list' formatada em 'Employee emp' + // Employee emp = list.stream().filter(x -> x.getId() == idsalary).findFirst().orElse(null); + // Colocar em comentario "Integer pos = position(list, idsalary);" Linha 43. + + if (pos == null) { + System.out.println("This id does not exist! "); } + else { + System.out.print("Enter the percentage: "); + double porcentage = sc.nextInt(); + list.get(pos).increaseSalary(porcentage); + } + + + System.out.println(); + System.out.println("List of employee: "); + for (Employee emp : list) { + System.out.println(emp); + } + + + sc.close(); + +} + + public static Integer position(List list, int id) { + for (int i=0; i < list.size(); i++) { + if (list.get(i).getId() == id); { + return i; + } + } + return null; + } +}