java bank项目--精选文档

上传人:夏** 文档编号:471031522 上传时间:2023-12-27 格式:DOC 页数:30 大小:69KB
返回 下载 相关 举报
java bank项目--精选文档_第1页
第1页 / 共30页
java bank项目--精选文档_第2页
第2页 / 共30页
java bank项目--精选文档_第3页
第3页 / 共30页
java bank项目--精选文档_第4页
第4页 / 共30页
java bank项目--精选文档_第5页
第5页 / 共30页
点击查看更多>>
资源描述

《java bank项目--精选文档》由会员分享,可在线阅读,更多相关《java bank项目--精选文档(30页珍藏版)》请在金锄头文库上搜索。

1、Java 基础实战Bank 项目实验题目 1:创建一个简单的银行程序包实验目的:Java 语言中面向对象的封装性及构造器的创建和使用。实验说明:在这个练习里,创建一个简单版本的 Account 类。将这个源文件放入 banking 程序包中。在创建单个帐户的默认程序包中,已编写了一个测试程序 TestBanking。这个测试程序初始化帐户余额,并可执行几种简单的事物处理。最后,该测试程 序显示该帐户的最终余额。提示:1创建 banking 包2 在 banking 包下创建 Account 类。该类必须实现上述 UML 框图中的模型。a. 声明一个私有对象属性:balance,这个属性保留了银

2、行帐户的当前(或 即时)余额。b. 声明一个带有一个参数(init_balance)的公有构造器,这个参数为 balance 属性赋值。c. 声明一个公有方法 geBalance,该方法用于获取经常余额。d. 声明一个公有方法 deposit,该方法向当前余额增加金额。e. 声明一个公有方法 withdraw 从当前余额中减去金额。3打开TestBanking.java文件,按提示完成编写,并编译 TestBanking.java 文件。4 运行 TestBanking 类。可以看到下列输出结果:Creating an account with a 500.00 balanceWithdraw

3、 150.00Deposit 22.50Withdraw 47.62The account has a balance of 324.88/TestBanking.java 文件/* 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.*/package test;i

4、mport banking.*;public class TestBanking public static void main(String args) Account account; / Create an account that can has a 500.00 balance. System.out.println(Creating an account with a 500.00 balance.); /code System.out.println(Withdraw 150.00); /code System.out.println(Deposit 22.50); /code

5、System.out.println(Withdraw 47.62); /code / Print out the final account balance System.out.println(The account has a balance of + account.getBalance(); Java 基础实战Bank 项目实验题目 2:扩展银行项目,添加一个 Customer 类。Customer 类将包含一个 Account对象。实验目的:使用引用类型的成员变量。提 示:1. 在banking包下的创建Customer类。该类必须实现上面的UML图表中的模型。a. 声明三个私有对

6、象属性:firstName、lastName 和 account。b. 声明一个公有构造器,这个构造器带有两个代表对象属性的参数(f 和 l)c. 声明两个公有存取器来访问该对象属性,方法 getFirstName 和 getLastName 返回相应的属性。d. 声明 setAccount 方法来对 account 属性赋值。e. 声明 getAccount 方法以获取 account 属性。2. 在 exercise2 主目录里,编译运行这个 TestBanking 程序。应该看到如下输出结果:Creating the customer Jane Smith.Creating her ac

7、count with a 500.00 balance.Withdraw 150.00Deposit 22.50Withdraw 47.62Customer Smith, Jane has a balance of 324.88/TestBanking.java 文件/* 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 transact

8、ions with the Account object.*/import banking.*;public class TestBanking public static void main(String args) Customer customer; Account account; / Create an account that can has a 500.00 balance. System.out.println(Creating the customer Jane Smith.); /code System.out.println(Creating her account wi

9、th a 500.00 balance.); /code System.out.println(Withdraw 150.00); /code System.out.println(Deposit 22.50);/code System.out.println(Withdraw 47.62); /code / Print out the final account balance System.out.println(Customer + customer.getLastName() + , + customer.getFirstName() + has a balance of + acco

10、unt.getBalance(); Java 基础实战Bank 项目实验题目 3:修改 withdraw 方法以返回一个布尔值,指示交易是否成功。实验目的:使用有返回值的方法。提 示:1 修改 Account 类a. 修改 deposit 方法返回 true(意味所有存款是成功的)。b. 修改 withdraw 方法来检查提款数目是否大于余额。如果amt小于 balance, 则从余额中扣除提款数目并返回 true,否则余额不变返回 false。2 在 exercise3 主目录编译并运行 TestBanking 程序,将看到下列输出;Creating the customer Jane Sm

11、ith.Creating her account with a 500.00 balance. Withdraw 150.00: trueDeposit 22.50: true Withdraw 47.62: true Withdraw 400.00: falseCustomer Smith, Jane has a balance of 324.88/TestBanking.java 文件/* This class creates the program to test the banking classes.* It creates a new Bank, sets the Customer

12、 (with an initial balance),* and performs a series of transactions with the Account object.*/import banking.*;public class TestBanking public static void main(String args) Customer customer; Account account; / Create an account that can has a 500.00 balance. System.out.println(Creating the customer

13、Jane Smith.);/code 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.getBalance(); Java 基础实战Bank 项目实验题目 4:将用数组实现银行与客户间的多重关系。

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 资格认证/考试 > 人力资源管理师

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号