Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9003377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:42:16+00:00 2026-06-16T00:42:16+00:00

Currently this is my code, and I need to display Please enter a valid

  • 0

Currently this is my code, and I need to display ” Please enter a valid choice” when the user don’t pick A,B,C,D,E or F as their choices. The problem is if I put the statement ” Please enter a valid….” on the “else” conditional, Java would ask me to initialized the variable ActivityFactor as there will not be one if the user don’t select the correct choice. Anyone know how I can fix this? Or any idea how I should code a program to do such?

if((inGender.equalsIgnoreCase("M") ||(inGender.equalsIgnoreCase ("F"))) && inActivity.equalsIgnoreCase("A"))
            ActivityFactor = 1.0;

        else if ((inGender.equalsIgnoreCase("M") ||(inGender.equalsIgnoreCase ("F"))) && inActivity.equalsIgnoreCase("B"))
        ActivityFactor = 1.3;

        else if (inGender.equalsIgnoreCase("M") && inActivity.equalsIgnoreCase("C"))
        ActivityFactor = 1.6;
        else if (inGender.equalsIgnoreCase("F") && inActivity.equalsIgnoreCase("C"))
        ActivityFactor = 1.5;
        else if (inGender.equalsIgnoreCase("M") && inActivity.equalsIgnoreCase("D"))
        ActivityFactor = 1.7;
        else if (inGender.equalsIgnoreCase("F") && inActivity.equalsIgnoreCase("D"))
        ActivityFactor = 1.6;
        else if (inGender.equalsIgnoreCase("M") && inActivity.equalsIgnoreCase("E"))
        ActivityFactor = 2.1;
        else if (inGender.equalsIgnoreCase("F") && inActivity.equalsIgnoreCase("E"))
        ActivityFactor = 1.9;
        else if (inGender.equalsIgnoreCase("M") && inActivity.equalsIgnoreCase("F"))
        ActivityFactor = 2.4;
        else if (inGender.equalsIgnoreCase("F") && inActivity.equalsIgnoreCase("F"))
        ActivityFactor = 2.2;
        else
        {
       ActivityFactor = -1;

    }

    //After
    if(ActivityFactor != -1){
     tdee = (nBMR * ActivityFactor);
     System.out.println(tdee);}
    else
   { System.out.println("Please enter a valid choice");
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:42:17+00:00Added an answer on June 16, 2026 at 12:42 am

    initialise ActivityFactor to an usual value before your conditional.

    For example you may do this:

    // knowing that it can never be -1
    // so if that value remains, you know that user entered wrong letter
    ActivityFactor = -1
    
    // then the conditional begins
    if((inGender.equalsIgnoreCase("M") ||(inGender.equalsIgnoreCase ("F"))) && inActivity.equalsIgnoreCase("A"))
    ...
    
    // after conditional...
    if(activityFactor != -1){
        double TDEE = (nBMR * ActivityFactor);
    }
    

    By the way, I suggest you use ‘activityFactor’ instead of ActivityFactor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently this code generates a colored hyperlink to an ad listing on my site.
I currently have this code which stores XML into an XML-type column called data,
I currently have this code: PACKETS = {}; function AddPacket(data) local id = data.ID;
I currently have this code : Private Sub Worksheet_Change(ByVal Target As Range) Dim lastrow
I currently have this code Private Sub Worksheet_Change(ByVal Target As Range) WorksheetChanged(Target, Range(AB3).CurrentRegion, Range(B18:B19))
I currently have this code which reads the first field in a database record
I'm currently using this code (per the codex) to show children on parent pages,
There is currently this Prototype code that does a PUT: new Ajax.Request(someUrl, { method:
I'm currently using this code to calculate the sunrise / sunset times. (To be
I am currently using this code to grab key-strokes, but I am missing e.g.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.