-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
364 lines (326 loc) · 12.6 KB
/
Main.java
File metadata and controls
364 lines (326 loc) · 12.6 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
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
package com.company;
import java.text.DecimalFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
class Data{
private int Dia;
private int Mes;
private int Ano;
Data(int dia, int mes, int ano){
this.Dia = dia;
this.Mes = mes;
this.Ano = ano;
}
public String formatData(){
return ""+this.Dia+"/"+this.Mes+"/"+this.Ano;
}
}
interface Autorizavel{
boolean autoriza(int senha);
}
class Funcionario{
private static int totalFuncionarios = 0;
public static void addFuncionario() {
Funcionario.totalFuncionarios += 1;
}
public static int getTotalFuncionarios() {
return totalFuncionarios;
}
private int id;
private String nome;
private String sobrenome;
private int idade;
private Data data_Cadastro;
protected Funcionario(String nome, String sobrenome, int idade,int dia, int mes, int ano){
addFuncionario();
this.id = getTotalFuncionarios();
this.nome = nome;
this.sobrenome = sobrenome;
this.idade = idade;
this.data_Cadastro = new Data(dia, mes, ano);
}
public String getNome() {
return this.nome;
}
public String getSobrenome(){
return this.sobrenome;
}
}
class Gerente extends Funcionario implements Autorizavel{
private static ArrayList<Gerente> listaGerentes = new ArrayList<>();
public static ArrayList<Gerente> getListaGerentes() {
return listaGerentes;
}
public static void addListaGerentes(Gerente g) {
Gerente.listaGerentes.add(g);
}
private int senha;
Gerente(String nome, String sobrenome, int idade,int dia, int mes, int ano, int senha){
super(nome,sobrenome,idade,dia,mes,ano);
this.senha = senha;
}
@Override
public boolean autoriza(int senha) {
if (senha == this.senha){
return true;
}
return false;
}
}
class Vendedor extends Funcionario implements Autorizavel{
private static ArrayList<Vendedor> listaVendedores = new ArrayList<>();
public static ArrayList<Vendedor> getListaVendedores() {
return listaVendedores;
}
public static void addListaVendedores(Vendedor v) {
Vendedor.listaVendedores.add(v);
}
private int senha;
Vendedor(String nome, String sobrenome, int idade,int dia, int mes, int ano, int senha){
super(nome,sobrenome,idade,dia,mes,ano);
this.senha = senha;
}
@Override
public boolean autoriza(int senha) {
if (senha == this.senha){
return true;
}
return false;
}
}
class Produto{
private String tipo_Produto;
private String marca;
private String cor_Produto;
private String descricao_Produto;
private double valor_Produto;
Produto(String tipo, String cor,String marca,double valor){
this.tipo_Produto = tipo;
this.cor_Produto = cor;
this.marca = marca;
this.descricao_Produto = this.tipo_Produto+" "+this.cor_Produto+" "+this.marca;
this.valor_Produto = valor;
}
public double getValor_Produto() {
return valor_Produto;
}
public String getDescricao_Produto() {
return descricao_Produto;
}
public String toString(int qnt) {
DecimalFormat df = new DecimalFormat("#.00");
LocalDateTime ldt = LocalDateTime.now();
DateTimeFormatter d = DateTimeFormatter.ofPattern("dd/MM/yyyy hh:mm:ss");
String data = ldt.format(d);
return data+" "+getDescricao_Produto()+" x"+qnt+" .......... "+df.format(getValor_Produto()*qnt);
}
}
class Loja{
private HashMap<String,Produto> produtoMap = new HashMap<>();
public void addProduto(String tipo, String cor,String marca,double valor){
Produto tmp = new Produto(tipo, cor, marca, valor);
this.produtoMap.put(tmp.getDescricao_Produto(),tmp);
}
private void removerProduto(String key){
produtoMap.remove(key);
}
private Set<String> retornarProdutos(){
return this.produtoMap.keySet();
}
public void Menu(){
Funcionario logado = null;
while (true){
Scanner s = new Scanner(System.in);
s.reset();
System.out.println("0 - Sair \n1 - Entrar como Gerente \n2 - Entrar como Vendedor");
switch (Integer.parseInt(s.nextLine())){
case 0:
return;
case 1:
int i = 0;
int opg;
if (!(logado instanceof Gerente) || logado == null){
ArrayList<Gerente> tmg = Gerente.getListaGerentes();
System.out.println("Escolha a conta para logar:. ");
for(Gerente g : tmg){
System.out.println("["+i+"] "+g.getNome()+" "+g.getSobrenome());
i++;
}
i = 0;
opg = Integer.parseInt(s.nextLine());;
for(Gerente g : tmg){
if (i == opg){
System.out.print("Digite a senha :. ");
int senha = Integer.parseInt(s.nextLine());
if (g.autoriza(senha)){
logado = g;
}else{
System.out.println("Senha Incorreta");
}
break;
}
i++;
}
if (i > tmg.size()){
System.out.println("Opção Inválida");
}
}
if (logado instanceof Gerente){
System.out.println("Bem Vindo, "+logado.getNome());
System.out.println("0 - Sair\n1 - Adicionar Produtos\n2 - Remover Produtos");
opg = Integer.parseInt(s.nextLine());
switch (opg){
case 0:
return;
case 1:
String tipo;
String cor;
String marca;
double valor;
System.out.println("Tipo de Produto :. ");
tipo = s.nextLine();
System.out.println("Cor do Produto :. ");
cor = s.nextLine();
System.out.println("Marca do produto:. ");
marca = s.nextLine();
System.out.println("Valor do Produto:. ");
valor = Double.parseDouble(s.nextLine());
addProduto(tipo,cor,marca,valor);
break;
case 2:
i = 0;
for(String x : retornarProdutos()){
System.out.println("["+i+"] "+x);
i++;
}
i = 0;
opg = s.nextInt();
for(String x : retornarProdutos()){
if (opg == i){
removerProduto(x);
break;
}
i++;
}
System.out.println(retornarProdutos());
if (i > retornarProdutos().size()){
System.out.println("Inválido");
}
break;
}
}
break;
case 2:
i = 0;
if (!(logado instanceof Vendedor) || logado == null){
ArrayList<Vendedor> tmp = Vendedor.getListaVendedores();
System.out.println("Escolha a conta para logar:. ");
for(Vendedor v : tmp){
System.out.println("["+i+"] "+v.getNome()+" "+v.getSobrenome());
i++;
}
i = 0;
int opc = s.nextInt();
for(Vendedor v : tmp){
if (i == opc){
System.out.print("Digite a senha :. ");
int senha = s.nextInt();
if (v.autoriza(senha)){
logado = v;
}
}
i++;
}
if (i > tmp.size()){
System.out.println("Opção Inválida");
}
}
if (logado instanceof Vendedor){
ArrayList<String> carrinho = null;
System.out.println("Bem Vindo, "+logado.getNome());
carrinho = compras();
if (carrinho != null){
System.out.println("Vendedor :. "+logado.getNome()+" "+logado.getSobrenome());
System.out.println("---------------------------------------------------------");
for (String x : carrinho){
System.out.println(x);
}
}
}
break;
default:
System.out.println("Opção Inválida");
break;
}
}
}
private ArrayList<String> compras(){
int cont = 0;
double valorTotal = 0;
ArrayList<String> compras = new ArrayList<>();
while(true){
int i = 1;
Set<String> tm= retornarProdutos();
System.out.println("[0] Sair");
for (String x : tm){
System.out.println("["+i+"] "+x);
i++;
}
Scanner s = new Scanner(System.in);
i = 0;
int op = s.nextInt();
Produto tmp = null;
if (op == 0){
double desc = 0;
if (cont >= 10 && cont < 15){
desc = 5;
}else if (cont >= 15 && cont < 20){
desc = 10;
}else if (cont >= 20){
desc = 20;
}
DecimalFormat df = new DecimalFormat("#.00");
compras.add("Valor Total(Sem Desconto) ........................ R$"+df.format(valorTotal));
if (desc > 0){
valorTotal -= (desc/100 * valorTotal);
}
compras.add("Desconto ......................................... "+desc+"%");
compras.add("Valor Total(Com Desconto) ........................ R$"+df.format(valorTotal));
return compras;
}else{
op -= 1;
for (String x : tm){
if (i == op){
op = 0;
System.out.print("Insira a Quantidade:. ");
while (op == 0) {
op = s.nextInt();
if (op > 0){
tmp = produtoMap.get(x);
compras.add(tmp.toString(op));
valorTotal += tmp.getValor_Produto()*op;
cont += op;
}
}
break;
}
i++;
}
if (i > tm.size()){
System.out.println("Opção Inválida");
}
}
}
}
}
public class Main {
public static void main(String[] args) {
Gerente.addListaGerentes(new Gerente("marcelo","gonzaga",17,10,12,2019,1234));
Vendedor.addListaVendedores(new Vendedor("marcelo","gonzaga",18,10,12,2019,4321));
Loja l = new Loja();
l.addProduto("Relógio","Dourado","nSei",125.74);
l.addProduto("Relógio","Cinza","nSei",130);
l.Menu();
}
}