本文主要是介绍J2SE实战项目——信用卡管理系统,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
信用卡管理系统
前言:做是做好了,但是我可能没有完全弄明白项目需求,编程中计算也可能有不准确的地方~学完java基础,想实战的朋友不妨做下这个项目哦~然后看我的答案做参考,一起改进,欢迎讨论!~
项目整体需求:
具体项目需求请到下面链接下载:
链接: http://pan.baidu.com/s/1dD7TFxv 密码: 4ymd
链接: http://pan.baidu.com/s/1dD7TFxv 密码: 4ymd
编程思路:
·由于没有利用到数据库,肯定需要用到对象流,因此我认为需要写一个类用于读写对象。·另一个是计算,大家看文档知道:
总信用额=可用信用额+预存金额
public double getCreditTotal() {return creditable+this.creditPresent;//可用信用额+预存金额}
可取现金额=可用信用额/1.1
public double getCreditcash() {return this.creditable / 1.1;}
因此可取现金额和总信用额,都是和可用信用额挂钩的,我们需要在它们的geter里设置好这些计算公式。
public void setCreditable(double creditable) {i++;if (i == 1) {// 只有第一次才会赋值,其他情况不会?可以吗?this.creditini = creditable;}this.creditable = creditable;// 总信用额=可用信用额+预存金额this.creditTotal = creditable + this.creditPresent;// 可取现金额=可用信用额/1.1this.creditcash = creditable / 1.1;}
在账户信息类中注意有个属性是private double creditini;
这个属性是用来记录信用额最初的可用信用额的,第一次设置可用信用额之后,这个属性的值就不变化了,以后如果还款超过了这个值,就需要把超过的部分放到预存金额,不然的话,可用信用额可以很大(还款多的时候),这是不符合实际的吧~
利用geter中的代码:
i++;if (i == 1) {this.creditini = creditable;}
这样,在初始化一张信用卡之后,creditini这个属性就确定不变了(不知道还有什么方法可以做到?),以后判断如果可用信用额超过这个数字,就把超过的部分加到预存金额
·文档里给出的框架基本上够用了,但是用户登录一块,我们需要多加一个参数,把用户对象传进入,不然生成账单的时候,不知道是谁的。
·需要用对象流读写的类记得实现Serializable接口。
我认为的难点基本上就这些。
下面是所有代码和注释:
说明:三个包
一、lance.creditcardsys.data;放数据、数据操作类等
package lance.creditcardsys.data;
//账户信息类,用于存储账户的各种信息,每次生成一个账户信息类对象,都要放到List里面,然后把List写入磁盘
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;public class AccountVo implements Serializable {private String cardNo;private String passWord;private String userName;private String settlementDate;private double creditTotal;private double creditable;private double creditcash;private double creditower;private double creditPresent;private int state = 1;private double creditini;private int i = 0;public AccountVo() {super();}public AccountVo(String cardNo, String passWord, String userName,double creditable) {this.cardNo = cardNo;this.passWord = passWord;this.userName = userName;// 生成一个当前时间SimpleDateFormat simf = new SimpleDateFormat("yyyyMMddHHmmss");Date d = new Date();this.settlementDate = simf.format(d);setCreditable(creditable);}public double getCreditini() {return creditini;}public void setCreditini(double creditini) {this.creditini = creditini;}public String getCardNo() {return cardNo;}public void setCardNo(String cardNo) {this.cardNo = cardNo;}public String getPassWord() {return passWord;}public void setPassWord(String passWord) {this.passWord = passWord;}public String getUserName() {return userName;}public void setUserName(String userName) {this.userName = userName;}public String getSettlementDate() {return settlementDate;}public double getCreditTotal() {return creditable+this.creditPresent;}public void setCreditTotal(double creditTotal) {this.creditTotal = creditTotal;}public double getCreditable() {return creditable;}public void setCreditable(double creditable) {i++;if (i == 1) {// 只有第一次才会赋值,其他情况不会?可以吗?this.creditini = creditable;}this.creditable = creditable;// 总信用额=可用信用额+预存金额this.creditTotal = creditable + this.creditPresent;// 可取现金额=可用信用额/1.1this.creditcash = creditable / 1.1;}public double getCreditcash() {return this.creditable / 1.1;}public void setCreditcash(double creditcash) {this.creditcash = creditcash;}public double getCreditower() {return creditower;}public void setCreditower(double creditower) {this.creditower = creditower;}public double getCreditPresent() {return creditPresent;}public void setCreditPresent(double creditPresent) {this.creditPresent = creditPresent;}public int getState() {return state;}public void setState(int state) {this.state = state;}}
package lance.creditcardsys.data;
//账单类
import java.io.Serializable;public class BillVo implements Serializable {/*** 账单号 billNo String 账单号生成规律:P+日期+时+分+秒如P20101012112558 用户名 userName String* 账号 cardNo String 金额 value double 类型 type Int 1:为消费 2:还款 3:取现*/private String billNo;private String userName;private String cardNo;private double value;private int type;public BillVo() {super();}public BillVo(String billNo, String userName, String cardNo, double value,int type) {this.billNo = billNo;this.userName = userName;this.cardNo = cardNo;this.value = value;this.type = type;}public String getBillNo() {return billNo;}public void setBillNo(String billNo) {this.billNo = billNo;}public String getUserName() {return userName;}public void setUserName(String userName) {this.userName = userName;}public String getCardNo() {return cardNo;}public void setCardNo(String cardNo) {this.cardNo = cardNo;}public double getValue() {return value;}public void setValue(double value) {this.value = value;}public int getType() {return type;}public void setType(int type) {this.type = type;}
}
package lance.creditcardsys.data;/**这个类用于读取记录,保存记录* @author Lance*/
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Scanner;public class DataReaderWriter {String AVpath = "F:\\avlist.dat";String BVpath = "F:\\bvlist.dat";private Scanner input;/*** 读取账户信息的方法* * @return ArraryList*/@SuppressWarnings("unchecked")public ArrayList<AccountVo> readAvlist() {// 装账户信息的listArrayList<AccountVo> avlist = new ArrayList<AccountVo>();File file = new File(AVpath);// 如果有记录,则读取if (file.exists()) {try {FileInputStream fis = new FileInputStream(AVpath);ObjectInputStream ois = new ObjectInputStream(fis);// 包装好对象输入流avlist = (ArrayList<AccountVo>) ois.readObject();// 读取记录fis.close();ois.close();// 关闭对象流return avlist;} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace(
这篇关于J2SE实战项目——信用卡管理系统的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!