-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquatorze.java
More file actions
44 lines (26 loc) · 1.29 KB
/
quatorze.java
File metadata and controls
44 lines (26 loc) · 1.29 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
import java.util.Scanner;
public class quatorze {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
final double PRECO_ALCOOL = 2.90;
final double PRECO_GASOLINA = 3.30;
System.out.print("Digite o número de litros vendidos: ");
double litros = scanner.nextDouble();
System.out.print("Digite o tipo de combustível (A para álcool, G para gasolina): ");
char tipoCombustivel = scanner.next().toUpperCase().charAt(0);
double precoFinal;
if (tipoCombustivel == 'A') {
double desconto = (litros <= 20) ? 0.03 : 0.05;
precoFinal = litros * PRECO_ALCOOL * (1 - desconto);
} else if (tipoCombustivel == 'G') {
double desconto = (litros <= 20) ? 0.04 : 0.06;
precoFinal = litros * PRECO_GASOLINA * (1 - desconto);
} else {
System.out.println("Tipo de combustível inválido. Por favor, insira 'A' ou 'G'.");
scanner.close();
return;
}
System.out.printf("O valor a ser pago é: R$ %.2f%n", precoFinal);
scanner.close();
}
}