Ich brauche Hilfe bei der Festlegung meiner boolean, ich bin sehr neu in der Programmierung und mein Professor Englisch ist arm.Easy Java Boolean
Ich brauche 5 bis mpg
hinzufügen, wenn highway
true
und 2 subtrahieren, wenn city
false
ist.
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 highway = true;
boolean city = false;
if (highway == true) {
mpg = mpg + 5;
}
if (city == false) {
mpg = mpg - 2;
}
System.out.println("Enter true if trip is on the highway false if the trip is in the city");
in.nextBoolean();
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);
}
}
die boolean ab sofort 3 in die mpg hinzufügen, aber ich brauche es 5 hinzufügen, wenn wahr oder 2 subtrahieren, wenn falsche – Pexing
Bitte von mindestens beginnen richtig Formatierung Code. Indentation Angelegenheiten; Dieses Zeug ist wirklich schwer zu lesen. Du willst, dass andere dir helfen; also machen Sie ihre Arbeit so einfach wie möglich. – GhostCat
Nein, es fügt 5 hinzu und subtrahiert dann 2. Genau wie Sie angegeben haben. Die Bedingungen schließen sich nicht gegenseitig aus. Und das Ergebnis ist eine Veränderung von +3. – zapl