public class Rectangle { public double width; public double height; public String color; public double getWidth(){ return width; } public void setWidth(double i) { this.width = i; } public double getHeight(){ return height; } public void setHeight(double h) { this.height = h; } public String getColor() { return color; } public void setColor(String c) { this.color = c; } public double getArea() { return height*width; } public double getLength() { return (height+width)*2; } }
import java.util.Scanner; public class Account { public int id; public int password; public String name; public int money; public Account(int id, int password, String name, int money) { this.id = id; this.password = password; this.name = name; this.money = money; } public void show(){ System.out.println("账户:" + id); System.out.println("姓名:" + name); System.out.println("余额:" + money); } public void takeMoney(){ while(true){ Scanner sc = new Scanner(System.in); System.out.println("输入密码"); int pass = sc.nextInt(); if(pass == password){ System.out.println("取款金额:"); int withdrawals = sc.nextInt(); if(withdrawals <= money) { money= money-withdrawals; System.out.println("余额为:" + money); } else { System.out.println("当前余额不足" ); } break; } else{ System.out.println("密码错误,请重新输入!"); } } } public void saveMoney(int moneys){ money = money+moneys; System.out.println("此次存款为:" + moneys); System.out.println("账户余额为:" + money); } public static void main(String[] args) { Account acc = new Account(10010,123456,"陈果",0); Scanner sc = new Scanner(System.in); System.out.println("请输入需要执行的操作"); System.out.println("1银行账户信息"); System.out.println("2取款操作"); System.out.println("3存款操作"); System.out.println("4退出系统"); int s = sc.nextInt(); switch(s) { case 1: System.out.println("银行账户"); acc.show(); break; case 2: System.out.println("取款"); acc.takeMoney(); break; case 3: System.out.println("存款"); acc.saveMoney(1000); break; case 4: System.exit(0); break; } } }