java银行项目_javabank项目

《javabank项目》由会员分享,可在线阅读,更多相关《javabank项目(64页珍藏版)》请在人人文库网上搜索。

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.);/codeSystem.out.println(Withdraw 150.00);/codeSystem.out.println(Deposit 22.50);/codeSystem.o。

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

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

7、 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 transactions with th。

8、e 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.);/codeSystem.out.println(Creating her account with a 500.00 balan。

9、ce.);/codeSystem.out.println(Withdraw 150.00);/codeSystem.out.println(Deposit 22.50);/codeSystem.out.println(Withdraw 47.62);/code/ Print out the final account balanceSystem.out.println(Customer + customer.getLastName()+ , + customer.getFirstName()+ has a balance of + account.getBalance();Java 基础实战B。

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

11、h 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 (with an initial balance),*。

12、 and

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,这是一个简单的 Java 银行存款取款项目的代码: ```java import java.util.Scanner; public class Bank { private static double balance = 0; public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int choice; do { System.out.println("1. 存款"); System.out.println("2. 取款"); System.out.println("3. 查看余额"); System.out.println("0. 退出"); System.out.print("请选择操作:"); choice = scanner.nextInt(); switch (choice) { case 1: System.out.print("请输入存款金额:"); double deposit = scanner.nextDouble(); balance += deposit; System.out.printf("存款成功,当前余额为 %.2f 元。\n", balance); break; case 2: System.out.print("请输入取款金额:"); double withdraw = scanner.nextDouble(); if (withdraw > balance) { System.out.println("余额不足,取款失败。"); } else { balance -= withdraw; System.out.printf("取款成功,当前余额为 %.2f 元。\n", balance); } break; case 3: System.out.printf("当前余额为 %.2f 元。\n", balance); break; case 0: System.out.println("感谢使用,再见!"); break; default: System.out.println("无效的选择,请重新输入。"); } System.out.println(); } while (choice != 0); } } ``` 在这个银行项目中,我们使用了一个 `balance` 变量来保存用户的余额。在 `main` 方法中,我们使用了一个 `do-while` 循环来让用户选择存款、取款、查看余额或退出程序。根据用户的选择,我们执行不同的操作,例如存款会增加余额,取款会减少余额,查看余额则只是显示余额而已。 这只是一个简单的示例,实际上银行系统的设计会更加复杂,需要考虑更多的因素,例如账户认证、安全性、交易记录等等。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值