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. 一只简单的网络爬虫(基于linux C/C++)————socket相关及HTTP

    socket相关 建立连接 网络通信中少不了socket,该爬虫没有使用现成的一些库,而是自己封装了socket的相关操作,因为爬虫属于客户端,建立套接字和发起连接都封装在build_connect中 ...

  2. Android 讯飞语音听写SDK快速接入(附空指针解决和修改对话框文字方法)

    1.账号准备工作 首先要有一个讯飞的账号啦,为后面申请APPID.APPKey等东西做准备.顺带一提:讯飞对不同认证类型用户开 放的SDK的使用次数是有不同的,详情如下图. 账号申请完成后,需要去你自 ...

  3. B站弹幕系统架构——GOIM解读

    架构图 说明: 1.logic启动http服务器, 接受http请求,用于将数据推送到kafka以及获取在线用户信息,websocket身份校验 2.comet组件起动webdocket/tcp服务, ...

  4. python post protobuf

    本文主要讲述如何使用Python发送protobuf数据. 安装protobuf .tar.gz cd protobuf- ./configure make make install 安装成功. // ...

  5. Spring官网阅读(九)Spring中Bean的生命周期(上)

    文章目录 生命周期回调 1.Bean初始化回调 2.Bean销毁回调 3.配置默认的初始化及销毁方法 4.执行顺序 5.容器启动或停止回调 Lifecycle 接口 LifecycleProcesso ...

  6. kafka学习 之 简介

    文章目录 [Topics and Logs](http://kafka.apache.org/intro#intro_topics): Distribution: Producers: Consume ...

  7. Owin Katana 的底层源码分析

    最近看了一下开源项目asp.net katana,感觉公开的接口非常的简洁优雅,channel 9 说是受到node.js的启发设计的,Katana是一个比较老的项目,现在已经整合到asp.net c ...

  8. VMware Tanzu已融合云原生与K8s 市场前景尚不确定

    Tanzu是什么? Tanzu 结合了Wavefront IT监控的项目和产品,VMware于2017年5月收购了该软件,并加入了Cloud Foundry PaaS实用工具.VMware在2019年 ...

  9. onmouseenter,onmouseleave,onmouseover,onmouseout的区别

    首先,这四个事件两两配对使用,onmouseenter.onmouseleave一对,onmouseover.onmouseout一对,不能混合使用. onmouseenter 和 onmousele ...

  10. zsy后台管理系统-架构设计

    Zsy框架总体架构设计 1.Mysql数据库,存储所有表的数据. 2.Zsy-基础项目(Zsy-Model,Zsy-Dao,Zsy-Service,Zsy-Web),基于SSM框架.项目功能包含基本的 ...