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 8 of 8

Thread: I am a newbie and I am stuck PLEASE HELP!!!

  1. #1
    Member
    Join Date
    Sep 2012
    Posts
    31
    My Mood
    Confused
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default I am a newbie and I am stuck PLEASE HELP!!!

    I am trying to validate that a user input valid information at the prompt but I keep getting errors please help!
    Here is my code:
        private double computeAverageSales() {
            WebHost webHost;
            double average = 0;
            double total = 0;
            int counter = 0;
     
     
            for (int i = 0; i <= 0; i++) {
                while (true) {
                    do {
                        System.out.print("Please enter the price of the new package: $");
     
                        while (!scanner.hasNextDouble()) {
                            System.out.println("Please enter a postive number!");
                            scanner.next();
                        }
     
                        double webHostPrice = scanner.nextDouble();
                        total = webHostPrice + total;
                        counter++;
                        while (webHostPrice <= 0) {
                            break;
                        }
                    }
     
                        do {
                            System.out.print("What will be the product ID: ");
     
                            while (!scanner.hasNextInt()) {
                                System.out.print("Please enter a valid product ID!");
                                scanner.next();                  
                            int webHostId = scanner.nextInt();
                            scanner.nextLine();
                            }
                        }
                            do {
                                System.out.print("What is the product name: ");
                                while (!scanner.hasNext("")) {
                                    System.out.print("Please enter the product name!");
                                    scanner.next();
     
     
                                    String webHostName = scanner.nextLine();
                                    do {
                                        System.out.print("Please enter the required Bandwidth needed for your site? ");
                                        while (!scanner.hasNextDouble()) {
                                            System.out.print("Please enter a positive number!");
                                            scanner.next();
                                            double webHostBandwidth = scanner.nextDouble();
                                        }
     
                                            do {
                                                System.out.print("How many FTP accounts do you need? ");
                                                while (!scanner.hasNextInt()) {
                                                    System.out.print("Please enter a valid number!");
                                                    scanner.next();
                                                    int webHostFtp = scanner.nextInt();
                                                    scanner.nextLine();
                                                    do {
                                                        System.out.print("How many email accounts do you need? ");
                                                        while (!scanner.hasNextInt()) {
                                                            System.out.print("Please enter a valid number");
                                                            scanner.next();
                                                            do {
                                                                System.out.print("What is your domain name? ");
                                                                while (!scanner.hasNext("")) {
                                                                    System.out.print("Please enter a valid domain name");
                                                                    scanner.next();
                                                                    int webHostMail = scanner.nextInt();
                                                                    scanner.nextLine();
                                                                    String webHostDomain = scanner.nextLine();
                                                                    webHost = new WebHost(webHostBandwidth, webHostPrice, webHostFtp,
                                                                            webHostMail, webHostId, webHostDomain, webHostName);
     
                                                                } 
                                                                average = total / (counter - 1);      
                                                                return average;
                                                           }
            }
        }

    I know it is messy but that is me messing with it for three days please help.


  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: I am a newbie and I am stuck PLEASE HELP!!!

    I keep getting errors
    Please copy the full text of the error message and paste it here.


       scanner.next();
    What does that line of code do?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Sep 2012
    Posts
    31
    My Mood
    Confused
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: I am a newbie and I am stuck PLEASE HELP!!!

    Like I said I am new at this and I found the do{....}while{.....scanner.next();} online for validation
    The error I am getting says "while expected" when I try to close the do statement

  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: I am a newbie and I am stuck PLEASE HELP!!!

    Please copy the full text of the error message and paste it here. It has important info about the error.

    "while expected"
    Where is the while() part of the do{}while() statement?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Sep 2012
    Posts
    31
    My Mood
    Confused
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: I am a newbie and I am stuck PLEASE HELP!!!

    when I run the code this is the error I am getting
    run:

    Welcome to the Web Host Ordering System

    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - missing return statement
    at WebHostOrder.computeAverageSales(WebHostOrder.java :136)
    at WebHostOrder.<init>(WebHostOrder.java:124)
    at WebHostOrder.main(WebHostOrder.java:265)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 6 seconds)

  6. #6
    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: I am a newbie and I am stuck PLEASE HELP!!!

    java.lang.RuntimeException
    Can you do the compile step only and get the compiler's errors? Don't try to execute/run the code with compiler errors. You need to fix the compiler errors BEFORE trying to execute the code.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Member
    Join Date
    Sep 2012
    Posts
    31
    My Mood
    Confused
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: I am a newbie and I am stuck PLEASE HELP!!!

    I changed the text color of the "while" section
    do {
                            System.out.print("What will be the product ID: ");
     
                            [COLOR="#FFFF00"]while (!scanner.hasNextInt()) {
                                System.out.print("Please enter a valid product ID!");
                                scanner.next();                  
                            int webHostId = scanner.nextInt();
                            scanner.nextLine();
                            }[/COLOR]


    --- Update ---

    Yes I am using NetBeans and I get the red flag when I hover over it that is when it gives me the "While Expected" error

    --- Update ---

    Would you like for me to upload a compressed folder of the NetBeans project?

  8. #8
    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: I am a newbie and I am stuck PLEASE HELP!!!

    The code is FULL of syntax errors and missing while statements and mismatched {}s

    One solution is to retype the whole method from the beginning.
    Type in a few lines, including the beginning { and ending } for each loop and a few statements inside and do a compile. Fix the errors, compile again. when the compile doesn't have any errors, add a few more lines, compile, fix and then add some more lines and do it again.

    I don't use Netbeans.
    If you don't understand my answer, don't ignore it, ask a question.

  9. The Following User Says Thank You to Norm For This Useful Post:

    mstratmann (April 30th, 2013)

Similar Threads

  1. hi all very new to all this and stuck already....
    By mrgray in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 15th, 2013, 03:06 PM
  2. Help!, newbie, interested in Java, Very simple code, completely stuck!
    By munkybunky in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 30th, 2011, 07:25 AM
  3. Im stuck, please help
    By bigsmoke101 in forum Loops & Control Statements
    Replies: 3
    Last Post: April 12th, 2011, 04:34 PM
  4. Stuck help please!
    By mindlessn00b in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 5th, 2010, 05:31 PM
  5. I am stuck
    By hawkman4188 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 29th, 2010, 12:46 AM