-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContrato.java
135 lines (107 loc) · 2.84 KB
/
Contrato.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
import java.util.Iterator;
import java.util.List;
public class Contrato {
private Hospede hospede;
private List<Servicos> servicos;
private EstrategiaCobranca e;
private String formaDePagamento;
private int periodo;
private boolean aberto;
public Contrato (List<Servicos> servicos, Hospede hospede, EstrategiaCobranca e, int periodo, String formaDePagamento) throws Exception{
if (periodo <= 0)
throw new Exception("Periodo invalido");
if (formaDePagamento.equals("") || formaDePagamento == null)
throw new Exception("Forma de pagamento invalida");
this.hospede = hospede;
this.servicos = servicos;
this.e = e;
this.formaDePagamento = formaDePagamento;
this.periodo = periodo;
aberto = true;
}
public EstrategiaCobranca getEstrategia() {
return e;
}
public void setE(EstrategiaCobranca e) {
this.e = e;
}
public String getFormaDePagamento() {
return formaDePagamento;
}
public void setFormaDePagamento(String formaDePagamento) {
this.formaDePagamento = formaDePagamento;
}
public List<Servicos> getServicos() {
return servicos;
}
public int getPeriodo() {
return periodo;
}
public void adicionaServico(Servicos servico) throws Exception{
if (!(isAberto()))
throw new Exception("O contrato ja foi fechado");
servicos.add(servico);
}
public boolean isAberto(){
return aberto;
}
public void setStatus(){
if (isAberto())
aberto = false;
else
aberto = true;
}
public double calculaValorServicos(){
double soma = 0;
Iterator<Servicos> it = servicos.iterator();
while(it.hasNext()) {
Servicos umServico = it.next();
soma += umServico.valor();
}
return soma;
}
public double calculaValorTotal(){
return calculaValorServicos() * getEstrategia().getFator();
}
public Hospede getHospede(){
return hospede;
}
public int getTelefone() {
return hospede.getTelefone();
}
public String getNome() {
return hospede.getNome();
}
public String getCPF() {
return hospede.getCPF();
}
public String getRG() {
return hospede.getRG();
}
public String getEmail() {
return hospede.getEmail();
}
public String getEndereco() {
return hospede.getEndereco();
}
private String mostraStatus(){
if (isAberto())
return "ABERTO";
else
return "FECHADO";
}
@Override
public String toString(){
return hospede.toString() + "\nForma de pagamento: " + getFormaDePagamento()
+ "\nPeriodo da hospedagem: " + getPeriodo() + "\nValor dos servicos: "
+ calculaValorServicos() + "\nValor total da estadia: " + calculaValorTotal()
+ "Status do contrato: " + mostraStatus();
}
@Override
public boolean equals(Object obj){
if (!(obj instanceof Contrato))
return false;
Contrato c1 = (Contrato) obj;
return getHospede().equals(c1.getHospede()) && isAberto() == c1.isAberto() && calculaValorTotal() == c1.calculaValorTotal();
}
}