中易网

急!!设计一个Java应用程序,模拟顾客到银行存取款的现象

答案:2  悬赏:30  
解决时间 2021-04-28 03:08
  • 提问者网友:北故人
  • 2021-04-27 17:25
银行运行模拟 1.1. 设计内容

    设计一个Java应用程序,模拟顾客到银行存取款的现象。

1.2. 设计要求

课程设计的要求应体现在课程设计的各个设计环节,学生应达到以下基本要求:

1)根据课题任务制定合理、可行的设计计划。

2)进行必要的课题任务调研、资料收集和文献阅读。

3)各课题小组的学生均应参与工程实现过程。

4)要提交工程文档。

1.3. 总体设计     1.3.1本系统开发环境

1)操作系统:win2k

2)编译器:j2sdk-1_4_1_02-windows-i586.exe

1.3.2 系统环境安装

1)安装编译环境

在OS上安装JDK(已安装过的计算机不再安装,版本不低于1.4)。在安装之前必须要有j2sdk-1_4_1_02-windows-i586.exe存在,这个软件在SUN的网站上可以下载。双击j2sdk-1_4_1_02-windows-i586.exe文件开始安装 ,在第一次选择画面单击NEXT,接下来的画面单击YES,第三个画面有一个Browse…按钮,在这里可以选择安装JDK的目录以及安装的目录名称,我们采用系统默认值。单击NEXT按钮进入下一个界面,在这个界面可以选择你所想要安装的组件和去掉你不想安装的组件,这里我们也采用系统的默认值。单击NEXT进入选择浏览器界面,默认的是选中Microsoft Internet Explorer,我们选种它,单击NEXT开始安装。最后单击Finish按钮完成JDK开发环境的安装。

1.3.3系统环境配置

在开发环境都安装好了以后,还有进行系统配置。根据上面安装信息,本系统配置如下:

打开系统设置,按Winkey+Break 或 右击“我的电脑”,选属性,选择高级->系统环境。在环境变量中我们分别添加或修改path、classpath、java_home三个变量,并给他们赋值。赋值如下:

l java_home=c:\j2sdk1.4.1_02 (安装路径)

l classpath=.;C:\j2sdk1.4.1_02\lib\tools.jar;C:\j2sdk1.4.1_02\lib

l 在path中添加C:\j2sdk1.4.1_02\bin

注解:classpath用于指明所有用于引用的类所在的目录,它允许用户把自己的类放在不同的目录中,但应该让JDK编译工具知道它们在那里。

在完成了上面的工作后,确定就可以了。为保证安装环境是否安装配置成功,进入DOS界面,输入javac或java,如果列出相应的命令使用帮助则安装配置成功。上面已经完成了系统环境的安装与配置,下面就要为本系统的运行做准备了。

1.3.4存储结构

整个应用程序具有以下存储结构:

     

其中TestBanking.java为给定的已知文件。banking目录下的5个文件需要你完成。

程序编译完成后,在work目录运行java TestBank,点击开始按钮后,应有如下结果:

1.4. 具体设计

参考UML图编程。

对每个类作如下说明:

1) Account类

a) 声明保护型属性: balance; 这个属性将保存当前账户余额

b) 声明构造器:初始化balance

c) 声明方法 getBalance :返回当前账户余额

d) 声明方法deposit:存钱到账户

e) 声明方法withdraw :从账户取钱 

2) CheckingAccount类(信用卡账户)

a) CheckingAccount 必须继承 Account 

b) 应含有double的属性overdraftProtection用于透支保护

c) 含有2个构造器,一个带1个参数,一个带2个参数。

     public CheckingAccount(double bal, double protect)

     public CheckingAccount(double bal)   //bal:初时账户余额,protect:透支额度

d) 类CheckingAccount必须覆盖父类withdraw 方法。实现以下功能:如果余额足够取,按正常方式取钱,否则将判断透支是否超过额度,超过不能取,没超过可以正常取钱。并返回boolean型变量。

