以下の機能コードを書いたので、プログラム内からメニュー設定を外に変更したいだけです。私はsodaMachineの内容を.txtファイルから取得して、プログラムが.txtファイルから取り出し、 "Take your drink(1.)"と表示するようにしました。.txtファイルから読み込み、プログラムが.txtファイルの変数と文字列を使用して更新するようにしました。
私の質問は、正確なintと、コマンドの.txtファイルからの文字列を取得するプログラムを取得するために追加するものです。したがって、 "1."を入力すると、 "コカコーラ"とその価格(int) "150"が抽出されます。
import java.lang.Math;
import java.util.Scanner;
public class CST1201 {
private static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
int coinTotal = 0;
int coinTotal2 = 0;
int coinTotal3 = 0;
int runAgain = 1;
while(runAgain == 1)
{
while (coinTotal < 100){
System.out.println("Please insert a coin ");
coinTotal2 = input.nextInt();
if (coinTotal2 != 25 && coinTotal2 != 5 && coinTotal2 != 10)
{
coinTotal2 = 0;
while (coinTotal2 != 25 && coinTotal2 != 5 && coinTotal2 != 10)
{
System.out.println("Please insert a coin(5,10,25)");
coinTotal2 = input.nextInt();
if (coinTotal2 != 25 && coinTotal2 != 5 && coinTotal2 != 10)
{
coinTotal2 = 0;
}
else
{
coinTotal = coinTotal + coinTotal2;
coinTotal3 = coinTotal + coinTotal2;
}
}
}
else
{
coinTotal = coinTotal + coinTotal2;
}
System.out.println("Total: " + coinTotal);
}
int choice = 0;
System.out.println("What would you like? \n1.Coca-Cola \n2.Pepsi \n3.Orange Soda \n4.Grape Soda \n5.Mountain Dew \n6.Water");
choice = input.nextInt();
if (choice ==1) {
System.out.println("Please take your Coca-Cola");
} else {
if(choice == 2) {
System.out.println("Please take your pepsi");
} else {
if (choice == 3) {
System.out.println("Please take your Orange Soda");
} else {
if (choice == 4) {
System.out.println("Please take your Grape Soda");
} else {
if (choice == 5) {
System.out.println("Please take your Mountain Dew");
} else {
if (choice == 6) {
System.out.println("Please take your water");
}
}
}
}
}
}
int change;
if (coinTotal > 100){
change = coinTotal - 100;
System.out.println("Please take your change: " + change);
}
System.out.println("Would you like to buy another drink?");
runAgain = input.nextInt();
if (runAgain == 1)
{
coinTotal = 0;
}
else
{
runAgain = 0;
System.out.println("Thank you");
}
}
}
}
ありがとうございます。私はちょうどそれを行う方法を考え出した、私は現在どのように私は.txtファイルを更新するかに取り組んでいます。 – theslurpeemaker