Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/forums/java/)
-   -   Array to Vector (http://www.go4expert.com/forums/array-to-vector-t17992/)

dsptl 15Jun2009 04:29

Array to Vector
 
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;
}}



All times are GMT +5.5. The time now is 07:07.