Results 1 to 6 of 6
  1. #1
    IzzyBelles is offline Member
    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0

    Default Problem with Return Statement

    Ok, so I'm new to Java and I'm trying to code a boolean program. It's telling me I have an error for return statement. Could someone please tell me what I'm missing?
    Java Code:
    import javax.swing.*;
    
    public class TestScore
    {
    public static void main(String[] args)
    {
    String testScore = JOptionPane.showInputDialog("\nEnter your testing score (0-100)");
    int score = Integer.parseInt (testScore);
    String volunteerHours = JOptionPane.showInputDialog("\nEnter the number of volunteer hours worked");
    int hours = Integer.parseInt (volunteerHours);
    shouldAccept(score, hours);
    }
    public static boolean shouldAccept(int score, int hours)
    {
    if (score > 100 || score < 0 || hours < 0)
    JOptionPane.showMessageDialog(null, "The data you have entered is incorrect");
    
    else if (score >= 90 || score >= 75 && hours >= 125)
    {
    JOptionPane.showMessageDialog(null, "You have been accepted for this position");
    return true;
    }
    else
    {
    JOptionPane.showMessageDialog(null, "You have not been accepted for this position");
    return false;
    }
    }
    }
    Last edited by IzzyBelles; 03-16-2013 at 05:41 PM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: Need help.

    Please read the Forum Rules, especially the third paragraph. Then go through Guide For New Members and BB Code List - Java Programming Forum - Learn Java Programming and edit your post accordingly. To change the subject line, click 'Edit Post' and then 'Go Advanced'

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    IzzyBelles is offline Member
    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0

    Default Re: Need help.

    Sorry about that. Very new to all this. Did I edit that correctly?

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Need help.

    Quote Originally Posted by IzzyBelles View Post
    Sorry about that. Very new to all this. Did I edit that correctly?
    Almost -- you want to post *formatted* easy to read code with appropriate and regular indentation, not all left-justified code which is very difficult to read. Also you'll want to post the actual error message.

  5. #5
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: Problem with Return Statement

    Line 17 is missing a return statement. If you successfully enter that block, then none of the other returns happen. You must return a boolean there.

  6. #6
    Wizard0860 is offline Member
    Join Date
    Nov 2012
    Posts
    29
    Rep Power
    0

    Default Re: Problem with Return Statement

    You have a return statement after he else-if and else, but no return after the if.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •