Itzi Bitzi Mitzi

Reply

Join Date: Jan 2007
Posts: 3
Reputation: mgland is an unknown quantity at this point 
Solved Threads: 0
mgland mgland is offline Offline
Newbie Poster

Itzi Bitzi Mitzi

 
0
  #1
Jan 24th, 2007
I have a project that I am working on for 5 days, and I am stuck. I have been able to generate some numbers, but no based on the instructions below. Can you please provide some assistance on what I missing and what I need to do to get this thing working. I have attached the code.

1. Generating random numbers.

a. Create a method in line 142 named generate that will take two ints, representing the low and high end of a range of random nubers and return a string containing a generated random number.

b. Drawing numbers for the games. Add code to the generateJButtonActionPerformed metod to call the generate method and display the generated numbers for all four games. Some lotteries allow repitition of numbers. To make this appliation simple, allow repetition of numbers for all the lotters.

itzi bitzi mitzi
Attached Files
File Type: doc lotterypicker.doc (35.0 KB, 2 views)
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 12,040
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 126
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: Itzi Bitzi Mitzi

 
0
  #2
Jan 24th, 2007
For those who don't want to download the attached .doc file:

  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import java.text.DecimalFormat;
  4. import java.util.Random;
  5. import javax.swing.*;
  6.  
  7. public class LotteryPicker extends JFrame
  8. {
  9. // JLabel and JTextField to display three number lottery
  10. private JLabel threeJLabel;
  11. private JTextField output3JTextField;
  12.  
  13. // JLabel and JTextField to display four number lottery
  14. private JLabel fourJLabel;
  15. private JTextField output4JTextField;
  16.  
  17. // JLabel and JTextField to display five number lottery
  18. private JLabel fiveJLabel;
  19. private JTextField output5JTextField;
  20.  
  21. // JLabel and JTextField to display five number + one lottery
  22. private JLabel fivePlus1JLabel;
  23. private JTextField output5Plus1JTextField;
  24. private JTextField outputExtra1JTextField;
  25.  
  26. // JButton to generate new lottery numbers
  27. private JButton generateJButton;
  28.  
  29. // create a new Random object
  30. private Random generator = new Random();
  31. private int game3one = 0 + generator.nextInt( 10 );
  32. private int game3two = 0 + generator.nextInt( 10 );
  33. private int game3three = 0 + generator.nextInt( 10 );
  34.  
  35. //private int game3 = 0 + generator.nextInt( 10 );
  36. private int game4 = 0 + generator.nextInt( 10 );
  37. private int game5 = 1 + generator.nextInt( 40 );
  38. private int game5Plus1 = 1 + generator.nextInt( 50 );
  39. private int game5PlusExtra = 1 + generator.nextInt( 43 );
  40.  
  41. // no-argument constructor
  42. public LotteryPicker()
  43. {
  44. createUserInterface();
  45. }
  46.  
  47. // create and position GUI components; register event handlers
  48. private void createUserInterface()
  49. {
  50. // get content pane for attaching GUI components
  51. Container contentPane = getContentPane();
  52.  
  53. // enable explicit positioning of GUI components
  54. contentPane.setLayout( null );
  55.  
  56. // set up threeJLabel
  57. threeJLabel = new JLabel();
  58. threeJLabel.setText( "Three number lottery:" );
  59. threeJLabel.setBounds( 16, 18, 132, 16 );
  60. contentPane.add( threeJLabel );
  61.  
  62. // set up output3JTextField
  63. output3JTextField = new JTextField();
  64. output3JTextField.setBounds( 152, 16, 124, 23 );
  65. output3JTextField.setHorizontalAlignment( JTextField.CENTER );
  66. output3JTextField.setEditable( false );
  67. contentPane.add( output3JTextField );
  68.  
  69. // set up fourJLabel
  70. fourJLabel = new JLabel();
  71. fourJLabel.setText( "Four number lottery:" );
  72. fourJLabel.setBounds( 16, 50, 132, 16 );
  73. contentPane.add( fourJLabel );
  74.  
  75. // set up output4JTextField
  76. output4JTextField = new JTextField();
  77. output4JTextField.setBounds( 152, 48, 124, 23 );
  78. output4JTextField.setHorizontalAlignment( JTextField.CENTER );
  79. output4JTextField.setEditable( false );
  80. contentPane.add( output4JTextField );
  81.  
  82. // set up fiveJLabel
  83. fiveJLabel = new JLabel();
  84. fiveJLabel.setText( "Five number lottery:" );
  85. fiveJLabel.setBounds( 16, 82, 132, 16 );
  86. contentPane.add( fiveJLabel );
  87.  
  88. // set up output5JTextField
  89. output5JTextField = new JTextField();
  90. output5JTextField.setBounds( 152, 80, 124, 23 );
  91. output5JTextField.setHorizontalAlignment( JTextField.CENTER );
  92. output5JTextField.setEditable( false );
  93. contentPane.add( output5JTextField );
  94.  
  95. // set up fivePlus1JLabel
  96. fivePlus1JLabel = new JLabel();
  97. fivePlus1JLabel.setText( "Five number + 1 lottery:" );
  98. fivePlus1JLabel.setBounds( 16, 114, 132, 16 );
  99. contentPane.add( fivePlus1JLabel );
  100.  
  101. // set up output5Plus1JTextField
  102. output5Plus1JTextField = new JTextField();
  103. output5Plus1JTextField.setBounds( 152, 112, 92, 23 );
  104. output5Plus1JTextField.setHorizontalAlignment(
  105. JTextField.CENTER );
  106. output5Plus1JTextField.setEditable( false );
  107. contentPane.add( output5Plus1JTextField );
  108.  
  109. // set up outputExtra1JTextField
  110. outputExtra1JTextField = new JTextField();
  111. outputExtra1JTextField.setBounds( 252, 112, 24, 23 );
  112. outputExtra1JTextField.setHorizontalAlignment(
  113. JTextField.CENTER );
  114. outputExtra1JTextField.setEditable( false );
  115. contentPane.add( outputExtra1JTextField );
  116.  
  117. // set up generateJButton
  118. generateJButton = new JButton();
  119. generateJButton.setText( "Generate" );
  120. generateJButton.setBounds( 180, 152, 96, 24 );
  121. contentPane.add( generateJButton );
  122. generateJButton.addActionListener(
  123.  
  124. new ActionListener() // anonymous inner class
  125. {
  126. // event handler called when generateJButton is pressed
  127. public void actionPerformed( ActionEvent event )
  128. {
  129. generateJButtonActionPerformed( event );
  130. }
  131.  
  132. } // end anonymous inner class
  133.  
  134. ); // end call to addActionListener
  135.  
  136. // set properties of application's window
  137. setTitle( "Lottery Picker" ); // set title bar string
  138. setSize( 300, 216 ); // set window size
  139. setVisible( true ); // display window
  140.  
  141. } // end method createUserInterface
  142.  
  143. // generate random lottery numbers
  144. private void generateJButtonActionPerformed( ActionEvent event )
  145. {
  146.  
  147. output3JTextField.setText( String.valueOf( game3one + " "
  148. + game3two + " " + game3three));
  149. // output3JTextField.setText( String.valueOf( game3 ));
  150. output4JTextField.setText( String.valueOf( game4 ));
  151. output5JTextField.setText(String.valueOf( game5));
  152. output5Plus1JTextField.setText(String.valueOf( game5Plus1 ));
  153. outputExtra1JTextField.setText(String.valueOf( game5PlusExtra ));
  154.  
  155.  
  156. } // end method generateJButtonActionPerformed
  157.  
  158. private void generate()
  159. {
  160. int low = 0;
  161. int high = 10;
  162. Random generator = new Random();
  163. String number = String.valueOf( low + generator.nextInt
  164. ( high ) );
  165.  
  166. } // end method generate
  167. // main method
  168. public static void main( String[] args )
  169. {
  170. LotteryPicker application = new LotteryPicker();
  171. application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
  172.  
  173. } // end method main
  174.  
  175. } // end class LotteryPicker
