Assignment Help ASAP!

Reply

Join Date: May 2007
Posts: 1
Reputation: mspooh8 is an unknown quantity at this point 
Solved Threads: 0
mspooh8 mspooh8 is offline Offline
Newbie Poster

Assignment Help ASAP!

 
0
  #1
May 7th, 2007
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.

  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
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 46
Reputation: lucky1981_iway is an unknown quantity at this point 
Solved Threads: 3
lucky1981_iway's Avatar
lucky1981_iway lucky1981_iway is offline Offline
Light Poster

Re: Assignment Help ASAP!

 
0
  #2
May 7th, 2007
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"

  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.
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC