[问题] 自制atm问题

楼主: HarryWen (Harry)   2016-01-10 00:13:33
小弟想要在press[5]转换英文接口
但不管我怎么研究都无法执行成功
我试图在default: Break之间
硬塞一个英文接口但都不成功 可能对资料结构不熟
Java新手求教。
不是来这求答案是来求知识
import java.util.Scanner;
import java.io.*;
public class ATMMachine
{
public static void checkBalance()
{
System.out.println("\t您当前余额为 " + BalanceInquiry.getBalance());
}
public static void withdrawMoney()
{
if(BalanceInquiry.balance==0)
{
System.out.println("\t您当前的余额为零.");
System.out.println("\t你无法领取!");
System.out.println("\t你需要先存钱。");
}
else if(BalanceInquiry.balance<=500)
{
System.out.println("\t你没有足够的钱领取");
System.out.println("\t请检查您的帐户余额是否足够.");
}
else if(Withdraw.withdraw > BalanceInquiry.balance)
{
System.out.println("\t你取款的金额超过您的余额");
System.out.println("\t请检查您输入的金额.");
}
else
{
BalanceInquiry.balance = BalanceInquiry.balance - Withdraw.withdra
w;
System.out.println("\n\t您提取的金额为 NT. " + Withdraw.withdraw);
}
}
public static void depositMoney()
{
System.out.println("\t你存款的金额为 NT. " + Deposit.getDeposit());
}
public static void main(String[] args)
{
Scanner read = new Scanner(System.in);
int select = 0;
int choice = 0;
System.out.println("==================================================
==");
System.out.println("\t欢迎来到这个简单的ATM机");
System.out.println("==================================================
==");
System.out.println();
do
{try
{
do {
System.out.println("\t请选择ATM交易");
System.out.println("\t按[1]存款");
System.out.println("\t按[2]提款");
System.out.println("\t按[3]余额查询");
System.out.println("\t按[4]退出");
System.out.println("\t按[5]ENGLISH");
System.out.print("\n\t你的选择是? ");
select = read.nextInt();
if(select>5)
{
System.out.println("\n\t请选择正确的交易.");
}
else
{
switch (select)
{
case 1:
System.out.print("\n\t输入的货币量以存款: ");
Deposit.deposit = read.nextDouble();
BalanceInquiry.balance = Deposit.deposit + Bal
anceInquiry.balance;
depositMoney();
break;
case 2:
System.out.print("\n\t要退出,请确保您的帐户中
有足够的余额.");
System.out.println();
System.out.print("\t输入提款金额: ");
Withdraw.withdraw = read.nextDouble();
withdrawMoney();
break;
case 3:
checkBalance();
break;
case 4:
System.out.print("\n\t交易退出.");
break;
default:
System.out.println("\tPlease select ATM Transacti
ons");
System.out.println("\tPress [1] Deposit");
System.out.println("\tPress [2] Withdraw");
System.out.println("\tPress [3] Balance Inquir
y");
System.out.println("\tPress [4] Exit");
System.out.print("\n\tWhat would you like to d
o? ");
select = read.nextInt();
break;
}
}
}while(select>5);
do {
try
{
System.out.println("\n\t还有其他交易要执行?");
System.out.println("\n\t按[1]有 按[2]没有");
System.out.print("\t输入选择: ");
choice = read.nextInt();
if(choice>2)
{
System.out.print("\n\t请选择正确的选择.");
}
}
catch(Exception e)
{
System.out.println("\t错误输入!请只输入数字.");
read = new Scanner(System.in);
System.out.println("\t输入您的选择:");
choice = read.nextInt();
}
} while(choice>2);
}
catch(Exception e)
{
System.out.println("\t错误输入!请只输入数字.");
read = new Scanner(System.in);
System.out.println("\t输入您的选择:");
select = read.nextInt();
}
}while(choice<=1);
System.out.println("\n\t谢谢你使用这个简单的ATM机器.");
}
}
class Deposit extends ATMMachine
{
static double deposit;
public void setDeposit(double d)
{
deposit = d;
}
public static double getDeposit()
{
return deposit;
}
}
class Withdraw extends ATMMachine
{
static double withdraw = 0;
public void setWithdraw(double w)
{
withdraw = w;
}
public static double getWithdraw()
{
return withdraw;
}
}
class BalanceInquiry extends ATMMachine
{
static double balance = 0;
public void setBalance(double b)
{
balance = b;
}
public static double getBalance()
{
return balance;
}
}
作者: icydream (巧虎)   2016-01-10 07:33:00
在英文接口中,若输入的值<=5的话,就会离开循环我的想法是新增一个boolean变量,默认是true,用来判断呈现接口,默认是中文接口。然后在选项的地方,使用这个变量判断呈现的是中/英文,在default里把这个变量值设为false
楼主: HarryWen (Harry)   2016-01-10 14:21:00
If(select<=5) While(select<=5)Boolean status=true. ; System.out.println("status="+status);像这样子吗

Links booklink

Contact Us: admin [ a t ] ucptt.com