Account:

package banking5;
//账户 public class Account {
protected double balance; public Account(double int_balance) {
balance = int_balance;
} public double getBlance() {
return balance;
} public boolean deposit(double amt) {
balance += amt;
return true;
} public boolean withdraw(double amt) {
if (balance >= amt) {
balance -= amt;
return true;
} else {
System.out.println("余额不足");
return false;
}
}
}

Customer:

package banking5;

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 Account getAccount() {
return account;
} public void setAccount(Account acct) {
account = acct;
}
}

Bank:

package banking5;

public class Bank {

    private Customer[] customers;
private int numberOfCustomers; public Bank() {
customers = new Customer[5];
} public void addCustomer(String f, String l) {
Customer cust = new Customer(f, l);
customers[numberOfCustomers] = cust;
numberOfCustomers++;
} public int getNumberofCustomer() {
return numberOfCustomers;
} public Customer getCustomer(int index) {
return customers[index];
}
}

CheckingAccount:

package banking5;

//信用卡账户
public class CheckingAccount extends Account {
private double overdraftProtection;// 透支额度 public CheckingAccount(double balance) {
super(balance);
} public CheckingAccount(double balance, double protect) {
super(balance);
this.overdraftProtection = protect;
} public double getOverdraftProtection() {
return overdraftProtection;
} public void setOverdraftProtection(double overdraftProtection) {
this.overdraftProtection = overdraftProtection;
} public boolean withdraw(double amt) {
if (balance >= amt) {
balance -= amt;
return true;
} else if (overdraftProtection >= amt - balance) { overdraftProtection -= (amt - balance);
balance = 0;
return true;
} else {
System.out.println("额度不够");
return false;
}
}
}

SavingAccount:

package banking5;

public class SavingAccount extends Account {
private double interestRate;// 利率 public SavingAccount(double balance, double init_rate) {
super(balance);
this.interestRate = init_rate;
} public double getInterestRate() {
return interestRate;
} public void setInterestRate(double interestRate) {
this.interestRate = interestRate;
} }

TestBanking5:

