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. ansible roles 自动化安装

    例:  ansible roles 自动化安装memcached 文件目录结构如下: cat memcached_role.yml - hosts: memcached remote_user: ro ...

  2. php扩展开发之hello world

    最近在公司做的事情就是php扩展开发,虽然我只负责c++代码的编写,但是了解扩展开发的流程还是很有必要的. (本文介绍的是动态扩展,对静态扩展有兴趣的读者可自行google) php扩展开发环境搭建可 ...

  3. D. Ehab the Xorcist(纯构造方法)

    \(如果觉得下面难以理解,可以去这里看一种较为简单的解法\):saf \(这个题嘛,首先要明确异或的性质:相同为0,不同为1.\) \(举个例子,我们来构造u=15和v=127的情况\) \(注意到, ...

  4. C. Barcode dp

    https://codeforces.com/problemset/problem/225/C 这个题目和之前一个题目很像 https://www.cnblogs.com/EchoZQN/p/1090 ...

  5. {bzoj2338 [HNOI2011]数矩形 && NBUT 1453 LeBlanc}平面内找最大矩形

    思路: 枚举3个点,计算第4个点并判断是否存在,复杂度为O(N3logN)或O(N3α) 考虑矩形的对角线,两条对角线可以构成一个矩形,它们的长度和中点必须完全一样,于是将所有线段按长度和中点排序,那 ...

  6. 【hdu5100】棋盘覆盖

    http://acm.hdu.edu.cn/showproblem.php?pid=5100 题目大意: 用1*k的木块铺n*n的棋盘,求多铺满多少个单位格. 方法: n < k,显然无解:n ...

  7. burpsuite抓包无法识别POST参数问题

    直接拿一道bugkuctf中的题目进行测试 这道题目就是用POST方法上传what=flag 我们利用burpsuite进制抓包 需要更改三个部分,这样就可以解决burpsuite无法识别POST参数 ...

  8. 散列表PTA判断

    1-1 在散列表中,所谓同义词就是具有相同散列地址的两个元素. (1分) T         F 作者 DS课程组 单位 浙江大学   1-2 采用平方探测冲突解决策略(h​i​​(k)=(H(k)+ ...

  9. Springboot Mybatis 打包jar扫描bean与mapper问题研究与解决

    SpringBootLean 是对springboot学习与研究项目,是根据实际项目的形式对进行配置与处理,欢迎star与fork. [oschina 地址] http://git.oschina.n ...

  10. es 报错cannot allocate because allocation is not permitted to any of the nodes

    0.现象 es 集群报red ,有unassigned shared , 用命令 curl localhost:9200/_cat/shards |grep UNASSIGNED 可以查看. 即使你马 ...