您的位置:首页 > 其它

ATM系统实现[12]——抽象转户类[00原创]

2007-07-23 20:27 701 查看
package cn.edu.ynu.sei.atm.account;

import cn.edu.ynu.sei.atm.interfaceDef.IBankAccount;
import cn.edu.ynu.sei.atm.sqlManager.SqlStatementsManager;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.Calendar;
import java.util.GregorianCalendar;

/**
* 银行帐户抽象类
*
* @author 88250
*/
public abstract class BankAccount extends UnicastRemoteObject implements
IBankAccount
{
/**
* SQL语句管理器对象
*/
protected SqlStatementsManager sqlSM = SqlStatementsManager.getInstance();

/**
* 帐户帐号
*/
protected int accountID = 0;

/**
* 交易的总金额数
*/
protected float amount = 0;

/**
* 帐户结余
*/
protected float balance = 0;

/**
* 当天还可以取款金额数
*/
protected float remain = 0;

/**
* 交易时间
*/
protected String date = null;

/**
* 创建一个帐户实例
*
* @throws RemoteException
*/
public BankAccount() throws RemoteException
{
super();
balance = getBalance();
remain = getRemain();
}

/*
* (non-Javadoc)
*
* @see cn.edu.ynu.sei.atm.interfaceDef.IBankAccount#setRemain(float)
*/
public abstract void setRemain(float remain) throws RemoteException;

/*
* (non-Javadoc)
*
* @see cn.edu.ynu.sei.atm.interfaceDef.IBankAccount#getRemain()
*/
public abstract float getRemain() throws RemoteException;

/*
* (non-Javadoc)
*
* @see cn.edu.ynu.sei.atm.interfaceDef.IBankAccount#deposit(float)
*/
public void deposit(float amount) throws RemoteException
{

}

/*
* (non-Javadoc)
*
* @see cn.edu.ynu.sei.atm.interfaceDef.IBankAccount#withdraw(float)
*/
public void withdraw(float amount) throws RemoteException
{
// 生成取款时间
GregorianCalendar theTime = new GregorianCalendar();
date = formatTime(theTime.get(Calendar.YEAR), theTime
.get(Calendar.MONTH), theTime.get(Calendar.DAY_OF_MONTH),
theTime.get(Calendar.HOUR_OF_DAY),
theTime.get(Calendar.MINUTE), theTime.get(Calendar.SECOND));

// 设置当天还可以取款金额数
if (getLatedTime(accountID).substring(0, 10).equals(
date.substring(0, 10)))
{// 确定是在同一天
setRemain(getRemain() - getAmount());
}
else
{// 新一天的取款
setRemain(5000 - getAmount());
}
}

/*
* (non-Javadoc)
*
* @see cn.edu.ynu.sei.atm.interfaceDef.IBankAccount#getAmount()
*/
public float getAmount() throws RemoteException
{
return amount;
}

/*
* (non-Javadoc)
*
* @see cn.edu.ynu.sei.atm.interfaceDef.IBankAccount#setAmount(float)
*/
public void setAmount(float amount) throws RemoteException
{
this.amount = amount;
}

/*
* (non-Javadoc)
*
* @see cn.edu.ynu.sei.atm.interfaceDef.IBankAccount#setBalance(float)
*/
public abstract void setBalance(float balance) throws RemoteException;

/*
* (non-Javadoc)
*
* @see cn.edu.ynu.sei.atm.interfaceDef.IBankAccount#getBalance()
*/
public abstract float getBalance() throws RemoteException;

/*
* (non-Javadoc)
*
* @see cn.edu.ynu.sei.atm.interfaceDef.IBankAccount#setID(int)
*/
public void setID(int accountID) throws RemoteException
{
this.accountID = accountID;
}

/*
* (non-Javadoc)
*
* @see cn.edu.ynu.sei.atm.interfaceDef.IBankAccount#getID()
*/
public int getID() throws RemoteException
{
return accountID;
}

/*
* (non-Javadoc)
*
* @see cn.edu.ynu.sei.atm.interfaceDef.IBankAccount#getAccountType()
*/
public abstract String getAccountType() throws RemoteException;

/**
* 返回最近一次交易事务的时间
*
* @param accountID
* 帐户帐号
* @return 交易时间
*/
protected String getLatedTime(int accountID)
{
return sqlSM.getLatedTime(accountID);
}

/**
* 转化时间格式
*
* @param year
* 年
* @param month
* 月
* @param day
* 日
* @param hour
* 时
* @param minute
* 分
* @param second
* 秒
* @return 格式为yyyy-mm-dd hh:mm:ss的<code>String</code>
*/
public static String formatTime(int year, int month, int day, int hour,
int minute, int second)
{
String date = null;
if (month > 9)
{
date = Integer.toString(year) + "-" + Integer.toString(month) + "-"
+ Integer.toString(day) + " ";
}
else
{
date = Integer.toString(year) + "-0" + Integer.toString(month)
+ "-" + Integer.toString(day) + " ";
}
String time = Integer.toString(hour) + ":" + Integer.toString(minute)
+ ":" + Integer.toString(second);
return date + time;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: