Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. package exemplos;
  2.  
  3. import java.util.*;
  4.  
  5. public class Gemialidade {
  6.  
  7. public static void main(String[] args) {
  8. Scanner in = new Scanner(System.in);
  9. // lendo a quantidade de comandos
  10. int qtdComandos = Integer.parseInt(in.nextLine());
  11. String[] produtos = new String[qtdComandos];
  12. int[] estoque = new int[qtdComandos];
  13. // lendo a operação
  14. for (int i = 0; i < qtdComandos; i++) {
  15. int aux = 0;
  16. boolean achado = false;
  17. String operacao = in.nextLine();
  18. if (!operacao.contentEquals("CADASTRO") && !operacao.equals("ESTOQUE") && !operacao.equals("VENDA")) {
  19. System.out.println("Comando invalido");
  20. } else {
  21. if (operacao.equals("CADASTRO")) {
  22. String produto = in.nextLine();
  23. for (int j = 0; j < produtos.length - 1; j++) {
  24. if (produtos[j].equals(produto)) {
  25. System.out.println("Produto já cadastrado");
  26. achado = true;
  27. }
  28. if (produtos==null && achado == false) {
  29. produtos[j] = produto;
  30. System.out.println("Produto cadastrado com sucesso");
  31. }
  32. }
  33.  
  34. } else if (operacao.equals("ESTOQUE")) {
  35. String qtdProduto = in.nextLine();
  36. int quantidade = Integer.parseInt(in.nextLine());
  37. aux = quantidade;
  38. int j = 0;
  39. if(estoque[j]<0) {
  40. System.out.println("Nao ha estoque para a venda");
  41. }else {
  42. estoque[j] += quantidade;
  43. System.out.println("Estoque realizado com sucesso");
  44. }
  45. j++;
  46. } else if (operacao.equals("VENDA")) {
  47. String venda = in.nextLine();
  48. int qtdVenda = Integer.parseInt(in.nextLine());
  49.  
  50.  
  51.  
  52. }
  53.  
  54. }
  55.  
  56. }
  57. for (int i = 0; i < produtos.length - 1; i++) {
  58. System.out.printf("%s: %d", produtos[i], estoque[i]);
  59. }
  60. in.close();
  61.  
  62. }
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement