From d7fd49373cb9736e0821dd8feeb7eb3c81f18fae Mon Sep 17 00:00:00 2001 From: Vanessa Santos <98504873+VanessaSotnas@users.noreply.github.com> Date: Tue, 22 Feb 2022 18:38:20 -0300 Subject: [PATCH 1/2] Add files via upload --- funcionarios/Employee.java | 51 +++++++++++++++++++++++++ funcionarios/Program.java | 78 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 funcionarios/Employee.java create mode 100644 funcionarios/Program.java 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..c1b5522 --- /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; + } +} From 82ac5b94b1ea3458e7281c827e4e283eae557d77 Mon Sep 17 00:00:00 2001 From: Vanessa Santos <98504873+VanessaSotnas@users.noreply.github.com> Date: Tue, 22 Feb 2022 18:40:11 -0300 Subject: [PATCH 2/2] Update Program.java --- funcionarios/Program.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/funcionarios/Program.java b/funcionarios/Program.java index c1b5522..5ea802c 100644 --- a/funcionarios/Program.java +++ b/funcionarios/Program.java @@ -17,7 +17,7 @@ public static void main(String[] args) { System.out.print("How many employees will be registered?"); int n = sc.nextInt(); - //List id = new ArrayList<>(); + //List id = new ArrayList<>(); //List name = new ArrayList<>(); Nao serao necessarios. //List salary = new ArrayList<>(); Instanciar um nome objeto com os 3 atributos.