Advertisement
tcelestino

Cadastrar Produtos

Nov 12th, 2011
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.22 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3.  
  4. /*
  5.  * To change this template, choose Tools | Templates
  6.  * and open the template in the editor.
  7.  */
  8.  
  9. /**
  10.  *
  11.  * @author iris software
  12.  */
  13.  
  14. public class produtos {
  15.  
  16.     public static void cadastrarProduto() throws Exception {
  17.        
  18.      
  19.      
  20.     int op1;
  21.      
  22.     do {
  23.        
  24.      //menu
  25.      System.out.println("PRODUTOS\n");
  26.      System.out.println("1 - ADICIONAR NOVO");
  27.      System.out.println("2 - CONSULTAR");
  28.      System.out.println("3 - VOLTAR");
  29.        
  30.      //cadastro dos produtos
  31.      
  32.      op1 = (new Scanner(System.in)).nextInt();
  33.      
  34.      if(op1==1) {
  35.          
  36.        
  37.          
  38.          //salvando produtos
  39.          String ctn ="";
  40.          
  41.          String[] registro = ctn.split("\n");
  42.          
  43.          String[] nomeProduto = new String[registro.length];
  44.          String[][] infoProduto = new String[registro.length][2];
  45.          double[][] numerosProduto = new double[registro.length][3];
  46.          
  47.  
  48.          double cod, qtd, preco;
  49.          
  50.          int count = 0;
  51.          
  52.          String nome, descricao, fornecedor = null;
  53.          
  54.          
  55.          System.out.println("CODIGO:");
  56.          cod = (new Scanner(System.in)).nextDouble();
  57.                        
  58.                         for (int x = 0; x < nomeProduto.length; x++) {
  59.                             if (cod == (numerosProduto[x][0])) {
  60.                                 System.out.println("Código já cadastrado! digite um novo código");
  61.                                 cod = (new Scanner(System.in)).nextDouble();
  62.                             }
  63.                            
  64.                          
  65.                         }
  66.              System.out.println("NOME:");
  67.          
  68.           nome = (new Scanner(System.in)).nextLine();
  69.                         for (int x = 0; x < nomeProduto.length; x++) {
  70.                            
  71.                             if (nome.equals(nomeProduto[x])) {
  72.                                 System.out.println("Já existe um produto com essse nome");
  73.                                 nome = (new Scanner(System.in)).nextLine();
  74.                             }
  75.                         }                
  76.                        
  77.             System.out.println("DESCRICAO:");
  78.             descricao = (new Scanner(System.in)).nextLine();
  79.             for(int x = 0; x<nomeProduto.length; x++) {
  80.                  descricao.equals(infoProduto[x][0]);
  81.             }
  82.                        
  83.          System.out.println("PRECO UNITARIO:");
  84.                         preco = (new Scanner(System.in)).nextDouble();
  85.                        
  86.                         for (int x = 0; x < nomeProduto.length; x++) {
  87.                            
  88.                             preco = (numerosProduto[x][1]);
  89.                            
  90.                             }
  91.                        
  92.          System.out.println("QUANTIDADE EM ESTOQUE:");
  93.                         qtd = (new Scanner(System.in)).nextDouble();
  94.                        
  95.                         for (int x = 0; x < nomeProduto.length; x++) {
  96.                            
  97.                             qtd = (numerosProduto[x][2]);
  98.                            
  99.                             }
  100.                        
  101.           System.out.println("FORNECEDOR:");
  102.             fornecedor = (new Scanner(System.in)).nextLine();
  103.             for(int x = 0; x<nomeProduto.length; x++) {
  104.                  fornecedor.equals(infoProduto[x][1]);
  105.             }
  106.          
  107.          
  108.              nomeProduto[count] = nome;
  109.              infoProduto[count][0] = descricao;
  110.              infoProduto[count][1] = fornecedor;
  111.              numerosProduto[count][0] = cod;
  112.              numerosProduto[count][1] = preco;
  113.              numerosProduto[count][2] = qtd;
  114.              
  115.              count++;
  116.          
  117.          for(int x=0; x<nomeProduto.length; x++){
  118.      
  119.           ctn = ctn+numerosProduto[x][0]+"|"+nomeProduto[x]+"|"+infoProduto[x][0]+"|"+numerosProduto[x][1]+"|"+numerosProduto[x][2]+"|"+infoProduto[x][1]+"\n";
  120.            
  121.            arquivo.gravar("produtos.txt", ctn);
  122.        
  123.          }
  124.                          
  125.        
  126.          
  127.      }
  128.      
  129.     }while(op1 !=3);
  130.   }
  131.  
  132.  
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement