Repository navigation
Expand file tree
/
Copy pathListaExercicio.java
More file actions
97 lines (74 loc) · 1.96 KB
/
Copy pathListaExercicio.java
File metadata and controls
97 lines (74 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package aplication;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Scanner;
class Funcionario{
protected int id;
private String name;
private double salary;
public Funcionario() {
}
public Funcionario(int id, String name, double salary) {
this.id = id;
this.name = name;
this.salary = salary;
}
public int getId() {
return id;
}
void salaryIncrease(double percent) {
salary = salary + ((percent/100) * salary);
}
public String toString() {
return id + ", " + name + ", " + salary;
}
}
public class ListaExercicio {
public static void main(String[] args) {
Locale.setDefault(Locale.US);
List<Funcionario> list = new ArrayList<>();
Scanner sc = new Scanner(System.in);
System.out.println("How many employees will be registered? ");
int n = sc.nextInt();
for(int i=0 ; i < n ; i++) {
System.out.println("Employer #" + (i+1));
System.out.println("Id: ");
int id = sc.nextInt();
System.out.println("Name: ");
sc.nextLine();
String name = sc.nextLine();
System.out.println("Salary: ");
double salary = sc.nextDouble();
System.out.println("");
Funcionario f1 = new Funcionario(id, name, salary);
list.add(f1);
}
System.out.println("Enter the employee id that will have salary increase: ");
sc.nextLine();
int eId = sc.nextInt();
Funcionario foundEmployee = null;
for(Funcionario emp : list) {
if(emp.getId() == eId) {
foundEmployee = emp;
break;
}
}
if(foundEmployee == null) {
System.out.println("\nThis id does not exists!\n");
System.out.println("List of employees: ");
for(Funcionario x : list) {
System.out.println(x);
}
} else {
System.out.println("Enter the percentage: ");
double percent = sc.nextDouble();
foundEmployee.salaryIncrease(percent);
System.out.println("\nList of employees: ");
for(Funcionario x : list) {
System.out.println(x);
}
}
sc.close();
}
}