python创建⼀个银⾏账户类account_银⾏账户(⽰例代码)Money 类
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.Outstand() + money);
System.out.println("您的余额:" + Outstand());
}
/**
* 取款,如果成功返回true,如果失败返回false
*
* @param money
* @return
*/
public boolean draw(double money) {
Money mon = new Money();
boolean result = false;
if (money > Outstand()) {
result = false;
} else {
mon.Outstand() - money);
result = true;
}
System.out.println("您的余额:" + Outstand()); 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 = Line();
if (str.equals("a")) {
System.out.println("请输⼊存款额:"); Scanner scan2 = new Scanner(System.in); s = Line();
count = Double.parseDouble(s);
bank.deposit(count);
} else if (str.equals("b")) {
System.out.println("请输⼊取款额:"); Scanner scan2 = new Scanner(System.in); s = Line();
count = Double.parseDouble(s);
bank.draw(count);
}else{
flag=false;
}
}
python新手代码示例}
public static void main(String args[]) { BankAccount bank = new BankAccount(); bank.list();
}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论