Account:

package banking3;

//账户
public class Account {
private double balance;// 账户余额 public Account(double init_balance) {
balance = init_balance;
} public double getBlance() {
return balance;
} // 存钱
public boolean deposit(double amt) {// amt 要存的额度
balance += amt;
return true;
} // 取钱
public boolean withdraw(double amt) {// amt:要取得额度
if (balance >= amt) {
balance -= amt;
return true;
} else {
System.out.println("余额不足");
return false;
}
}
}

Customer:

package banking3;
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;
}
}

TestBanking3:

package TestBanking;

import banking3.Account;
import banking3.Customer; public class TestBanking3 {
public static void main(String[] args) {
Customer customer;
Account account; // Create an account that can has a 500.00 balance.
customer = new Customer("Jane", "Smith.");
account = new Account(500.00); System.out.println("Creating the customer Jane Smith.");
// code
customer.setAccount(account); System.out.println("Creating her account with a 500.00 balance."); // code
// 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());
}
} 输出结果:

Withdraw 47.62: true
余额不足
Withdraw 400.00: false
Customer [Smith., Jane] has a balance of 324.88


Bank3的更多相关文章

  1. BAYSY2 的LVDS引脚 笔记

    差分引脚标号说明: 'L' 代表该引脚属于差分引脚 'xx' 两位整型数,在每一 bank 的独特标记 'y' 表示正向 还是 反向,同时要注意输入输出方向 ‘#’ 0~3,代表 bank0~bank ...

  2. 【小梅哥FPGA进阶学习之旅】基于Altera FPGA 的DDR2+千兆以太网电路设计

    DDR2电路设计 在高速大数据的应用中,高速大容量缓存是必不可少的硬件.当前在FPGA系统中使用较为广泛的高速大容量存储器有经典速度较低的单数据速率的SDRAM存储器,以及速度较高的双速率DDR.DD ...

  3. ZYNQ学习之——MIO

    1.GPIO基础知识 Zynq7000 系列芯片有 54 个 MIO(multiuse I/O) ,它们分配在 GPIO 的 Bank0 和Bank1 隶属于 PS 部分, 这些 IO 与 PS 直接 ...

  4. 《Java核心技术卷一》笔记 多线程同步(底层实现)

    一.锁的基本原理 多个线程同时对共享的同一数据存取 ,在这种竞争条件下如果不进行同步很可能会造成数据的讹误. 例如:有一个共享变量int sum=0, 一个线程正调用 sum+=10,另一个线程正好也 ...

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

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

  6. 【转】Bootloader之uBoot简介(转)

    原文网址:http://blog.csdn.net/sadamoo/article/details/8139946 来自http://blog.ednchina.com/hhuwxf/1915416/ ...

  7. STM32F407 外扩SRAM

    字节控制功能.支持高/低字节控制. 看看实现 IS62WV51216 的访问,需要对 FSMC进行哪些配置. 这里就做一个概括性的讲解.步骤如下: 1)使能 FSMC 时钟,并配置 FSMC 相关的  ...

  8. stm32f10x.h文件分析理解

    今天再看过半年前自己写的这篇发现自己当时理解有误,stm32f10x.h与库开发并未存在太大关系,只是一个最为重要的寄存器地址到寄存器结构体变量的映射. stm32f10x.h 这个头文件是STM32 ...

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

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

随机推荐

  1. 一个poll的简单例子

    该程序使用poll事件机制实现了一个简单的消息回显的功能,其服务器端和客户端的代码如下所示: 服务器端: //start from the very beginning,and to create g ...

  2. python——append后的列表为什么打印出来为空

    关于python 列表append的用法: list = [] list = list.append("c") print(list) >>>None 正确写法应 ...

  3. Intersection of Two Linked Lists (求两个单链表的相交结点)

    题目描述: Write a program to find the node at which the intersection of two singly linked lists begins. ...

  4. IDEA编写快捷生成代码

    转载于:https://www.jianshu.com/p/029c2de5c612 1. psvm //生成main方法: public static void main(String[] args ...

  5. Web的Cookies,Session,Application

    Cookies:客户端(浏览器)存储信息的地方 Session:服务器的内置对象,可以在这里存储信息.按用户区分,每个客户端有一个特定的SessionID.存储时间按分钟计. Application: ...

  6. [hdu5316]线段树

    题意:给一个array,有两种操作,(1)修改某一个位置的值,(2)询问区间[L,R]内的最大子段和,其中子段需满足相邻两个数的位置的奇偶性不同 思路:假设对于询问操作没有奇偶性的限制,那么记录区间的 ...

  7. zookeeper和Eureka的区别

    RDBMS==>(MySql,Oracle,SqlServer等关系型数据库)遵循的原则是:ACID原则 A:Atomicity 原子性 C:Consistency 一致性 I:Isolatio ...

  8. Codeforces 1105D(Kilani and the Game,双队列bfs)

    AC代码: #include<bits/stdc++.h> #define ll long long #define endl '\n' #define mem(a,b) memset(a ...

  9. IP协议及其它的小弟 ,我保证没人会看的

    IP协议及其它的小弟 IP协议:127.0.0.1就一个32位的标识符.实际上: 类似这样的: 精神小伙慢慢看吧.我赌一包辣条你是不会认真看完的. IP协议的构成 地址解析协议 ARP 前面的叙述中我 ...

  10. gentoo 下安装lamp

    更新系统 emerge --sync emerge --update world 安装apache emerge www-servers/apache rc-update add apache2 de ...