Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package exemplos;
- import java.util.*;
- public class Gemialidade {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- // lendo a quantidade de comandos
- int qtdComandos = Integer.parseInt(in.nextLine());
- String[] produtos = new String[qtdComandos];
- int[] estoque = new int[qtdComandos];
- // lendo a operação
- for (int i = 0; i < qtdComandos; i++) {
- int aux = 0;
- boolean achado = false;
- String operacao = in.nextLine();
- if (!operacao.contentEquals("CADASTRO") && !operacao.equals("ESTOQUE") && !operacao.equals("VENDA")) {
- System.out.println("Comando invalido");
- } else {
- if (operacao.equals("CADASTRO")) {
- String produto = in.nextLine();
- for (int j = 0; j < produtos.length - 1; j++) {
- if (produtos[j].equals(produto)) {
- System.out.println("Produto já cadastrado");
- achado = true;
- }
- if (produtos==null && achado == false) {
- produtos[j] = produto;
- System.out.println("Produto cadastrado com sucesso");
- }
- }
- } else if (operacao.equals("ESTOQUE")) {
- String qtdProduto = in.nextLine();
- int quantidade = Integer.parseInt(in.nextLine());
- aux = quantidade;
- int j = 0;
- if(estoque[j]<0) {
- System.out.println("Nao ha estoque para a venda");
- }else {
- estoque[j] += quantidade;
- System.out.println("Estoque realizado com sucesso");
- }
- j++;
- } else if (operacao.equals("VENDA")) {
- String venda = in.nextLine();
- int qtdVenda = Integer.parseInt(in.nextLine());
- }
- }
- }
- for (int i = 0; i < produtos.length - 1; i++) {
- System.out.printf("%s: %d", produtos[i], estoque[i]);
- }
- in.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement