-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCardapio.java
110 lines (105 loc) · 3.91 KB
/
Cardapio.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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package testeestagio;
import java.util.ArrayList;
/**
*
* @author Chady Chaito
*/
public class Cardapio {
private final ArrayList<String> morning = new ArrayList();
private final ArrayList<String> night = new ArrayList();
/* Construtor do Cardapio */
public Cardapio(){
this.morning.add("eggs");
this.morning.add("toast");
this.morning.add("coffe");
this.morning.add("error");
this.night.add("steak");
this.night.add("potato");
this.night.add("wine");
this.night.add("cake");
}
/* Listar Cardapio de acordo com pedido do Cliente */
public int listarCardapio(Pedidos pedido){
String periodo = pedido.getPeriodo();
int value, flag = 0;
/* Se manhã */
if("morning".equals(periodo)){
for(int i = 0 ; i < 4 ; i++){
value = pedido.getVetValue(i); //Pegando valor do vetor de pedidos
/* Se ele fez o pedido então o Value do Vetor = 1 */
if(value >= 1){
// Colocar ou não virgula
if(flag == 0){
/* Se pedir mais de um Prato que não seja Café - ERROR */
if(value > 1 && i != 2){
System.out.printf("%s", morning.get(i));
System.out.printf(", error");
flag = 1;
return -1;
}
else{
System.out.printf("%s", morning.get(i));
flag = 1;
}
}
else{
if(value > 1 && i == 2){
System.out.printf(", %s (x%d)", morning.get(i), value);
}
/* Se pedir mais de um Prato que não seja Café - ERROR */
else if(value > 1 && i != 2){
System.out.printf(", %s", morning.get(i));
System.out.printf(", error");
return -1;
}
else{
System.out.printf(", %s", morning.get(i));
}
}
}
}
}
else if("night".equals(periodo)){
for(int i = 0 ; i < 4 ; i++){
value = pedido.getVetValue(i); //Pegando valor do vetor de pedidos
/* Se ele fez o pedido então o Value do Vetor = 1 */
if(value >= 1){
// Colocar ou não virgula
if(flag == 0){
/* Se pedir mais de um Prato que não seja Café - ERROR */
if(value > 1 && i != 1){
System.out.printf("%s", night.get(i));
System.out.printf(", error");
flag = 1;
return -1;
}
else{
System.out.printf("%s", night.get(i));
flag = 1;
}
}
else{
if(value > 1 && i == 1){
System.out.printf(", %s (x%d)", night.get(i), value);
}
/* Se pedir mais de um Prato que não seja Café - ERROR */
else if(value > 1 && i != 1){
System.out.printf(", %s", night.get(i));
System.out.printf(", error");
return -1;
}
else{
System.out.printf(", %s", night.get(i));
}
}
}
}
}
return 1;
}
}