0

Why doesn't my program not registering the value of the sting variable? When I run the program, it all goes fine, but when I get to the part where I type in the planet, the pathway goes directly to the invalid choice, and not the actual decision.

import java.util.Scanner; public class Planet {

public static void main(String[] args) 
{
    //Import the scanner
    Scanner keyboard = new Scanner(System.in);

    //Create variables
    double weight = 0;
    String planet = "";
    double result = 0;


    //Ask for user's weight
    System.out.println("What is your weight on Earth?");
    weight = keyboard.nextDouble();

    //Open menu for planets
    System.out.println("\nChoose a planet...\n\nMercury\nVenus\nMars\nJupiter\nSaturn\nUranus\nNeptune\nPluto");
    planet = keyboard.next();


    //Calculate weight
    if (planet=="Mercury")
    {
        result = (weight * .37);
    }
    else if (planet=="Venus")
    {
        result = (weight * .88);
    }
    else if (planet=="Mars")
    {
        result = (weight*.38);
    }
    else if (planet=="Jupiter")
    {
        result = (weight*2.64);
    }
    else if (planet=="Saturn")
    {
        result = (weight*1.15);
    }
    else if (planet=="Uranus")
    {
        result = (weight*1.15);
    }
    else if (planet=="Neptune")
    {
        result = (weight*1.12);
    }
    else if (planet=="Pluto")
    {
        result = (weight*.04);
    }
    else  
    {
        System.out.println("Invalid choice.");
    }

    //Output weight
    System.out.println("Your weight is " + weight + " on Earth. Your weight is " + result + " on " + planet + ".");


}

}

0 Answers0