//Account类
package com.power;
public class Account {
private int id;
private double balance;
public Account(int id,double balance){
this.balance = balance;
this.id = id;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public void withdraw(double amount){
if(balance < amount){
System.out.println("余额不足,取款失败!");
}else{
balance-=amount;
System.out.println("成功取出:"+amount);
System.out.println("当前余额为:"+balance);
}
}
public void deposit(double amount){
if(amount > 0){
balance+=amount;
System.out.println("当前余额为:"+balance);
}
}
public void balance(){
System.out.println("当前余额为:"+balance);
}
}
//customer类
package com.power;
public class customer {
private String name;
private Account account;
public customer(String name){
this.name = name;
}
public String getName() {
return name;
}
public Account getAccount() {
return account;
}
public void setAccount(Account account) {
this.account = account;
}
}
//测试类
package com.power;
import java.util.Scanner;
public class customertest {
public static void main(String[] args) {
customer cust = new customer("颜碧莹");
Account acct = new Account(1000, 2000);
cust.setAccount(acct);
System.out.println("假定您的余额为2000元!");
System.out.println("银行卡号为:" + cust.getAccount().getId() + ",姓名为:" + cust.getName());
Scanner sq = new Scanner(System.in);
System.out.println("请选择您所要进行的操作:");
System.out.println("1:进行存款;");
System.out.println("2:进行取款;");
System.out.println("3:查看余额;");
System.out.println("4:退出。");
int choice = sq.nextInt();
if (choice == 1) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入您的存款金额:");
double amount_deposited = sc.nextDouble();
cust.getAccount().deposit(amount_deposited);
}
if (choice == 2) {
Scanner se = new Scanner(System.in);
System.out.println("请输入您的取款金额:");
double amount_withdrawed = se.nextDouble();
cust.getAccount().withdraw(amount_withdrawed);
}
if (choice == 3) {
cust.getAccount().balance();
}
if (choice == 4) {
System.out.println("滚!");
}
}
}