日期:2014-05-20 浏览次数:20816 次
import java.util.Scanner; public class Testt { public static void main(String[] args) { double a1 = 0; double b1; int count; Scanner input = new Scanner(System.in); Account a = new Account(); do { System.out.println("1.存款 2.取款 0.退出"); System.out.println("请选择你需要办理的业务:"); count = input.nextInt(); switch (count) { case 0: System.out.println("谢谢使用"); break; case 1: System.out.println("请输入存款金额:"); a1 = input.nextDouble(); System.out.println("存款成功"); a.setSum(a.shape(a1)); System.out.println("*****当前余额为:" + a.getSum() + "元*****"); break; case 2: System.out.println("请输入取款金额:"); b1 = input.nextDouble(); if (a.getSum() >= a.qukuan(b1)) { System.out.println("取款成功"); a.setSum(a.qukuan(b1)); System.out.println("*****当前余额为:" + a.getSum() + "元*****"); } else { System.out.println("错误!"); } break; default: System.out.println("您的输入有误,请重新输入:"); count = input.nextInt(); break; } } while (count != 0); } } class Account { double sum = 0; // 带参存款 public double shape(double a) { return sum + a; } // 带参取款 public double qukuan(double b) { return sum - b; } public double getSum() { return sum; } public void setSum(double sum) { this.sum = sum; } }