私は Java を学んでいますが、私が書いている単純なプログラムが本来の方法で動作しない理由を理解するのに苦労しています。
import java.util.Scanner;
class CarApp{
String carMake;
String carColour;
String features;
int carPrice;
void carFinal(){
System.out.println(carMake);
System.out.println(carPrice);
if(carMake == "ford")
{
carPrice = 120000;
}
else if(carMake == "porsche")
{
carPrice = 1000000;
}
System.out.println(carPrice);
System.out.println("Thank you for choosing your car with the car chooser app!" + "\n");
System.out.println("You have chosen a " + carColour + " " + carMake + " with " + features + "\n" );
System.out.println("Your car will be delivered to you in 7 working days. At a price of R" + carPrice + ".");
}
}
public class App {
public static void main(String[] args) {
Scanner carChooser = new Scanner(System.in);
CarApp carApp = new CarApp();
System.out.println("Please let us know which car you would like, porsche or ford:");
carApp.carMake = carChooser.nextLine();
System.out.println("Please say which color car you would like:");
carApp.carColour = carChooser.nextLine();
System.out.println("Which features would you like added to your car:");
carApp.features = carChooser.nextLine();
carApp.carFinal();
}
}
システムが価格を印刷していないようですか?だから私はいつも次のようになります:
Your car will be delivered to you in 7 working days. At a price of R0.
どんな助けでも大歓迎です。それは非常に些細なことであり、おそらく私が見落としているものだと思います。前もって感謝します、
フレッド