Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.Random;
- import java.util.List;
- import java.util.Collections;
- import javax.swing.JOptionPane;
- public class Vetor {
- Random rd = new Random(); //rd = objeto
- private List<Integer>vetor;
- private boolean ordenado;
- private int ponteiro;
- public void Ordena(){
- Collections.sort(vetor);
- ordenado = true;
- }
- public Vetor(){ //construtor
- ordenado = false;
- vetor = new ArrayList<Integer>();
- ponteiro = -1;
- }
- public void geracao(){
- int i, n;
- for (i=0; i<100; i++){
- n = rd.nextInt(999);
- vetor.add(n);
- }
- }
- public String toString(){
- String saida = "Vetor \n";
- int metade = vetor.size()/2;
- for (int i=0; i<metade; i++)
- saida += String.format("\n[%d]=%d [%d]=%d\n", i, vetor.get(i), i+50, vetor.get(i+50));
- return saida;
- }
- public int buscaExaustiva(int num){
- ponteiro = -1;
- //busca exaustiva
- return ponteiro;
- }
- public int buscaBinaria(int num){
- ponteiro = -1;
- //busca binaria
- return ponteiro;
- }
- public static void main (String []args){
- Vetor v = new Vetor();
- //menu-showInputDialog
- String opcao;
- while (true){
- opcao=JOptionPane.showInputDialog(null, "--------Classe Vetor--------\n"+
- "1- geracao de vetor\n"+
- "2 - exibe o vetor\n"+
- "3 - ordena o vetor\n"+
- "4 - busca um numero\n"+
- "5 - sair\n");
- opcao=opcao.toUpperCase();
- char op = opcao.charAt(0);
- switch (op){
- case '1': v.geracao();
- break;
- case '2': String saida = v.toString();
- JOptionPane.showMessageDialog(null, saida);
- break;
- case '3': v.Ordena();
- JOptionPane.showMessageDialog(null, "Vetor ordenado");
- break;
- case '4': String texto= JOptionPane.showInputDialog(null, "Entre com o numero a ser procurado");
- int num = Integer.parseInt(texto); //transforma o texto em numero
- int posicao = v.buscaExaustiva(num);
- break;
- case '5': System.exit (0);
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement