Bank5
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的更多相关文章
- esxi 5.1 由于断电错误无法启动 报错 bank5 invalid configuration
由于着急,处理过程中也没有截图,这里简单的描写叙述下整个过程吧. IBM pcserver x3850 可能是机器太热的原因,中午无故掉电,导致esxi无法正常启动 启动时报错 bank5 inval ...
- S5PV210的内存分配研究分析
S5PV210内存一般会使用SDRAM和DDR2 (DDR SDRAM),SDRAM的uboot启动网络已经有很多资料的,对于DDR2还有有很多疑惑,如果有错误的地方,请大家一定指出,醍醐灌顶,不胜感 ...
- (一)s3c2440 地址分配讲解 (很难很纠结)
mini2440的地址怎么分配.mini2440处理器的地址怎么分配. S3C2440处理器可以使用的物理地址空间可以达到4GB,其中前1GB的地址(也就是0x0000 0000--0x4000 00 ...
- uboot在nandflash和norflash是如何运行的
转自:http://www.aiuxian.com/article/p-2796357.html 电子产品如果没有了电,就跟废品没什么区别,是电赋予了他们生命,然而程序则是他们的灵魂. 小时候一直很好 ...
- mini2440裸机之MMU(二)(mmu.c) (转)
分类: 嵌入式 http://blog.chinaunix.net/uid-26435987-id-3082166.html(转) /********************************* ...
- ARM--存储管理器
初入领悟: 1. bank.L-bank的概念 2. s3c2440内部管理SDRAM寄存器配置 Frist part:原理分析 S3c2440为32位微处理器,其可访问空间为4G:但其中提供1G外设 ...
- arm汇编:ldr,str,ldm,stm,伪指令ldr
ldr,str,ldm,stm的命名规律: 这几个指令命名看起来不易记住,现在找找规律. 指令 样本 效果 归纳名称解释 ldr Rd,addressing ldr r1,[r0] addressin ...
- CC2530存储空间——Code
硬件平台:CC2530-F256 开发环境:IAR 8051(版本号 8.10) 參考: .<CC2530 User's Guide.pdf>(swru191c) .<IAR C/C ...
- 用jlink在mini2440上烧写uboot
首先,附上我安装jlink驱动: http://download.csdn.net/detail/zzmno1/3776716#comment 以及我使用的uboot.bin文件下载地址: http: ...
随机推荐
- 深度优先搜索理论基础与实践(java)
概论 深度优先搜索属于图算法的一种,是一个针对图和树的遍历算法,英文缩写为 DFS 即 Depth First Search.深度优先搜索是图论中的经典算法,利用深度优先搜索算法可以产生目标图的相应拓 ...
- C++ 函数重载,函数模板和函数模板重载,选择哪一个?
重载解析 在C++中,对于函数重载.函数模板和函数模板重载,C++需要有一个良好的策略,去选择调用哪一个函数定义(尤其是多个参数时),这个过程称为重载解析. (这个过程将会非常复杂,但愿不要遇到一定要 ...
- Java——多线程锁的那些事
引入 Java提供了种类丰富的锁,每种锁因其特性的不同,在适当的场景下能够展现出非常高的效率. 下面先带大家来总体预览一下锁的分类图 1.乐观锁 VS 悲观锁 乐观锁与悲观锁是一种广义上的概念,体现了 ...
- K - Leapin' Lizards HDU - 2732 网络流
题目链接:https://vjudge.net/contest/299467#problem/K 这个题目从数据范围来看可以发现是网络流,怎么建图呢?这个其实不是特别难,主要是读题难. 这个建图就是把 ...
- spring的后台数据校验
数据校验对于开发项目来说是必须的.校验一般分为前台校验和后台校验,前台校验是必须要做的,后台校验是可选的.后台校验相对前台校验来说配置起来一般更复杂.前台校验通过js做,前台校验一般非常容易绕过.sp ...
- python学习之break和continue在for循环中的使用(案例:打印出10以内的偶数,并且只要前三个偶数)
运行程序,break是整个程序都跳出 continue则表示跳过当前一次循环,然后继续执行循环
- vue+.netcore可支持业务代码扩展的开发框架 VOL.Vue 2.0版本发布
框架介绍 这是一个基于vue.element-ui.iview..netcore3.1 可支持前端.后台动态扩展业务代码快速开发框架. 框架内置定制开发的代码生成器,生成的代码不需要复制也不需要更改, ...
- 【Kafka】Stream API
Stream API Kafka官方文档给了基本格式 http://kafka.apachecn.org/10/javadoc/index.html?org/apache/kafka/streams/ ...
- 【MySQL基础总结】索引的使用
索引的使用 概述 1.索引由数据库中一列或多列组合而成,其作用是提高对表中数据的查询速度 2.索引的优点是可以提高检索数据的速度 3.缺点是创建和维护索引需要耗费时间 4.所以索引可以提高查询速度,减 ...
- mybatis 新增返回id
第一种方式: 在实体类的映射文件 "*Mapper.xml" 这样写: <insert id="insertAndGetId" useGeneratedK ...