Dani the Computer Science Gal
Follow my Twitter feed! twitter.com/daniweb
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 353
Reputation: aniseed is an unknown quantity at this point 
Solved Threads: 6
aniseed's Avatar
aniseed aniseed is offline Offline
Posting Whiz

Re: Itzi Bitzi Mitzi

 
0
  #3
Jan 25th, 2007
Originally Posted by mgland View Post
a. Create a method in line 142 named generate that will take two ints, representing the low and high end of a range of random nubers and return a string containing a generated random number.
If you want the method to return a String, you should not be declaring the method to return 'void' and you should be taking the low and high values as method arguments.
Last edited by aniseed; Jan 25th, 2007 at 3:40 am.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 353
Reputation: aniseed is an unknown quantity at this point 
Solved Threads: 6
aniseed's Avatar
aniseed aniseed is offline Offline
Posting Whiz

Re: Itzi Bitzi Mitzi

 
0
  #4
Jan 25th, 2007
  1. private void generate(int low, int high) {
  2. Random generator = new Random();
  3.  
  4. return String.valueOf( low + generator.nextInt( high -low ) );
  5.  
  6. }
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,359
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: Itzi Bitzi Mitzi

 
-1
  #5
Jan 25th, 2007
As a comment on your signature, many military elements, in many countries around the world, have played around with weather control, and China is actually actively attempting to manipulate the weather right now to avoid droughts in some areas of the country (it hasn't been working to well, but they are doing it). ;-)
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 353
Reputation: aniseed is an unknown quantity at this point 
Solved Threads: 6
aniseed's Avatar
aniseed aniseed is offline Offline
Posting Whiz

Re: Itzi Bitzi Mitzi

 
0
  #6
Jan 25th, 2007
Originally Posted by masijade View Post
As a comment on your signature, many military elements, in many countries around the world, have played around with weather control, and China is actually actively attempting to manipulate the weather right now to avoid droughts in some areas of the country (it hasn't been working to well, but they are doing it). ;-)
:lol:
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC