|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
ArrayList and Iterator problems!! Lotto Machine
I am trying to write the ticket class for a lotto ticket machine. I have created a Number class but I am having trouble with the Ticket class, my code is below if anyone can help!!!
import java.util.ArrayList; import java.util.Iterator; /** * Class Ticket. * Builds a Lucky Dip Lotto Ticket. * Creates an arrayList of Lucky Dip numbers then displays the ticket and numbers to the screen. * * @author ############# * @version ############ * * Note : The following is only a suggested set of fields, constructors and methods, * candidates may design their own class if they wish. * */ public class Ticket { private int numberOfLines; private ArrayList lotoLines; // Constructor : Creates an arrayList of Lucky Dip numbers, takes one argument to load the numberOfLines field. /** * Creates an arrayList of Lucky Dip numbers, * takes one argument to load the numberOfLines field. */ public Ticket() { lotoLines = new ArrayList(); numberOfLines = 1; } // Method : Display the ticket details and the list of Lucky Dip numbers to the screen. /** * Show the ticket details and list the list of Lucky Dip numbers to the screen. */ public void showNumbers() { Iterator it = lotoLines.iterator(); while(it.hasNext()){ Numbers lotoLines = (Numbers) it.next(); System.out.println(lotoLines.toString()); } } } Last edited by handy : March 28th, 2005 at 08:16 AM. Reason: updated code |
|
#2
|
||||
|
||||
|
In the future, try wrapping your code in [code][/code] tags when posting the forum.
Can you explain further? What happens when your Ticket class is run? "What do you expect it to do" vs "What does it do" This will save us from having to compile the code and create a test class |
|
#3
|
|||
|
|||
|
Reply to message - Lotto
Hi,
I want to have as many randomly generated Lucky Dips as required on the same ticket. I have constructed the numbers class which generates the random numbers. I now need to link the Ticket class to the numbers class to store the Lucky Dip number sets in a flexible-sized collection(array list) Display the ticket and the Lucky Dip numbers to the screen in the correct format, this will Allow an output for a ticket with five lucky dips and an output for a ticket with three lucky dips. Thank you in advance for your help |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Java Development > ArrayList and Iterator problems!! Lotto Machine |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|