944,161 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1694
  • Java RSS
Jan 24th, 2007
0

Itzi Bitzi Mitzi

Expand Post »
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, 13 views)
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mgland is offline Offline
3 posts
since Jan 2007
Jan 24th, 2007
0

Re: Itzi Bitzi Mitzi

For those who don't want to download the attached .doc file:

java Syntax (Toggle Plain Text)
  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
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 163
The Queen of DaniWeb
cscgal is offline Offline
13,646 posts
since Feb 2002
Jan 25th, 2007
0

Re: Itzi Bitzi Mitzi

Click to Expand / Collapse  Quote originally posted by mgland ...
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.
Reputation Points: 48
Solved Threads: 7
Posting Whiz
aniseed is offline Offline
353 posts
since Apr 2006
Jan 25th, 2007
0

Re: Itzi Bitzi Mitzi

Java Syntax (Toggle Plain Text)
  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. }
Reputation Points: 48
Solved Threads: 7
Posting Whiz
aniseed is offline Offline
353 posts
since Apr 2006
Jan 25th, 2007
0

Re: Itzi Bitzi Mitzi

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). ;-)
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Jan 25th, 2007
0

Re: Itzi Bitzi Mitzi

Click to Expand / Collapse  Quote originally posted by masijade ...
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:
Reputation Points: 48
Solved Threads: 7
Posting Whiz
aniseed is offline Offline
353 posts
since Apr 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: hi im new to java project
Next Thread in Java Forum Timeline: Java Text Editor (Scroll Bars)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC