package EXER;
public class Account
{
private int id;
private double balance;
private double annualInterestRate;
public Account(int i,double b,double a)
{
id = i;
balance = b;
annualInterestRate = a;
}
public int getId() {
return id;
}
public double getBalance() {
return balance;
}
public double getAnnualInterestRate() {
return annualInterestRate;
}
public void setId(int id) {
this.id = id;
}
public void setBalance(double balance) {
this.balance = balance;
}
public void setAnnualInterestRate(double annualInterestRate) {
this.annualInterestRate = annualInterestRate;
}
@Override
public String toString() {
return "Account{" +
"id=" + getId() +
", balance=" + getBalance() +
", annualInterestRate=" + getAnnualInterestRate() +
'}';
}
public void withdraw(double amount)//取钱
{
if(amount <= balance && amount > 0)
{
balance = balance - amount;
System.out.println("成功取出"+amount);
}
else
{
System.out.println("余额不足");
}
}
public void deposit(double amount)//存款
{
if(amount > 0)
{
balance = balance + amount;
System.out.println("存入成功");
}
}
}
package EXER;
public class Account
{
private int id;
private double balance;
private double annualInterestRate;
public Account(int i,double b,double a)
{
id = i;
balance = b;
annualInterestRate = a;
}
public int getId() {
return id;
}
public double getBalance() {
return balance;
}
public double getAnnualInterestRate() {
return annualInterestRate;
}
public void setId(int id) {
this.id = id;
}
public void setBalance(double balance) {
this.balance = balance;
}
public void setAnnualInterestRate(double annualInterestRate) {
this.annualInterestRate = annualInterestRate;
}
@Override
public String toString() {
return "Account{" +
"id=" + getId() +
", balance=" + getBalance() +
", annualInterestRate=" + getAnnualInterestRate() +
'}';
}
public void withdraw(double amount)//取钱
{
if(amount <= balance && amount > 0)
{
balance = balance - amount;
System.out.println("成功取出"+amount);
}
else
{
System.out.println("余额不足");
}
}
public void deposit(double amount)//存款
{
if(amount > 0)
{
balance = balance + amount;
System.out.println("存入成功");
}
}
}
package EXER;
public class Bank
{
private Customer[] customers;
private int numberOfCustomer;
public Bank(int num)
{
customers = new Customer[num];
}
public void addCustomer(String f,String j)
{
Customer c = new Customer("f","j");
customers[numberOfCustomer++] = c;
}
public int getNumberOfCustomer()
{
return numberOfCustomer;
}
public Customer getCustomer(int index)
{
if(index < 0 || index >= numberOfCustomer)
{
System.out.println("错误");
return null;
}
else
{
return customers[index];
}
}
}
package EXER;
public class Bank
{
private Customer[] customers;
private int numberOfCustomer;
public Bank(int num)
{
customers = new Customer[num];
}
public void addCustomer(String f,String j)
{
Customer c = new Customer("f","j");
customers[numberOfCustomer++] = c;
}
public int getNumberOfCustomer()
{
return numberOfCustomer;
}
public Customer getCustomer(int index)
{
if(index < 0 || index >= numberOfCustomer)
{
System.out.println("错误");
return null;
}
else
{
return customers[index];
}
}
}
package EXER;
public class Customer
{
private String firstName;
private String lastName;
private Account account;
public Customer(String f,String l)
{
firstName = f;
lastName = l;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Account getAccount()
{
return account;
}
public void setAccount(Account account)
{
this.account = account;
}
}
package EXER;
public class Customer
{
private String firstName;
private String lastName;
private Account account;
public Customer(String f,String l)
{
firstName = f;
lastName = l;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Account getAccount()
{
return account;
}
public void setAccount(Account account)
{
this.account = account;
}
}
package EXER;
public class Test
{
public static void main(String[] args)
{
Customer c1 = new Customer("Jane","Smith");
c1.setAccount(new Account(1000,2000.0,0.0123));
Account a = c1.getAccount();
c1.getAccount().deposit(100);
c1.getAccount().withdraw(960);
c1.getAccount().withdraw(2000);
System.out.println(c1.getAccount().toString());
System.out.println(a.toString());
Bank b = new Bank(10);
b.addCustomer("曹","操");
b.addCustomer("刘","备");
b.getCustomer(0).setAccount(new Account(1000,2000.0,0.0123));
b.getCustomer(0).getAccount().withdraw(100);
System.out.println(b.getCustomer(0).getAccount().toString());
}
}
package EXER;
public class Test
{
public static void main(String[] args)
{
Customer c1 = new Customer("Jane","Smith");
c1.setAccount(new Account(1000,2000.0,0.0123));
Account a = c1.getAccount();
c1.getAccount().deposit(100);
c1.getAccount().withdraw(960);
c1.getAccount().withdraw(2000);
System.out.println(c1.getAccount().toString());
System.out.println(a.toString());
Bank b = new Bank(10);
b.addCustomer("曹","操");
b.addCustomer("刘","备");
b.getCustomer(0).setAccount(new Account(1000,2000.0,0.0123));
b.getCustomer(0).getAccount().withdraw(100);
System.out.println(b.getCustomer(0).getAccount().toString());
}
}