修改withdraw 方法
修改withdraw 方法
练习目标-使用有返回值的方法:在本练习里,将修改withdraw方法以返回一个布尔值来指示交易是否成功。

任务
1. 修改Account类
- 修改deposit 方法返回true(意味所有存款是成功的)。
- 修改withdraw方法来检查提款数目是否大于余额。如果amt小于balance,则从余额中扣除提款数目并返回true,否则余额不变返回false。
2. 在exercise2主目录编译并运行TestBanking程序,将看到下列输出;
Creating the customer Jane Smith.
Creating her account with a 500.00 balance.
Withdraw 150.00: true
Deposit 22.50: true
Withdraw 47.62: true
Withdraw 400.00: false
Customer [Smith, Jane] has a balance of 324.88
package banking; public class Account
{
//成员属性
private double balance ;//余额 // 无参构造
public Account()
{ }
// 有参构造
public Account(double balance)
{
this.balance = balance;
} // set get
public double getBalance()
{
return balance;
}
public void setBalance(double balance)
{
this.balance = balance;
} public boolean withdraw1( double amt )
{
if(amt>&&amt<balance==true)
{
balance -= amt ;
System.out.print("Withdraw " + amt+" : ");
return true ;
}
else
{
System.out.print("Withdraw " + amt+" : ");
return false ;
}
} public boolean deposit1( double amt )
{
if(amt<)
{
System.out.print("Deposit " + amt+" : " );
return false ;
}
else
{
balance += amt ;
System.out.print("Deposit " + amt +" : ");
return true ;
}
} }
Customer cr1 = new Customer( ) ;
cr1.setFirstName("Jane");
cr1.setLastName("Smith");
cr1.setBalance();
System.out.println("Creating the customer "+cr1.getFirstName() +" "+cr1.getLastName());
System.out.println("Creating her account with a " +cr1.getBalance()+" balance");
System.out.println(cr1.withdraw1() );
System.out.println(cr1.deposit1(22.5));
System.out.println(cr1.withdraw1(47.62));
System.out.println(cr1.withdraw1());
System.out.println("Customer "+cr1.getLastName()+" "+cr1.getFirstName()+
" has a balance of "+cr1.getBalance());

修改withdraw 方法的更多相关文章
- 练习3:修改withdraw 方法
练习目标-使用有返回值的方法:在本练习里,将修改withdraw方法以返回一个布尔值来指示交易是否成功. 任务 1.修改Account类 a.修改deposit 方法返回true(意味所有存款是成功的 ...
- 练习3:修改withdraw 方法 练习目标-使用有返回值的方法:在本练习里,将修改withdraw方法以返回一个布尔值来指示交易是否成功。
boolean withdraw(double get){ if(get<=balance) { System.out.println("取钱"+get+"元,当余 ...
- Spring Aop 修改目标方法参数和返回值
一.新建注解 @Target({ElementType.METHOD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Document ...
- Django的内置登录、退出、修改密码方法
Django中内置的登录.退出.修改密码方法. 1.url.py中使用django.contrib.auth中的views函数,django.views.generic中的TemplateView函数 ...
- ecshop2.73修改密码方法|ecshop2.73修改密码方法
ecshop2.73修改密码方法|ecshop2.73修改密码方法 ECSHOP教程/ ecshop教程网(www.ecshop119.com) 2012-09-09 ecshop2.73正式版后 ...
- JS高级. 06 缓存、分析解决递归斐波那契数列、jQuery缓存、沙箱、函数的四种调用方式、call和apply修改函数调用方法
缓存 cache 作用就是将一些常用的数据存储起来 提升性能 cdn //-----------------分析解决递归斐波那契数列<script> //定义一个缓存数组,存储已经计算出来 ...
- Mac修改hosts方法
总有各种各样的原因需要修改hosts文件,那么就来简介下怎么修改.terminal中打开hosts: sudo vim /private/etc/hosts 打开文件后I开启插入模式,在最后一行添加你 ...
- 【VS开发】VS2010 MFC中控件、对话框等背景颜色动态修改的方法
[VS开发]VS2010 MFC中控件.对话框等背景颜色动态修改的方法 标签(空格分隔):[VS开发] 声明:引用请注明出处http://blog.csdn.net/lg1259156776/ 说明: ...
- .net 4.0 以下HttpWebRequest Header 修改hosts方法
.net 4.0 以下HttpWebRequest Header 修改hosts方法 特此记录 public class CusteredHeaderCollection : WebHeaderCol ...
随机推荐
- 解决WP程序 重复打开出现 “正在加载...” 字样 解决方案
在开发winphone程序时候 我们经常遇到调试.在调试的时候 可能会重复打开 debug一下.可是有时候 经常遇到 "正在加载...."字样.而且很慢.效率很低. 测试发现 在 ...
- 大专生自学Python到找到工作的心得
先做个自我介绍,我13年考上一所很烂专科民办的学校,学的是生物专业,具体的学校名称我就不说出来献丑了.13年我就辍学了,我在那样的学校,一年学费要1万多,但是根本没有人学习,我实在看不到希望,我就退学 ...
- Ubuntu 安装有道词典
本系列文章由 @yhl_leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/51302546 官网首页:有道词典 其中 ...
- [繁华模拟赛]Evensgn 剪树枝
Evensgn 剪树枝 题目 繁华中学有一棵苹果树.苹果树有 n 个节点(也就是苹果),n − 1 条边(也就 是树枝).调皮的 Evensgn 爬到苹果树上.他发现这棵苹果树上的苹果有两种:一 种是 ...
- win7安装gmpy2
1.下载地址:https://pypi.python.org/pypi/gmpy2 2.安装python和pip python 安装 下载: https://www.python.org/getit/ ...
- shell面试题整理
1.给一个放有IP的文件,其中一个IP一行,统计哪个IP出现的次数最多. ip_input.txt内容如下: 219.217.49.14 175.43.4.87 87.48.98.1 59.73.38 ...
- [bzoj1103][POI2007]大都市meg_dfs序_树状数组
大都市meg bzoj-1103 POI-2007 题目大意:给定一颗n个点的树,m次操作.将一条路的边权更改成0:查询一个点到根节点的点权和.开始的时候所有边的边权都是1. 注释:$1\le n,m ...
- 3.0 - remote access 基础知识
RA概述: remote access: 广域网的远程连接,按L1分类: 1:通过电路交换网络实现的专线:(circuit switching) ~~~~~~~~~~~~~~~~~~~~~~~~~~~ ...
- [React Storybook] Get started with Storybook for React
Storybook is a UI component development environment for React, Vue, and Angular. With that, you can ...
- 使用OpenCV滑动条写成的简单调色器,实时输出RGB值
好久没有写博客了,近期在看OpenCV.于是动手写了个简单的RGB调色器,在终端实时输出RGB的值.通过这个程序学习滑动条的使用.程序中主要用到cvCreateTrackbar ,其使用方法例如以下: ...