浏览了一些编程任务(第一年),我想出了这个。当我运行它时,程序直接进入 switch 语句的默认值。现在已经连续工作了大约 24 小时,所以我几乎不知道,但我就是找不到出了什么问题。
谁能指出我的写作方向。我不想让你为我做
// Practical 5B - Question 1
// Nathan Griffin
// 28/02/2013
// Program to simulate a continuos system of deposits and withdraw for a bank account until user exits.
import java.util.Scanner;
public class SingleAccountSim
{
public static void main(String [] args)
{
Scanner keyboardIn = new Scanner(System.in);
BankAccount account = new BankAccount();
int menuSelect = 0;
double depositIn, withdrawalOut;
do
{
System.out.println("*_*_*Monopoly Bank*_*_*");
System.out.println("1. Deposit money");
System.out.println("2. Withdraw money");
System.out.println("3. Get balance");
System.out.println("4. Quit");
menuSelect = keyboardIn.nextInt();
switch(menuSelect)
{
case '1': System.out.print("Please enter the deposit amount: ");
depositIn = keyboardIn.nextDouble();
account.deposit(depositIn);
break;
case '2': System.out.print("Please enter the withdrawl amount: ");
withdrawalOut = keyboardIn.nextDouble();
account.withdraw(withdrawalOut);
break;
case '3': System.out.print("Your current balance is " + account.getBalance());
break;
case '4': System.out.print("Quitting.....");
break;
default: System.out.println("Invalid selection. Please try again");
}
}while(menuSelect !=4);
}
}