아래에 작동하는 코드를 작성 했으므로 프로그램 내에서 외부로 내 메뉴 설정을 간단히 변경하고 싶습니다. 프로그램이 .txt 파일에서 가져올 프로그램 외부의 .txt 파일에서 sodaMachine 내용을 가져 오도록 요청 받았으며 "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