944,001 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1610
  • Java RSS
May 7th, 2007
0

Assignment Help ASAP!

Expand Post »
Hi, I'm new here. I'm kinda behind on my school work due to me going into labor early. So, I'm doing an assignment and the next thing I have to do is 'call the generate method and display the numbers for all four games,' and I'm stuck. Also I keep getting an error that says 'missing return type.' I would really appreciate if someone could help.

Java Syntax (Toggle Plain Text)
  1. // Exercise 15.13: LotteryPicker.java
  2. // This application picks randomly generated numbers for a lottery.
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. import java.text.DecimalFormat;
  6. import java.util.Random;
  7. import javax.swing.*;
  8. public class LotteryPicker extends JFrame
  9. {
  10. // JLabel and JTextField to display three number lottery
  11. private JLabel threeJLabel;
  12. private JTextField output3JTextField;
  13. // JLabel and JTextField to display four number lottery
  14. private JLabel fourJLabel;
  15. private JTextField output4JTextField;
  16. // JLabel and JTextField to display five number lottery
  17. private JLabel fiveJLabel;
  18. private JTextField output5JTextField;
  19. // JLabel and JTextField to display five number + one lottery
  20. private JLabel fivePlus1JLabel;
  21. private JTextField output5Plus1JTextField;
  22. private JTextField outputExtra1JTextField;
  23. // JButton to generate new lottery numbers
  24. private JButton generateJButton;
  25. // create a new Random object
  26. private Random generator = new Random();
  27.  
  28. // no-argument constructor
  29. public LotteryPicker()
  30. {
  31. createUserInterface();
  32. }
  33.  
  34. // create and position GUI components; register event handlers
  35. private void createUserInterface()
  36. {
  37. // get content pane for attaching GUI components
  38. Container contentPane = getContentPane();
  39. // enable explicit positioning of GUI components
  40. contentPane.setLayout( null );
  41. // set up threeJLabel
  42. threeJLabel = new JLabel();
  43. threeJLabel.setText( "Three number lottery:" );
  44. threeJLabel.setBounds( 16, 18, 132, 16 );
  45. contentPane.add( threeJLabel );
  46. // set up output3JTextField
  47. output3JTextField = new JTextField();
  48. output3JTextField.setBounds( 152, 16, 124, 23 );
  49. output3JTextField.setHorizontalAlignment( JTextField.CENTER );
  50. output3JTextField.setEditable( false );
  51. contentPane.add( output3JTextField );
  52. // set up fourJLabel
  53. fourJLabel = new JLabel();
  54. fourJLabel.setText( "Four number lottery:" );
  55. fourJLabel.setBounds( 16, 50, 132, 16 );
  56. contentPane.add( fourJLabel );
  57. // set up output4JTextField
  58. output4JTextField = new JTextField();
  59. output4JTextField.setBounds( 152, 48, 124, 23 );
  60. output4JTextField.setHorizontalAlignment( JTextField.CENTER );
  61. output4JTextField.setEditable( false );
  62. contentPane.add( output4JTextField );
  63. // set up fiveJLabel
  64. fiveJLabel = new JLabel();
  65. fiveJLabel.setText( "Five number lottery:" );
  66. fiveJLabel.setBounds( 16, 82, 132, 16 );
  67. contentPane.add( fiveJLabel );
  68. // set up output5JTextField
  69. output5JTextField = new JTextField();
  70. output5JTextField.setBounds( 152, 80, 124, 23 );
  71. output5JTextField.setHorizontalAlignment( JTextField.CENTER );
  72. output5JTextField.setEditable( false );
  73. contentPane.add( output5JTextField );
  74. // set up fivePlus1JLabel
  75. fivePlus1JLabel = new JLabel();
  76. fivePlus1JLabel.setText( "Five number + 1 lottery:" );
  77. fivePlus1JLabel.setBounds( 16, 114, 132, 16 );
  78. contentPane.add( fivePlus1JLabel );
  79. // set up output5Plus1JTextField
  80. output5Plus1JTextField = new JTextField();
  81. output5Plus1JTextField.setBounds( 152, 112, 92, 23 );
  82. output5Plus1JTextField.setHorizontalAlignment(
  83. JTextField.CENTER );
  84. output5Plus1JTextField.setEditable( false );
  85. contentPane.add( output5Plus1JTextField );
  86. // set up outputExtra1JTextField
  87. outputExtra1JTextField = new JTextField();
  88. outputExtra1JTextField.setBounds( 252, 112, 24, 23 );
  89. outputExtra1JTextField.setHorizontalAlignment(
  90. JTextField.CENTER );
  91. outputExtra1JTextField.setEditable( false );
  92. contentPane.add( outputExtra1JTextField );
  93. // set up generateJButton
  94. generateJButton = new JButton();
  95. generateJButton.setText( "Generate" );
  96. generateJButton.setBounds( 180, 152, 96, 24 );
  97. contentPane.add( generateJButton );
  98. generateJButton.addActionListener(
  99.  
  100. new ActionListener() // anonymous inner class
  101. {
  102. // event handler called when generateJButton is pressed
  103. public void actionPerformed( ActionEvent event )
  104. {
  105. generateJButtonActionPerformed( event );
  106. }
  107.  
  108. } // end anonymous inner class
  109.  
  110. ); // end call to addActionListener
  111. // set properties of application's window
  112. setTitle( "Lottery Picker" ); // set title bar string
  113. setSize( 300, 216 ); // set window size
  114. setVisible( true ); // display window
  115.  
  116. } // end method createUserInterface
  117.  
  118. // generate random lottery numbers
  119. private void generateJButtonActionPerformed( ActionEvent event )
  120. {
  121.  
  122.  
  123. } // end method generateJButtonActionPerformed
  124.  
  125. // generate random number in a given range from low to high
  126. private String generate( int low, int high )
  127. {
  128.  
  129. Random randomGenerator = new Random();
  130. int randomNumber = randomGenerator.nextInt();
  131.  
  132. } // end generate random number method
  133.  
  134.  
  135. // main method
  136. public static void main( String[] args )
  137. {
  138. LotteryPicker application = new LotteryPicker();
  139. application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
  140. } // end method main
  141.  
  142. } // end class LotteryPicker
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mspooh8 is offline Offline
1 posts
since May 2007
May 7th, 2007
0

Re: Assignment Help ASAP!

You are writing the return type of method as String but where is your return statement in method ...? So you are receiving this error "missing return type"

Java Syntax (Toggle Plain Text)
  1.  
  2. private String generate( int low, int high )
  3.  
  4. {<blockquote>-</blockquote><blockquote>-</blockquote><blockquote>return SomeStringValue</blockquote>}

You didn't called generate method anywhere ....!! So call this method on the actionPerformed event of genereate button and display the result.
Last edited by lucky1981_iway; May 7th, 2007 at 11:22 pm.
Reputation Points: 10
Solved Threads: 3
Light Poster
lucky1981_iway is offline Offline
46 posts
since Apr 2007

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: Search problem
Next Thread in Java Forum Timeline: Optimization





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


Follow us on Twitter


© 2011 DaniWeb® LLC