Advertisement
Alfoli

Poo Aula 1

Feb 19th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.99 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Collections;
  3. import java.util.Random;
  4. import java.util.List;
  5. import java.util.Collections;
  6.  
  7. import javax.swing.JOptionPane;
  8. public class Vetor {
  9.     Random rd = new Random(); //rd = objeto
  10.     private List<Integer>vetor;
  11.     private boolean ordenado;
  12.     private int ponteiro;
  13.     public void Ordena(){
  14.         Collections.sort(vetor);
  15.         ordenado = true;
  16.     }
  17.     public Vetor(){ //construtor
  18.          ordenado = false;
  19.          vetor = new ArrayList<Integer>();
  20.          ponteiro = -1;
  21.     }
  22.     public void geracao(){
  23.     int i, n;
  24.     for (i=0; i<100; i++){
  25.         n = rd.nextInt(999);
  26.         vetor.add(n);
  27.     }
  28.     }
  29.     public String toString(){
  30.         String saida = "Vetor \n";
  31.         int metade = vetor.size()/2;
  32.         for (int i=0; i<metade; i++)
  33.             saida += String.format("\n[%d]=%d  [%d]=%d\n", i, vetor.get(i), i+50, vetor.get(i+50));
  34.         return saida;
  35.     }
  36.     public int buscaExaustiva(int num){
  37.         ponteiro = -1;
  38.         //busca exaustiva
  39.         return ponteiro;
  40.     }
  41.     public int buscaBinaria(int num){
  42.         ponteiro = -1;
  43.         //busca binaria
  44.         return ponteiro;
  45.     }
  46.    
  47. public static void main (String []args){
  48.     Vetor v = new Vetor();
  49.     //menu-showInputDialog
  50.     String opcao;
  51.     while (true){
  52.         opcao=JOptionPane.showInputDialog(null, "--------Classe Vetor--------\n"+
  53.     "1- geracao de vetor\n"+
  54.     "2 - exibe o vetor\n"+
  55.     "3 - ordena o vetor\n"+
  56.     "4 - busca um numero\n"+
  57.     "5 - sair\n");
  58.     opcao=opcao.toUpperCase();
  59.     char op = opcao.charAt(0);
  60.     switch (op){
  61.     case '1': v.geracao();
  62.               break;
  63.     case '2': String saida = v.toString();
  64.               JOptionPane.showMessageDialog(null, saida);
  65.               break;
  66.     case '3': v.Ordena();
  67.               JOptionPane.showMessageDialog(null, "Vetor ordenado");
  68.               break;
  69.     case '4': String texto= JOptionPane.showInputDialog(null, "Entre com o numero a ser procurado");
  70.               int num = Integer.parseInt(texto); //transforma o texto em numero
  71.               int posicao = v.buscaExaustiva(num);
  72.               break;
  73.     case '5': System.exit (0);
  74.               break;
  75.     }
  76.        
  77.     }
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement