package Bank.com;
import java.util.Scanner;
public class Account {
public static float money = 0;
public static void main(String[] args) {
// TODO Auto-generated method stub
menu();
}
/**
* 显示菜单
* */
public static void menu(){
System.out.println("1.存款 2.取款 3.退出");
System.out.print("请选择你需要办理的业务:");
Scanner scanner = new Scanner(System.in);
int read = scanner.nextInt();
switch(read){
case 1: deposit(); break;
case 2: withDraw(); break;
case 3:
System.out.println("谢谢使用!");
System.exit(0); break;
default:
menu();
}
}
/**
* 存款
* */
private static void deposit() {
// TODO Auto-generated method stub
System.out.print("请输入存款金额:");
Scanner scanner = new Scanner(System.in);
float depositMoney = scanner.nextFloat();
money += depositMoney;
System.out.println("存款成功");
showMoney();
menu();
}
/**
* 取款
* */
private static void withDraw() {
// TODO Auto-generated method stub
System.out.print("请输入取款金额:");
Scanner scanner = new Scanner(System.in);
float withDrawMoney = scanner.nextFloat();
money -= withDrawMoney;
if(money < 0){
System.out.println("余额不足");
money += withDrawMoney;
}else{
System.out.println("取款成功");
showMoney();
}
menu();
}
/**
* 显示金额
* */
private static void showMoney() {
// TODO Auto-generated method stub
System.out.println();
System.out.println("*** 当前余额为:"+ money +"元***");
System.out.println();
}
}
目录结构和运行结果看图,很简单,就不写注释了。