3) SavingsAccount类(储蓄卡帐户)

a)SavingsAccount类为Account的子类 

b)属性interestRate为利率

c)含有两个参数的构造器,注意必需要调用父类的一个参数的构造器。

 public SavingsAccount(double bal, double rate) //bal:账户余额//rate 利率

4) Customer类

a) 声明四个属性: firstName, lastName,numberOfAccounts and accounts数组 

b) 声明2个参数的构造器 (f and l) 给属性赋初值 

c) declare two public accessors for the object attributes; these methods getFirstName and getLastName simply return the appropriate attribute 

d) 声明setAccount方法赋帐号 

e) 其余参考UML图 

5) Bank类   参考UML图

6)TestBanking类

import banking.*;

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.text.NumberFormat;

public class TestBanking extends Frame implements ActionListener{

      Button button ;

      TextArea text;

      Panel panel;

public TestBanking(String title){

       super(title);

       button = new Button("开始");

       button.________________;//为button添加动作事件监听

       text = new TextArea(10,20);

       panel = new Panel();

       panel.________________;//把button放到panel上

       this.add(________);//把panel放到frame北部区域

       this.add(text,BorderLayout.CENTER);

       this.setLocation(300,300);

   this.setSize(400,300);

   this.setVisible(true);

}

    public void actionPerformed(ActionEvent e) {

    NumberFormat currency_format = NumberFormat.getCurrencyInstance();

    Bank     bank = new Bank();

    Customer customer;

    bank.addCustomer("Jane", "Simms");

    customer = bank.getCustomer(0);

    customer.addAccount(new SavingsAccount(500.00, 0.05));

    customer.addAccount(new CheckingAccount(200.00, 400.00));

    bank.addCustomer("Owen", "Bryant");

    customer = bank.getCustomer(1);

    customer.addAccount(new CheckingAccount(200.00));

    bank.addCustomer("Tim", "Soley");

    customer = bank.getCustomer(2);

    customer.addAccount(new SavingsAccount(1500.00, 0.05));

    customer.addAccount(new CheckingAccount(200.00));

    bank.addCustomer("Maria", "Soley");

    customer = bank.getCustomer(3);

    // Maria and Tim have a shared checking account

    customer.addAccount(bank.getCustomer(2).getAccount(1));

    customer.addAccount(new SavingsAccount(150.00, 0.05));

    // Generate a report

    text.setText(text.getText()+"\t\t\tCUSTOMERS REPORT\n");

    text.setText(text.getText()+"\t\t\t===============");

    for ( int cust_idx = 0; cust_idx < bank.getNumOfCustomers(); cust_idx++ ) {

      customer = bank.getCustomer(cust_idx);

      text.setText(text.getText()+"\n");

      text.setText(text.getText()+"Customer: "

 + customer.getLastName() + ", "

 + customer.getFirstName());

      for ( int acct_idx = 0; acct_idx < customer.getNumOfAccounts(); acct_idx++ ) {

Account account = customer.getAccount(acct_idx);

String  account_type = "";

// Determine the account type

if ( account instanceof SavingsAccount ) {

  account_type = "Savings Account";

} else if ( account instanceof CheckingAccount ) {

  account_type = "Checking Account";

} else {

  account_type = "Unknown Account Type";

}

// Print the current balance of the account

text.setText(text.getText()+"\n    " + account_type + ": current balance is "

 + currency_format.format(account.getBalance()));

      }

    }

    }

     public static void main(String[] args) {

      TestBanking frame = new TestBanking("银行模拟");

      frame.setVisible(true);

  }

}

最佳答案
  • 二级知识专家网友:风格单纯
  • 2021-04-27 18:35

我有一个样例,设计的界面如下,里面的数据库环节没有进行添加.


界面之一运行如下图

全部回答
  • 1楼网友:说多了都是废话
  • 2021-04-27 18:55
那么,无耻地收分来了
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息