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 6936397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:13:43+00:00 2026-05-27T12:13:43+00:00

How does one code for a choice between two options? if ((one_spinner.getSelectedItem().toString() .equals(one))) {

  • 0

How does one code for a choice between two options?

if ((one_spinner.getSelectedItem().toString()
                    .equals("one"))) {
                double one_thing = new Double(one.getText()
                        .toString());
                double two_thing = one_thing * 5;

            } else {
                double two_thing = new Double(one.getText()
                        .toString());
                double one_thing = two / 5;
            }
  • 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-05-27T12:13:44+00:00Added an answer on May 27, 2026 at 12:13 pm

    Assuming you want to refer to one_thing and two_thing after the if statement, you need to declare them before the if statement, so that they’ll still be in scope:

    double one_thing;
    double two_thing;
    if (one_spinner.getSelectedItem().toString().equals("one")) {
       one_thing = Double.parseDouble(one.getText().toString());
       two_thing = one_thing * 5;
    } else {
       two_thing = Double.parseDouble(one.getText().toString());
       one_thing = two_thing / 5;
    }
    

    Note that this can be simplified in terms of removing redundant code:

    double parsedValue = Double.parseDouble(one.getText().toString());
    
    double one_thing;
    double two_thing;
    if (one_spinner.getSelectedItem().toString().equals("one")) {
       one_thing = parsedValue;
       two_thing = one_thing * 5;
    } else {
       two_thing = parsedValue;
       one_thing = two_thing / 5;
    }
    

    Or, given that the relationship between the two is always a factor of 5:

    double one_thing = Double.parseDouble(one.getText().toString());
    if (one_spinner.getSelectedItem().toString().equals("one")) {
       one_thing = one_thing / 5;
    }
    double two_thing = one_thing * 5;
    

    Note that conventionally these names would be oneThing and twoThing, by the way.

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

Sidebar

Related Questions

how does one use code to do this: produce 15 random numbers [EDIT: from
When implementing the Strategy Pattern, where does one put the code that determines which
How does one execute some VBA code periodically, completely automated?
How does one go about attaching a bunch of code to an onkeydown event,
Where does one go to report bugs in Google Code? Alas, searching for Google
Does any one know from where can I download source code for Cassini. I
I'm usually one to say any piece of code no matter what it does,
Question: How does one deploy a HttpHandler in asp.net 2.0? Updated Http Handler code
does one perform better over the other in terms of indexing/quering etc ? e.g.
How does one go about authoring a Regular Expression that matches against all strings

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.