1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Array to Vector

Discussion in 'Java' started by dsptl, Jun 14, 2009.

  1. dsptl

    dsptl New Member

    Joined:
    Jun 14, 2009
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    Our assignment to write megaMillion.java I have written this program but that is using array and our professor require us to use vector, which i don't know how to use. So can you guys please help me.

    Code:
    
    
    import java.util.*;
    
    public class megaMillion
    {
    public static void main(String []args)
     {int [][] group1=new int [5][5];
     int[] group2=new int[5];
     int i,cards,j;
     String yorn;
     char c;
     Scanner in=new Scanner(System.in);
     do
      {Random number = new Random();
      do{
        System.out.print("how many cards do you mant to play? at most 5: ");
        cards=in.nextInt();
        }while(cards<1||cards>5);
      for(i=0;i<cards;i++)
        {group2[i]=number.nextInt(46) +1;;
        for(j=0;j<5;j++)
           GenWinNums(group1,i,5,56,number);
        }
    
    System.out.println("\nYour Tickets are");
    for(i=0;i<cards;i++)
         {System.out.print("Ticket "+(i+1)+":\t");
          for(j=0;j<5;j++)
             System.out.print(group1[i][j]+"\t");
          System.out.println("::\t"+group2[i]);
          }
    System.out.print("\nplay again (y/n) ");
    yorn=in.next();
    c=yorn.charAt(0);
    }while(c=='Y'||c=='y');
    }
    
         
         
    
    
    public static boolean NoDuplicates(int a[][],int card,int n)
    {int i;
     boolean dup=false;
     if(n==0)
         return false;
     for(i=0;i<=n-1;i++)
         if(a[card][n]==a[card][i])
            dup=true;
      return dup;
    }  
    
    public static void GenWinNums(int a[][],int card,int n,int max, Random number)
    {int i;
    boolean dup=true;
    for(i=0;i<n;i++)
       {while(dup)
         {
          a[card][i]=number.nextInt(max) +1;
          dup=NoDuplicates(a,card,i);
          }
         dup=true;
       }
    sort(a,card,n);
    }
    public static void sort(int a[][],int card,int n)
    {int i,j,t;
    for(i=0;i<n-1;i++)
       for(j=i+1;j<n;j++)
           if(a[card][i]>a[card][j])
               {t=a[card][i];
               a[card][i]=a[card][j];
               a[card][j]=t;
               }
    return;
    }}
    
    
    
     

Share This Page