-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCarro.java
263 lines (208 loc) · 7.56 KB
/
Carro.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
package poo;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
public abstract class Carro extends Veiculo {
private String marca;
private String matricula;
private String nif;
private int autonomia;
private double velocidade;
private double preco;
private int capacidade_Max;
private double consumocombus;
private HashSet<Classificar> classificacoes;
private int classificacao;
private double coordenadasx;
private double coordenadasy;
private boolean pdalugar;
//construtor vazio
public Carro() {
super();
this.marca =new String();
this.matricula=new String();
this.nif=new String();
this.autonomia=0;
this.velocidade= 0.0;
this.preco = 0.0;
this.capacidade_Max=0;
this.consumocombus = 0.0;
this.classificacoes = new HashSet<>();
this.classificacao = 0;
this.coordenadasx = 0.0;
this.coordenadasy = 0.0;
this.pdalugar = false;
}
//construtor parametrizado
public Carro(ArrayList<Aluguer_final> historico ,String marca,String matricula, String nif,int autonomia, double vel, double preco,int cap, double consu,HashSet<Classificar> classificacoes, int clas , double coordx ,double coordy ,boolean pdalg){
super(historico);
this.marca=marca;
this.matricula=matricula;
this.nif=nif;
this.autonomia=autonomia;
this.velocidade= vel;
this.preco = preco;
this.capacidade_Max=cap;
this.consumocombus = consu;
this.classificacoes = new HashSet<>();
for(Classificar hist: classificacoes){
this.classificacoes.add(hist.clone());
}
this.classificacao = clas;
this.coordenadasx = coordx;
this.coordenadasy = coordy;
this.pdalugar = pdalg;
}
//construtor de cópia
public Carro(Carro outroCarro) {
super(outroCarro);
this.marca = outroCarro.getMarca();
this.matricula = outroCarro.getMatricula();
this.nif = outroCarro.getNif();
this.autonomia = outroCarro.getAutonomia();
this.velocidade = outroCarro.getVelocidade();
this.preco = outroCarro.getPreco();
this.capacidade_Max=outroCarro.getCapacidade_Max();
this.consumocombus = outroCarro.getConsumocombus();
this.classificacoes=outroCarro.getClassiff();
this.classificacao = outroCarro.getClassificacao();
this.coordenadasx = outroCarro.getCoordenadasx();
this.coordenadasy = outroCarro.getCoordenadasy();
this.pdalugar = outroCarro.isPdalugar();
}
//GETTERS E SETTERS
public String getMarca() {
return marca;
}
public void setMarca(String marca) {
this.marca = marca;
}
public String getMatricula() {
return matricula;
}
public void setMatricula(String matricula) {
this.matricula = matricula;
}
public String getNif() {
return nif;
}
public void setNif(String nif) {
this.nif = nif;
}
public int getAutonomia() {
return autonomia;
}
public void setAutonomia(int autonomia) {
this.autonomia = autonomia;
}
public double getVelocidade() {
return velocidade;
}
public double getPreco() {
return preco;
}
public double getConsumocombus() {
return consumocombus;
}
public int getClassificacao() {
return classificacao;
}
public double getCoordenadasx() {
return coordenadasx;
}
public double getCoordenadasy() {
return coordenadasy;
}
public boolean isPdalugar() {
return pdalugar;
}
public void setVelocidade(double velocidade) {
this.velocidade = velocidade;
}
public void setPreco(double preco) {
this.preco = preco;
}
public void setConsumocombus(double consumocombus) {
this.consumocombus = consumocombus;
}
public void setClassificacao() {
Iterator<Classificar> it= classificacoes.iterator();
Classificar elem=null;
int r=0; int s=0;
while (it.hasNext()){
elem=it.next();
r=r+elem.getNota();
s++;
}
if(s==0) this.classificacao=0;
else this.classificacao=r/s;
}
public void setCoordenadasx(double coordenadasx) {
this.coordenadasx = coordenadasx;
}
public void setCoordenadasy(double coordenadasy) {
this.coordenadasy = coordenadasy;
}
public void setPdalugar(boolean pdalugar) {
this.pdalugar = pdalugar;
}
public int getCapacidade_Max() {
return capacidade_Max;
}
public void setCapacidade_Max(int capacidade_Max) {
this.capacidade_Max = capacidade_Max;
}
public HashSet<Classificar> getClassiff(){
HashSet<Classificar> newhistorico =new HashSet<>();
for(Classificar hist: this.classificacoes){
newhistorico.add(hist.clone());
}
return newhistorico;
}
public void adicionarClassiff(Classificar a){
classificacoes.add(new Classificar(a));
}
public abstract Carro clone ();
/**
*EQUALS
*/
public boolean equals (Object o){
if (this == o) return true;
if (o == null || this.getClass() != o.getClass()) return false;
Carro that = (Carro) o;
return (super.equals(o)
&& this.marca.equals(that.getMarca())
&& this.matricula.equals(that.getMatricula())
&& this.nif.equals(that.getNif())
&& this.autonomia == that.getAutonomia()
&& this.velocidade == (that.getVelocidade())
&& this.preco == (that.getPreco())
&& this.capacidade_Max == (that.getCapacidade_Max())
&& this.consumocombus == (that.getConsumocombus())
&& this.classificacoes.equals(that.getClassiff())
&& this.classificacao == (that.getClassificacao())
&& this.coordenadasx == (that.getCoordenadasx())
&& this.coordenadasy == (that.getCoordenadasy())
&& this.pdalugar == (that.isPdalugar()));
}
/**
*TO STRING
*/
public String toString(){
StringBuffer sb = new StringBuffer(super.toString());
sb.append("Marca: ").append(this.marca).append(", ");
sb.append("Matricula: ").append(this.matricula).append(", ");
sb.append("Nif: ").append(this.nif).append(", ");
sb.append("Autonomia: ").append(this.autonomia).append(", ");
sb.append("Velocidade média por km: ").append(this.velocidade).append(", ");
sb.append("Preço base por km: ").append(this.preco).append(", ");
sb.append("Capacidade máxima: ").append(this.capacidade_Max).append(", ");
sb.append("Consumo de combustivel por km percorrido: ").append(this.consumocombus).append(", ");
sb.append("Classificação do carro: ").append(this.classificacao).append(", ");
sb.append("Ordenada: ").append(this.coordenadasx).append(", ");
sb.append("Abcisa: ").append(this.coordenadasy).append(", ");
sb.append("Pode alugar? : ").append(this.pdalugar).append(", ");
return sb.toString();
}
}