-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostoAbastecimento.java
More file actions
54 lines (45 loc) · 1.5 KB
/
PostoAbastecimento.java
File metadata and controls
54 lines (45 loc) · 1.5 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
package Lista2;
import java.util.Scanner;
public class PostoAbastecimento {
public static void main(String[] args) {
Scanner entrada = new Scanner(System.in);
char op = 0;
int qtdLitros;
float valLitroAlc = (float) 1.90, valLitroGas = (float) 2.50;
float indicAlc1 = 3, indicAlc2 = 5, indicGas1 = 4, indicGas2 = 6;
System.out.println("Escolha o tipo de combustível:");
System.out.print("A - alcool ou G - gasolina -> ");
op = entrada.nextLine().toUpperCase().charAt(op);
System.out.println("Quantos litros você quer abastacer?");
System.out.print("Qtd Litros -> ");
qtdLitros = entrada.nextInt();
switch(op) {
case 'A':
if(qtdLitros <= 20) {
float desc = (qtdLitros * valLitroAlc * indicAlc1) /100;
float valTotal = (qtdLitros * valLitroAlc) - desc;
System.out.println("Total: R$ "+valTotal);
} else {
float desc = (qtdLitros * valLitroAlc * indicAlc2) /100;
float valTotal = (qtdLitros * valLitroAlc) - desc;
System.out.println("Total: R$ "+valTotal);
}
break;
case 'G':
if(qtdLitros <= 20) {
float desc = (qtdLitros * valLitroGas * indicGas1) /100;
float valTotal = (qtdLitros * valLitroGas) - desc;
System.out.println("Total: R$ "+valTotal);
} else {
float desc = (qtdLitros * valLitroGas * indicGas2) /100;
float valTotal = (qtdLitros * valLitroGas) - desc;
System.out.println("Total: R$ "+valTotal);
}
break;
default:
System.out.println("Quantidade não permitida");
break;
}
entrada.close();
}
}