该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
public class Account { // 初始化存款
float count = 0f;// 当前账户余额
int money1;// 存款数, int money2;// 取款数 /*
* 存款
*/
public float saveMoney() {
count += money1;
return count;
} /*
* 取款
*/
public float getMoney() {
if (count == 0) {
System.out.println("你的余额不足"); } else {
count -= money2;
System.out.println("你的余额不足"); }
return count;
}
}
/*
* 模拟银行存取款业务
*/
import java.util.Scanner; public class TestBan {
public static void main(String[] args) {
boolean isOk = false;
Account st = new Account();
Scanner sc = new Scanner(System.in); do {
System.out.println("1.存款 2.取款 0 退出");
System.out.print("请选择你需要办理的业务:");
int num = sc.nextInt();
switch (num) {
case 1:
System.out.print("请输入存款金额:");
st.money1 = sc.nextInt();
float a = st.saveMoney();
System.out.println("存款成功");
System.out.println("\n***当前余额为" + a + "元***\n");
isOk = true;
break;
case 2:
System.out.print("请输入取款金额:");
st.money2 = sc.nextInt();
if (st.count == 0||st.count
System.out.println("你的余额不足\n");
} else {
float b = st.getMoney();
System.out.println("取款成功");
System.out.println("\n***当前余额为" + b + "元***\n");
}
isOk = true;
break;
case 0:
System.out.println("谢谢使用!");
isOk = false;
break;
default:
break;
}
} while (isOk);
}
}