python创建一个银行账户类account_银行账户(示例代码)

Money 类

import java.text.SimpleDateFormat;

public class Money {

private String accountNumber;// 账号

private String name;// 储户姓名

private SimpleDateFormat date;// 开户时间

private String ID;// 身份证号码

private static double outstand;// 存款余额

/**

* 空构造方法

*/

public Money() {

super();

// TODO Auto-generated constructor stub

}

public Money(String accountNumber, String name, SimpleDateFormat date,

String id) {

super();

this.accountNumber = accountNumber;

this.name = name;

this.date = date;

ID = id;

}

public String getAccountNumber() {

return accountNumber;

}

public void setAccountNumber(String accountNumber) {

this.accountNumber = accountNumber;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public SimpleDateFormat getDate() {

return date;

}

public void setDate(SimpleDateFormat date) {

this.date = date;

}

public String getID() {

return ID;

}

public void setID(String id) {

ID = id;

}

public double getOutstand() {

return outstand;

}

public void setOutstand(double outstand) {

Money.outstand = outstand;

}

}

操作类:BankAccount

package com.soft.hello.dao;

import java.util.Scanner;

import com.soft.hello.pojo.Money;

class BankAccount {

/**

* 存款

*

* @param money

*/

public void deposit(double money) {

Money mon = new Money();

mon.setOutstand(mon.getOutstand() + money);

System.out.println(“您的余额:” + mon.getOutstand());

}

/**

* 取款,如果成功返回true,如果失败返回false

*

* @param money

* @return

*/

public boolean draw(double money) {

Money mon = new Money();

boolean result = false;

if (money > mon.getOutstand()) {

result = false;

} else {

mon.setOutstand(mon.getOutstand() – money);

result = true;

}

System.out.println(“您的余额:” + mon.getOutstand());

return result;

}

/**

* pos菜单

*/

public void list() {

BankAccount bank = new BankAccount();

// 存款

boolean flag = true;

String s = null;

double count = 0;

while (flag) {

System.out.println(“请选择:a 为存款,b 为取款,exit 为退出”);

Scanner scan = new Scanner(System.in);

String str = scan.nextLine();

if (str.equals(“a”)) {

System.out.println(“请输入存款额:”);

Scanner scan2 = new Scanner(System.in);

s = scan2.nextLine();

count = Double.parseDouble(s);

bank.deposit(count);

} else if (str.equals(“b”)) {

System.out.println(“请输入取款额:”);

Scanner scan2 = new Scanner(System.in);

s = scan2.nextLine();

count = Double.parseDouble(s);

bank.draw(count);

}else{

flag=false;

}

}

}

public static void main(String args[]) {

BankAccount bank = new BankAccount();

bank.list();

}

}

    原文作者:weixin_39751195
    原文地址: https://blog.csdn.net/weixin_39751195/article/details/111442387
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