Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: return statements kicking me out of do-while loop

  1. #1
    Junior Member
    Join Date
    Jun 2019
    Posts
    27
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default return statements kicking me out of do-while loop

    .
    Last edited by Markusovich_; June 18th, 2019 at 12:41 AM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: return statements kicking me out of do-while loop

    Please copy the full contents of the console window and paste it here so we can see what happens when the code is executed.

    A return statement will cause execution to return to the caller.
    What do you want the code to do at the locations where there are now return statements?


    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jun 2019
    Posts
    27
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: return statements kicking me out of do-while loop

    .
    Last edited by Markusovich_; June 18th, 2019 at 12:41 AM.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: return statements kicking me out of do-while loop

    Please copy the full contents of the console window and paste it here so we can see what happens when the code is executed.

    What do you want the code to do differently at the locations where there are now return statements?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Jun 2019
    Posts
    27
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default return statements kicking me out of do-while loop

    dsgwehfdsbrsfdnfgdsnb
    Last edited by Markusovich_; June 18th, 2019 at 12:39 AM.

  6. #6
    Member John Joe's Avatar
    Join Date
    Jun 2017
    Posts
    277
    My Mood
    Amused
    Thanks
    8
    Thanked 19 Times in 19 Posts

    Default Re: return statements kicking me out of do-while loop

    You don't need to use return statement. Return statement will break the loop.

    Modify your code to this

    Driver

    public class Driver {
     
        public static void main(String[] args) {
     
            CommisionCalculator hi = new CommisionCalculator();
            hi.Run();
        }
    }

    In Run function, replace return statement with System.out.println. At the last line, add the input value to allow user to key in the input.

     if (i == 1) {
                    System.out.println("First name: ");
                    String insured = scan.next();
                    System.out.println("Make: ");
                    String make = scan.next();
                    System.out.println("Model: ");
                    String model = scan.next();
                    System.out.println("Liability: ");
                    double liability = scan.nextDouble();
                    System.out.println("Collision: ");
                    double collision = scan.nextDouble();
                    a = new Auto(insured, make, model, liability, collision);
                    System.out.println(a.Filler());
                    int value = scan.nextInt();
                    if(value == 4){
                        System.out.println(a.toString());
                    }
                }

    Don't forget to remove all the return in each case statement.
    Whatever you are, be a good one

  7. The Following User Says Thank You to John Joe For This Useful Post:

    Markusovich_ (June 18th, 2019)

  8. #7
    Member John Joe's Avatar
    Join Date
    Jun 2017
    Posts
    277
    My Mood
    Amused
    Thanks
    8
    Thanked 19 Times in 19 Posts

    Default Re: return statements kicking me out of do-while loop

    Why you need to edit all your post?
    Whatever you are, be a good one

Similar Threads

  1. [SOLVED] Return statements while building a JPanel!
    By sebbe605 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 30th, 2014, 04:31 PM
  2. Other possible issues with if statements - book return program
    By Shenaniganizer in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 31st, 2012, 07:29 PM
  3. [SOLVED] Problem with multiple output statements in DO WHILE loop.
    By Nismoz3255 in forum Loops & Control Statements
    Replies: 0
    Last Post: February 22nd, 2012, 09:14 PM
  4. Stuck on a few Statements/Questions on timing of Main Game Loop.
    By StevenW in forum Java Theory & Questions
    Replies: 3
    Last Post: July 19th, 2011, 09:20 AM
  5. Return from incrementing for loop HELP?!
    By mindlessn00b in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 3rd, 2010, 02:36 PM

Tags for this Thread