I need to create a way for the user to enter the weather (snowy, rainy, or sunny) and after they do this it effects the MPG (Miles Per Gallon) of the car. Snowy minuses 4, rainy minuses 2 and sunny has no effect. The hint I had was to use in.equals but I know my code is far off. So my question is how do I ask the user for a input that effects another variable with three possible answers?
import java.util.Scanner;
public class AdvancedTripCalc {
public static void main(String[] args) {
// New Trip Calc.
String firstname;
int mpg;
int miles;
double price;
double totalcost;
Scanner in = new Scanner(System.in);
System.out.println("Please enter your First Name");
firstname = in.nextLine();
System.out.println("Please enter the MPG of your car");
mpg = in.nextInt();
boolean city;
System.out.println("Enter true if trip is in the city false if the trip is on the highway");
city = in.nextBoolean();
if (city){
mpg = mpg - 2;
}
else {
mpg = mpg + 5;
}
boolean weather;
double snowy = 0;
double rainy = 0;
double sunny = 0;
System.out.println("What is the weather like?");
weather = in.equals(snowy);
{
mpg = mpg - 4;
}
weather = in.equals(rainy);{
mpg = mpg - 1;
}
weather = in.equals(sunny);{
mpg = mpg;
}
System.out.println("Please enter the Miles to be traveled");
miles = in.nextInt();
System.out.println("Please enter the price per gallon of gas");
price = in.nextDouble();
totalcost = miles * price / mpg;
System.out.println("Your name is " +firstname);
System.out.println("Your MPG is " +mpg);
System.out.println("Your miles to be traveled is " +miles);
System.out.println("Your price per gallon of gas is " +price);
System.out.println("Your total cost is " +totalcost);
}
}
This is what I have so far.