-
Notifications
You must be signed in to change notification settings - Fork 0
/
CriminalRecordSystem.java
184 lines (165 loc) · 6.4 KB
/
CriminalRecordSystem.java
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
package main;
import java.util.ArrayList;
public class CriminalRecordSystem {
private ArrayList<Indicted> indicteds;
public CriminalRecordSystem(){
this.indicteds = new ArrayList<Indicted>();
}
public void addIndictedAndRecord(String name, String lastname, String id,
String gender, int age, int crimeId,
String type, String description){
if (!this.existsIndected(id) &&
this.findCriminalRecord(crimeId) == null &&
age >= 5){
Indicted newIndicted = new Indicted(name, lastname, id, gender, age);
newIndicted.addCriminalRecord(crimeId, type, description);
this.indicteds.add(newIndicted);
}else{
/*if(age < 5){
System.out.println("Error de edad");
}else if(this.existsIndected(id)){
System.out.println("Error de convicto");
}else if(this.findCriminalRecord(crimeId) != null){
System.out.println("Error de crimen");
}*/
//Reportar error de Id de convicto duplicado.
//Reportar error de edad mínima.
//Reportar error de Id de crimen duplicado.
}
}
public void addRecordToIndicted(String id, int crimeId, String type,
String description){
if(this.findIndicted(id) != -1 && this.findCriminalRecord(crimeId) == null){
this.getIndicted(this.findIndicted(id)).addCriminalRecord(crimeId, type, description);
}
}
public boolean existsIndected(String id){
for (Indicted guy : indicteds){
if(guy.getIdentification().equalsIgnoreCase(id)){
return true;
}
}
return false;
}
public CriminalRecord findCriminalRecord(int crimeId){
if (!this.getIndicteds().isEmpty()){
for(Indicted guy : this.getIndicteds()){
CriminalRecord flag = guy.findCriminalRecord(crimeId);
if (flag != null){
return flag;
}
}
}
return null;
}
public int findIndicted(String id){
if (this.existsIndected(id)){
for (Indicted guy : this.getIndicteds()){
if(guy.getIdentification().equalsIgnoreCase(id)){
return this.getIndicteds().indexOf(guy);
}
}
}
return -1;
//Básicamente devuelve la posición en la lista del convicto.
//-1 indica que no lo encontró.
//Agregar mensaje sobre que no lo encontró.
}
public ArrayList<Indicted> findIndictedsByCriminalRecord(String type){
ArrayList<Indicted> indictedByType = new ArrayList<Indicted>();
if(!this.getIndicteds().isEmpty()){
for(Indicted guy : this.getIndicteds()){
if(guy.haveCriminalRecordType(type)){
indictedByType.add(guy);
}
}
}
return indictedByType;
}
//Está mal nombrado. Sabiendo que el CriminalRecord es único pues
//no se podría hacer una lista, sino máximo traer a un convicto.
//El nombre correcto sería findIndictedByType.
public int findIndictedWithGreaterSentence(){
int flag = -1;
if (!this.getIndicteds().isEmpty()){
Indicted guyFlag = this.getIndicteds().get(0);
for (Indicted guy : this.getIndicteds()){
if(guy.getYearsOfSentence() > flag){
flag = guy.getYearsOfSentence();
guyFlag = guy;
}
}
return this.getIndicteds().indexOf(guyFlag);
}
return -1;
//Básicamente devuelve la posición en la lista del convicto.
//-1 indica que no lo encontró.
//Agregar mensaje sobre que no lo encontró.
}
public int findIndictedWithLessSentence(){
if (!this.getIndicteds().isEmpty()){
Indicted guyFlag = this.getIndicteds().get(0);
for (Indicted guy : this.getIndicteds()){
if(guy.getYearsOfSentence() < guyFlag.getYearsOfSentence()){
guyFlag = guy;
}
}
return this.getIndicteds().indexOf(guyFlag);
}
return -1;
//Básicamente devuelve la posición en la lista del convicto.
//-1 indica que no lo encontró.
//Agregar mensaje sobre que no lo encontró.
}
public int findIndictedWithMoreRecords(){
if (!this.getIndicteds().isEmpty()){
Indicted guyFlag = this.getIndicteds().get(0);
for (Indicted guy : this.getIndicteds()){
if(guy.getCriminalRecordQuantity() > guyFlag.getCriminalRecordQuantity()){
guyFlag = guy;
}
}
return this.getIndicteds().indexOf(guyFlag);
}
return -1;
}
public Indicted getIndicted(int number){
if(!this.getIndicteds().isEmpty() && number > -1 &&
number <this.getIndicteds().size()){
return this.getIndicteds().get(number);
}
return null;
}
public ArrayList<Indicted> getIndicteds(){
return this.indicteds;
}
//No idea what these are used for.
/*
public String method1(){
return;
}
public String method2(){
return;
}
*/
public void removeCriminalRecordOfIndicted(String indictedId, int crimeId){
int position = this.findIndicted(indictedId);
if (position != -1){
Indicted theGuy = this.getIndicteds().get(position);
theGuy.removeCriminalRecord(crimeId);
}
}
public void removeIndicted(String id){
int position = this.findIndicted(id);
if (position != -1){
this.getIndicteds().remove(position);
}
}
public void sentenceIndicted(String indictedId, int crimeId, int sentence){
int position = this.findIndicted(indictedId);
if (position != -1){
Indicted theGuy = this.getIndicteds().get(position);
theGuy.sentenceIndicted(crimeId, sentence);
}
}
}