| | |
Assignment Help ASAP!
![]() |
•
•
Join Date: May 2007
Posts: 1
Reputation:
Solved Threads: 0
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)
// Exercise 15.13: LotteryPicker.java // This application picks randomly generated numbers for a lottery. import java.awt.*; import java.awt.event.*; import java.text.DecimalFormat; import java.util.Random; import javax.swing.*; public class LotteryPicker extends JFrame { // JLabel and JTextField to display three number lottery private JLabel threeJLabel; private JTextField output3JTextField; // JLabel and JTextField to display four number lottery private JLabel fourJLabel; private JTextField output4JTextField; // JLabel and JTextField to display five number lottery private JLabel fiveJLabel; private JTextField output5JTextField; // JLabel and JTextField to display five number + one lottery private JLabel fivePlus1JLabel; private JTextField output5Plus1JTextField; private JTextField outputExtra1JTextField; // JButton to generate new lottery numbers private JButton generateJButton; // create a new Random object private Random generator = new Random(); // no-argument constructor public LotteryPicker() { createUserInterface(); } // create and position GUI components; register event handlers private void createUserInterface() { // get content pane for attaching GUI components Container contentPane = getContentPane(); // enable explicit positioning of GUI components contentPane.setLayout( null ); // set up threeJLabel threeJLabel = new JLabel(); threeJLabel.setText( "Three number lottery:" ); threeJLabel.setBounds( 16, 18, 132, 16 ); contentPane.add( threeJLabel ); // set up output3JTextField output3JTextField = new JTextField(); output3JTextField.setBounds( 152, 16, 124, 23 ); output3JTextField.setHorizontalAlignment( JTextField.CENTER ); output3JTextField.setEditable( false ); contentPane.add( output3JTextField ); // set up fourJLabel fourJLabel = new JLabel(); fourJLabel.setText( "Four number lottery:" ); fourJLabel.setBounds( 16, 50, 132, 16 ); contentPane.add( fourJLabel ); // set up output4JTextField output4JTextField = new JTextField(); output4JTextField.setBounds( 152, 48, 124, 23 ); output4JTextField.setHorizontalAlignment( JTextField.CENTER ); output4JTextField.setEditable( false ); contentPane.add( output4JTextField ); // set up fiveJLabel fiveJLabel = new JLabel(); fiveJLabel.setText( "Five number lottery:" ); fiveJLabel.setBounds( 16, 82, 132, 16 ); contentPane.add( fiveJLabel ); // set up output5JTextField output5JTextField = new JTextField(); output5JTextField.setBounds( 152, 80, 124, 23 ); output5JTextField.setHorizontalAlignment( JTextField.CENTER ); output5JTextField.setEditable( false ); contentPane.add( output5JTextField ); // set up fivePlus1JLabel fivePlus1JLabel = new JLabel(); fivePlus1JLabel.setText( "Five number + 1 lottery:" ); fivePlus1JLabel.setBounds( 16, 114, 132, 16 ); contentPane.add( fivePlus1JLabel ); // set up output5Plus1JTextField output5Plus1JTextField = new JTextField(); output5Plus1JTextField.setBounds( 152, 112, 92, 23 ); output5Plus1JTextField.setHorizontalAlignment( JTextField.CENTER ); output5Plus1JTextField.setEditable( false ); contentPane.add( output5Plus1JTextField ); // set up outputExtra1JTextField outputExtra1JTextField = new JTextField(); outputExtra1JTextField.setBounds( 252, 112, 24, 23 ); outputExtra1JTextField.setHorizontalAlignment( JTextField.CENTER ); outputExtra1JTextField.setEditable( false ); contentPane.add( outputExtra1JTextField ); // set up generateJButton generateJButton = new JButton(); generateJButton.setText( "Generate" ); generateJButton.setBounds( 180, 152, 96, 24 ); contentPane.add( generateJButton ); generateJButton.addActionListener( new ActionListener() // anonymous inner class { // event handler called when generateJButton is pressed public void actionPerformed( ActionEvent event ) { generateJButtonActionPerformed( event ); } } // end anonymous inner class ); // end call to addActionListener // set properties of application's window setTitle( "Lottery Picker" ); // set title bar string setSize( 300, 216 ); // set window size setVisible( true ); // display window } // end method createUserInterface // generate random lottery numbers private void generateJButtonActionPerformed( ActionEvent event ) { } // end method generateJButtonActionPerformed // generate random number in a given range from low to high private String generate( int low, int high ) { Random randomGenerator = new Random(); int randomNumber = randomGenerator.nextInt(); } // end generate random number method // main method public static void main( String[] args ) { LotteryPicker application = new LotteryPicker(); application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); } // end method main } // end class LotteryPicker
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"
You didn't called generate method anywhere ....!! So call this method on the actionPerformed event of genereate button and display the result.
Java Syntax (Toggle Plain Text)
private String generate( int low, int high ) {<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.
![]() |
Similar Threads
- USb to Serial Cable Pin Assignment (USB Devices and other Peripherals)
- Help needed with VB Assignment (Visual Basic 4 / 5 / 6)
- confused with the assignment ... need help asap (C++)
- Trying to write a program for an assignment... (Java)
- round robin scheduling (Java)
- I need help on my 'address book' assignment! (C++)
Other Threads in the Java Forum
- Previous Thread: Search problem
- Next Thread: Optimization
| Thread Tools | Search this Thread |
2dgraphics 3d @param affinetransform android api applet application arc arguments array arrays automation banking binary bluetooth byte chat chatprogramusingobjects class client code color compare component count database design detection eclipse eclipsedevelopment encryption error fractal game givemetehcodez graphics gridlayout gui guitesting helpwithhomework html ide if_statement image input integer interface j2me java java.xls javadesktopapplications javaprojects jni jpanel julia keytool keyword linux list loop macintosh map method methods mobile netbeans newbie object os pong problem producer program programming project projectideas read recursion reference replaysolutions rim scanner server set size sms sort sql string swing terminal threads transforms tree ui unicode validation web windows





