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

Thread: I need help with these "if" statement and boolean errors

  1. #1
    Junior Member
    Join Date
    Nov 2019
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post I need help with these "if" statement and boolean errors

    The purpose of this program that I'm writing is to calculate a user's total daily energy expenditure. However, for some reason, it's giving me a ton of errors regarding my boolean operators and "if-else-if" statements. I feel like I'm missing something obvious, could you guys help?:
     
    import java.util.Scanner;
    public class TDEE
    {
        public static void main(String [] args)
        {
            double activityFactor;   
            double TDEE;
            Scanner in = new Scanner(System.in);        
     
     
            System.out.print("Please enter your name: ");
            String firstName = in.next();                    
            String lastName = in.next();
            System.out.println(firstName + " " + lastName);
            System.out.print("Please enter your BMR: ");
            double userBMR = in.nextDouble();
            System.out.println(userBMR);
            System.out.print("Please enter your gender (M/F): ");
            String userGender = in.next();
            System.out.println(userGender);
            System.out.println();
     
            System.out.println("Select your Activity Level");
            System.out.println("[A] Resting (Sleeping, Reclining)");
            System.out.println("[B] Sedentary (Minimal Movement)");
            System.out.println("[C] Light (Sitting, Standing)");
            System.out.println("[D] Moderate (Light Manual Labor, Dancing, Riding Bike)");
            System.out.println("[E] Very Active (Team Sports, Hard Manual Labor)");
            System.out.println("[F] Extremely Active (Full-Time Athlete, Heavy Manual Labor)");
            System.out.println();
            System.out.print("Enter the letter corresponding to your activity level: ");
            String choice = in.next();
            System.out.println(choice);
     
            if(choice.equalsIgnoreCase("A"))                          
            {                                                           
                activityFactor = 1.0;
                TDEE = userBMR * activityFactor;
            }                                                          
            else if (choice.equalsIgnoreCase("B")) 
            {
                activityFactor = 1.3;
                TDEE = userBMR * activityFactor;
            }
            }
            else if (choice.equalsIgnoreCase("C")) && (userGender.equalsIgnoreCase("F"))
            {
                activityFactor = 1.5;
                TDEE = userBMR * activityFactor;
            }
            else if ((choice.equalsIgnoreCase("C")) && (userGender.equalsIgnoreCase("M"))) || ((choice.equalsIgnoreCase("D")) && (userGender.equalsIgnoreCase("F")))
            {
                activityFactor = 1.6;
                TDEE = userBMR * activityFactor;
            }
            else if (choice.equalsIgnoreCase("D")) && (userGender.equalsIgnoreCase("M"))
            {
                activityFactor = 1.7;
                TDEE = userBMR * activityFactor;
            }
            else if (choice.equalsIgnoreCase("E")) && (userGender.equalsIgnoreCase("F"))
            {
                activityFactor = 1.9;
                TDEE = userBMR * activityFactor;
            }
            else if (choice.equalsIgnoreCase("E")) && (userGender.equalsIgnoreCase("M"))
            {
                activityFactor = 2.1;
                TDEE = userBMR * activityFactor;
            }
            else if (choice.equalsIgnoreCase("F")) && (userGender.equalsIgnoreCase("F")) 
            {
                activityFactor = 2.2;
                TDEE = userBMR * activityFactor;
            }
            else if (choice.equalsIgnoreCase("F")) && (userGender.equalsIgnoreCase("M"))
            {
                activityFactor = 2.4;
                TDEE = userBMR * activityFactor;
            }
            else 
            {
                System.out.println("You did not choose a valid menu option!");
            }
            System.out.println();
            System.out.print("Name: " + firstName + " " + lastName);
            System.out.println("     Gender: " + userGender);
            System.out.print("BMR: " + userBMR);
            System.out.println("     Activity Factor: " + activityFactor);
            System.out.print("TDEE: " + TDEE);
     
         }//end of main method
    }//end of class
    Last edited by Norm; November 25th, 2019 at 06:12 PM. Reason: Added []s to code tags

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

    Default Re: I need help with these "if" statement and boolean errors

    it's giving me a ton of errors
    Please copy full text of error messages and paste here.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 4
    Last Post: July 18th, 2014, 02:04 AM
  2. Replies: 1
    Last Post: July 16th, 2014, 04:16 AM
  3. Replies: 2
    Last Post: May 22nd, 2014, 01:17 PM
  4. Trying to get an "if" statement to work in a "for loop".
    By JAKATAK in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 1st, 2013, 11:16 PM
  5. "Program execution skips the "if" statement"!
    By antony1925 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 7th, 2012, 07:15 AM