package TestBanking;
/*
* This class creates the program to test the banking classes.
* It creates a new Bank, sets the Customer (with an initial balance),
* and performs a series of transactions with the Account object.
*/ import banking5.Account;
import banking5.Bank;
import banking5.CheckingAccount;
import banking5.Customer;
import banking5.SavingAccount; public class TestBanking5 { public static void main(String[] args) {
Bank bank = new Bank();
Customer customer;
Account account; // Create bank customers and their accounts
// System.out.println("Creating the customer Jane Smith.");
bank.addCustomer("Jane", "Simms");
// code
account = new SavingAccount(500.00, 0.03);
customer = bank.getCustomer(0);
customer.setAccount(account); System.out.println("Creating her Savings Account with a 500.00 balance and 3% interest.");
// code
System.out.println("Creating the customer Owen Bryant.");
// code
bank.addCustomer("Owner", "Bryant");
customer = bank.getCustomer(1);
account = new CheckingAccount(500.00);
customer.setAccount(account);
System.out.println("Creating his Checking Account with a 500.00 balance and no overdraft protection.");
// code System.out.println("Creating the customer Tim Soley.");
bank.addCustomer("Tim", "Soley");
customer = bank.getCustomer(2);
account = new CheckingAccount(500.00, 500.00);
customer.setAccount(account); System.out.println("Creating his Checking Account with a 500.00 balance and 500.00 in overdraft protection.");
// code
System.out.println("Creating the customer Maria Soley.");
// code
bank.addCustomer("Maria", "Soley");
customer = bank.getCustomer(3);
// account =bank.getCustomer(2).getAccount(); System.out.println("Maria shares her Checking Account with her husband Tim.");
customer.setAccount(bank.getCustomer(2).getAccount()); System.out.println(); //
// Demonstrate behavior of various account types
// // Test a standard Savings Account
System.out.println("Retrieving the customer Jane Smith with her savings account.");
customer = bank.getCustomer(0);
account = customer.getAccount();
// Perform some account transactions
System.out.println("Withdraw 150.00: " + account.withdraw(150.00));
System.out.println("Deposit 22.50: " + account.deposit(22.50));
System.out.println("Withdraw 47.62: " + account.withdraw(47.62));
System.out.println("Withdraw 400.00: " + account.withdraw(400.00));
// Print out the final account balance
System.out.println("Customer [" + customer.getLastName() + ", " + customer.getFirstName()
+ "] has a balance of " + account.getBlance()); System.out.println(); // Test a Checking Account w/o overdraft protection
System.out
.println("Retrieving the customer Owen Bryant with his checking account with no overdraft protection.");
customer = bank.getCustomer(1);
account = customer.getAccount();
// Perform some account transactions
System.out.println("Withdraw 150.00: " + account.withdraw(150.00));
System.out.println("Deposit 22.50: " + account.deposit(22.50));
System.out.println("Withdraw 47.62: " + account.withdraw(47.62));
System.out.println("Withdraw 400.00: " + account.withdraw(400.00));
// Print out the final account balance
System.out.println("Customer [" + customer.getLastName() + ", " + customer.getFirstName()
+ "] has a balance of " + account.getBlance()); System.out.println(); // Test a Checking Account with overdraft protection
System.out
.println("Retrieving the customer Tim Soley with his checking account that has overdraft protection.");
customer = bank.getCustomer(2);
account = customer.getAccount();
// Perform some account transactions
System.out.println("Withdraw 150.00: " + account.withdraw(150.00));
System.out.println("Deposit 22.50: " + account.deposit(22.50));
System.out.println("Withdraw 47.62: " + account.withdraw(47.62));
System.out.println("Withdraw 400.00: " + account.withdraw(400.00));
// Print out the final account balance
System.out.println("Customer [" + customer.getLastName() + ", " + customer.getFirstName()
+ "] has a balance of " + account.getBlance()); System.out.println(); // Test a Checking Account with overdraft protection
System.out.println("Retrieving the customer Maria Soley with her joint checking account with husband Tim.");
customer = bank.getCustomer(3);
account = customer.getAccount();
// Perform some account transactions
System.out.println("Deposit 150.00: " + account.deposit(150.00));
System.out.println("Withdraw 750.00: " + account.withdraw(750.00));
// Print out the final account balance
System.out.println("Customer [" + customer.getLastName() + ", " + customer.getFirstName()
+ "] has a balance of " + account.getBlance());
}
} 输出结果:

Creating the customer Jane Smith.
Creating her Savings Account with a 500.00 balance and 3% interest.
Creating the customer Owen Bryant.
Creating his Checking Account with a 500.00 balance and no overdraft protection.
Creating the customer Tim Soley.
Creating his Checking Account with a 500.00 balance and 500.00 in overdraft protection.
Creating the customer Maria Soley.
Maria shares her Checking Account with her husband Tim.


Retrieving the customer Jane Smith with her savings account.
Withdraw 150.00: true
Deposit 22.50: true
Withdraw 47.62: true
余额不足
Withdraw 400.00: false
Customer [Simms, Jane] has a balance of 324.88


Retrieving the customer Owen Bryant with his checking account with no overdraft protection.
Withdraw 150.00: true
Deposit 22.50: true
Withdraw 47.62: true
额度不够
Withdraw 400.00: false
Customer [Bryant, Owner] has a balance of 324.88


Retrieving the customer Tim Soley with his checking account that has overdraft protection.
Withdraw 150.00: true
Deposit 22.50: true
Withdraw 47.62: true
Withdraw 400.00: true
Customer [Soley, Tim] has a balance of 0.0


Retrieving the customer Maria Soley with her joint checking account with husband Tim.
Deposit 150.00: true
额度不够
Withdraw 750.00: false
Customer [Soley, Maria] has a balance of 150.0

 

