x.Hmo write a program to simulate the mega bucks. To my knowledge everything wor
ID: 3616152 • Letter: X
Question
x.Hmo write a program to simulate the mega bucks. To my knowledge everything works except for checking for duplicates and changing the duplicate to a different random number between 1 and 42 within the user's ticket and the computers tickets. I made a class and a driver for this project.HERE IS THE CLASS -
/**
* This class represents a MegaBucks object.
*
* Aaron Bagley
* 1/5/10
*/
import java.util.Scanner;
import java.util.ArrayList;
public class MegaBucks
{
private ArrayList<Integer>user; // The ArrayList for the user's ticket
private ArrayList<Integer>winner; // The ArrayList for the winning ticket
public MegaBucks()
{
user = new ArrayList<Integer>();
winner = new ArrayList<Integer>();
}
// ------------------------------------------------------
// The winning numbers that are randomly given to the
// computer without duplicates.
// ------------------------------------------------------
public void winNums()
{
for(int count = 0; count < 7; count++)
{
winner.add((int)(Math.random()*43));
}
System.out.println("The computer's numbers are:" + winner);
this.checkDuplicWin();
}
// ---------------------------------------
// Shows the numbers the user picked.
// ---------------------------------------
public void userPick()
{
for(int count = 0; count < 6; count++)
{
Scanner scan = new Scanner(System.in);
System.out.println("Please enter a number between 1 and 42.");
user.add(scan.nextInt());
}
System.out.println("Your numbers are:" + user);
this.checkDuplicUser();
}
//-----------------------------------------------
// This method removes the old set of numbers.
//-----------------------------------------------
public void removeNum()
{
winner.clear();
}
//------------------------------------------------------
// Checks for duplicates in the winer/computer's ticket.
//------------------------------------------------------
public void checkDuplicWin()
{
for(int count = 0; count < 6; count++)
for(int ct = count+1; ct < 7; ct++)
{
while(winner.get(count) == winner.get(ct))
{
winner.set(count, (int)(Math.random()*43));
}
}
}
//------------------------------------------------------
// Checks for duplicates in the user's group of numbers.
//------------------------------------------------------
public void checkDuplicUser()
{
for(int count = 0; count < 5; count++)
for(int ct = count+1; ct < 6; ct++)
{
while(user.get(count) == user.get(ct))
{
user.set(count, (int)(Math.random()*43));
}
}
}
//-------------------------------------------------
// Compares the user's pick to the winner's pick
// and returns true if the numbers match but
// returns false if the numbers do not equal.
//-------------------------------------------------
public boolean comparePicks()
{
int win = 0;
for(int count = 0; count < 6; count++)
{
for(int ct = 0; ct < 7; ct++)
{
if(user.get(count) == winner.get(ct))
Explanation / Answer
x.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.