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

Thread: help whats wrong

  1. #1
    Junior Member
    Join Date
    Oct 2009
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry help whats wrong

    Been doing this one and totally miffed with this even a tutor looked and could not see error the problem line indicates ")" expected and highlights the line i have made bold, perhaps another set of eyes can find the problem.

    //this program decides amount of calories to a daily activity and weight

    import java.util.Scanner;
     
    public class calories1
    {
        public static void main (String [] args)
     
    {
     
            Scanner input = new Scanner (System.in);
     
            // delcaring variables
            double weight;
            String activityFactor;
     
            // program is now going to request input from user
     
            System.out.println("please enter your weight in Kilograms: ");
            weight  = input.nextDouble();
     
            System.out.println("Please enter if your lifestyle is active or inactive (a/i)");
            activityFactor = input.next();
     
            // program will calculate dependant on activity using if and else and or ||
     
                if (activityFactor.equals ("a") || activityFactor.equals ("A"))
               [B] System.out.println("your recommended calorie intake is " + (weight x 30)); [/B]
     
                else if (activityFactor.equals ("i") || activityFactor.equals ("I"))
                System.out.println("your recommended calorie intake is " + (weight x 20));
     
                else
                System.out.println("invalid input");
                System.out.println("GOODBYE");
     
            }
        }


  2. #2
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default Re: help whats wrong

    import java.util.Scanner;
     
    public class calories1
    {
    public static void main (String [] args)
     
    {
     
    Scanner input = new Scanner (System.in);
     
    // delcaring variables
    double weight;
    String activityFactor;
     
    // program is now going to request input from user
     
    System.out.println("please enter your weight in Kilograms: ");
    weight = input.nextDouble();
     
    System.out.println("Please enter if your lifestyle is active or inactive (a/i)");
    activityFactor = input.next();
     
    // program will calculate dependant on activity using if and else and or ||
     
    if (activityFactor.equals ("a") || activityFactor.equals ("A")) {
     
        System.out.println("your recommended calorie intake is " + (weight * 30));
    }
    else if (activityFactor.equals ("i") || activityFactor.equals ("I")) {
     
        System.out.println("your recommended calorie intake is " + (weight * 20));
    }
     
    else {
        System.out.println("invalid input");
        System.out.println("GOODBYE");
    }
     
    }
    }
    are you trying to multiply the weight? using "x" as an operator?
    if thats the case then i edited your post... in programming the operator in multiplication is not 'x'
    its an askterisk '*'

    / - division
    * - multiplication

    and another thing ill give you a simple advice..

    whenever your are making a statement for an if-else always put it inside an opening and closing bracket { }
    even if the statement is single.. single or compound always put it in a braces

    because if you dont you will have some compiling error. ahm or some logic error..


    anyway is this what you want?

  3. #3
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default Re: help whats wrong

    ah one more thing.. dont forget to add code tags in your java code

    ' [ CODE ] your java code here [ /CODE ] '

    Last edited by chronoz13; October 2nd, 2009 at 12:25 PM.

  4. #4
    Junior Member
    Join Date
    Oct 2009
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help whats wrong

    ironic thing is that the tutor is teaching this and did not spot any of that that is bad and worrying because i on a degree course.

    Thanks for you help

  5. #5
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default Re: help whats wrong

    hmm in some sense thats not good for you. but in someway its very efficient because you will learn how to correct your own mistakes....
    anyway im glad i statisfied you regarding with your post

Similar Threads

  1. whats wrong with this one....
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: October 6th, 2009, 11:08 AM
  2. [SOLVED] whats wrong with my IDE
    By chronoz13 in forum Java IDEs
    Replies: 2
    Last Post: August 27th, 2009, 07:34 AM
  3. Generation of Palindrome number in Java
    By tina.goyal in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 26th, 2009, 09:49 AM
  4. [SOLVED] Difference between public and private variable and their uses
    By napenthia in forum Java Theory & Questions
    Replies: 1
    Last Post: April 22nd, 2009, 12:36 PM