import java.util.ArrayList;
import java.util.Scanner;
class Produto {
String nome;
double preco;
int quantidade;
Produto(String nome, double preco, int quantidade) {
this.nome = nome;
this.preco = preco;
this.quantidade = quantidade;
}
double total() {
return preco * quantidade;
}
}
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ArrayList vendas = new ArrayList<>();
int opcao;
do {
System.out.println("\n=== PAINEL DE VENDAS ===");
System.out.println("1 - Cadastrar venda");
System.out.println("2 - Listar vendas");
System.out.println("3 - Total vendido");
System.out.println("0 - Sair");
System.out.print("Escolha: ");
opcao = sc.nextInt();
sc.nextLine();
switch (opcao) {
case 1:
System.out.print("Nome do produto: ");
String nome = sc.nextLine();
System.out.print("Preço: ");
double preco = sc.nextDouble();
System.out.print("Quantidade: ");
int quantidade = sc.nextInt();
sc.nextLine();
vendas.add(new Produto(nome, preco, quantidade));
System.out.println("Venda cadastrada com sucesso.");
break;
case 2:
if (vendas.isEmpty()) {
System.out.println("Nenhuma venda cadastrada.");
} else {
System.out.println("\n--- LISTA DE VENDAS ---");
for (Produto p : vendas) {
System.out.println(
"Produto: " + p.nome +
" | Preço: " + p.preco +
" | Quantidade: " + p.quantidade +
" | Total: " + p.total()
);
}
}
break;
case 3:
double soma = 0;
for (Produto p : vendas) {
soma += p.total();
}
System.out.println("Total vendido: R$ " + soma);
break;
case 0:
System.out.println("Encerrando sistema...");
break;
default:
System.out.println("Opção inválida.");
}
} while (opcao != 0);
sc.close();
}
}
import java.util.ArrayList;
import java.util.Scanner;
class Produto {
String nome;
double preco;
int quantidade;
}
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ArrayList vendas = new ArrayList<>();
}