实现代码:
package 银行账户存储管理;
import java.util.Scanner;
/******start******/
class account {
public String name;
public float balance;
public account(String name, float balance) {
super();
= name;
this.balance = balance;
}
public void save(float money){
System.out.println("账户"+name+"存款:"+money);
balance=balance+money;
}
public void draw(float money){
balance=balance-money;
if(balance>=0){
System.out.println("账户"+name+"取款:"+money);
}
else{
System.out.println("账户"+name+"当前余额:"+money+"元");
balance=balance+money;
}
}
public void displayBalance(){
System.out.println("账户"+name+"余额:"+this.balance);
}
}
/******end******/
public class main {
public static void main(String[] args) {
System.out.print("请输入账户名 当前余额 取款金额 存款金额 (中间以空格分隔)");
Scanner scanner = new Scanner(System.in);
String name = scanner.next();
float balance = scanner.nextFloat();
float saveMoney = scanner.nextFloat();
float drawMoney = scanner.nextFloat();
account a = new account(name, balance);
System.out.println("output:");
a.displayBalance();
a.save(saveMoney);
a.draw(drawMoney);
a.displayBalance();
scanner.close();
}
}