Bank5的更多相关文章

  1. esxi 5.1 由于断电错误无法启动 报错 bank5 invalid configuration

    由于着急,处理过程中也没有截图,这里简单的描写叙述下整个过程吧. IBM pcserver x3850 可能是机器太热的原因,中午无故掉电,导致esxi无法正常启动 启动时报错 bank5 inval ...

  2. S5PV210的内存分配研究分析

    S5PV210内存一般会使用SDRAM和DDR2 (DDR SDRAM),SDRAM的uboot启动网络已经有很多资料的,对于DDR2还有有很多疑惑,如果有错误的地方,请大家一定指出,醍醐灌顶,不胜感 ...

  3. (一)s3c2440 地址分配讲解 (很难很纠结)

    mini2440的地址怎么分配.mini2440处理器的地址怎么分配. S3C2440处理器可以使用的物理地址空间可以达到4GB,其中前1GB的地址(也就是0x0000 0000--0x4000 00 ...

  4. uboot在nandflash和norflash是如何运行的

    转自:http://www.aiuxian.com/article/p-2796357.html 电子产品如果没有了电,就跟废品没什么区别,是电赋予了他们生命,然而程序则是他们的灵魂. 小时候一直很好 ...

  5. mini2440裸机之MMU(二)(mmu.c) (转)

    分类: 嵌入式 http://blog.chinaunix.net/uid-26435987-id-3082166.html(转) /********************************* ...

  6. ARM--存储管理器

    初入领悟: 1. bank.L-bank的概念 2. s3c2440内部管理SDRAM寄存器配置 Frist part:原理分析 S3c2440为32位微处理器,其可访问空间为4G:但其中提供1G外设 ...

  7. arm汇编:ldr,str,ldm,stm,伪指令ldr

    ldr,str,ldm,stm的命名规律: 这几个指令命名看起来不易记住,现在找找规律. 指令 样本 效果 归纳名称解释 ldr Rd,addressing ldr r1,[r0] addressin ...

  8. CC2530存储空间——Code

    硬件平台:CC2530-F256 开发环境:IAR 8051(版本号 8.10) 參考: .<CC2530 User's Guide.pdf>(swru191c) .<IAR C/C ...

  9. 用jlink在mini2440上烧写uboot

    首先,附上我安装jlink驱动: http://download.csdn.net/detail/zzmno1/3776716#comment 以及我使用的uboot.bin文件下载地址: http: ...

随机推荐

  1. 前端——Vue CLI 3.x搭建Vue项目

    一.Node安装 windows 1. Node.js (>=8.9, 推荐8.11.0+) Node官网下载 .msi 文件,按步骤下载安装即可. 安装完之后在cmd中输入 node -v,若 ...

  2. HTML往div中赋值

    HTML中往div赋值 <div id="mazey">content</div> 使用JavaScript: var mazey=document.get ...

  3. 【mybatis】IF判断的坑

    http://cheng-xinwei.iteye.com/blog/2008200 最近在项目使用mybatis中碰到个问题 <if test="type=='y'"> ...

  4. AbstractList源码分析

    AbstractList 1 类图 2 字段 // 默认容量 private static final int DEFAULT_CAPACITY = 10; // 共享的空数组 private sta ...

  5. jQuery中操作属性的方法attr与prop的区别

    attr 与 prop 都可以对某个属性进行获取和设置的操作,二者的用法相同: <script src = 'jQuery.js'></script> <script&g ...

  6. 自定义IDOC

    目录 1需求场景    4 2配置发送端IDOC    4 2.1定义段(WE31)    4 2.2定义基本类型(WE30)    4 2.3定义消息类型(WE81)    5 2.4定义传输结构  ...

  7. python 基础应用1

    1.使用while循环输入1 2 3 4 5 6 8 9 10 n = 0 while n < 11: n = n + 1 if n == 7: continue print(n) n = 0 ...

  8. electron——通知

    所有三个操作系统都提供了应用程序向用户发送通知的手段. Electron允许开发者使用 HTML5 Notification API 发送通知,并使用当前运行的操作系统的本地通知 API 来显示它. ...

  9. Velocity中判断表达式是不是为空

    Velocity中判断表达式是不是为空 $if ($null.isNull($mycoll) || $mycoll.size()==0) ${}与$!{}区别 例子: ${str}:如果str没有值, ...

  10. jquery 扫码实现入库登记管理

    刚才跟一位分享的大神讲了关于项目中的需求,因为是第一次做这样的需求,还是蒙蒙的,现在把设计图给大家看看,大家有没有做过这样的需求业务,请多多指教!