具体要求:
1.在MySQL数据库中建立名为bank的数据库,在bank库中建立银行储户表account存储储户信息。
2. 在eclipse下建立项目。
3.在上述你创建的项目内,针对account表编写实体类Account。
4. 编写数据访问接口AccountDao及其实现类AccountDaoImpl;业务接口AccountService及其实现类AccountServiceImpl。
实现以下业务需求:
1)储户开户功能,应输入cardID,姓名,密码,初次开户余额为交易额-10(卡费)。
2)储户根据cardID及password登录系统,只有账号和密码都正确才算登录成功,否则应给出“该储户不存在”或“密码错误”等提示。
3)成功登录系统后完成存款操作,存款成功后应提示“存款成功”!
4)成功登录系统后完成取款操作,当取款金额>账户余额时,应提示 “余额不足”。取款成功应提示“取款成功!”
5)成功登录系统后完成转账操作,转账给他人,应输入他人的cardID,如果账户id有误(不存在),应提示“该储户不存在!”;应保证你的转帐金额<=你的余额,注意两人账户余额的更新,转账成功后,应提示“你向XXX(账户姓名)成功转账XXX(具体金额)元”。
5.编写用户操作类AccountTest,可以给出具体的选项操作完成以上功能,如(1.开户2.存款3.取款4.转账5.退卡)。无论每个储户来银行办理什么具体业务,都首先应该欢迎,可打印“欢迎光临××银行”,当储户退卡离开,都应该表示欢迎其下次再来,可打印“感谢您的光临,欢迎您下次再来!”
import java.util.Scanner;
public class Account {
private int cardID;
private String name;
private String password;
private double balance=0;
private double many=0;
public int getCardID() {
return cardID;
}
public void setCardID(int cardID) {
this.cardID = cardID;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public double getMany() {
return many;
}
public void setMany(double many) {
this.many = many;
}
public Account() {
super();
// TODO Auto-generated constructor stub
}
public Account(int cardID, String name, String password, double balance) {
super();
this.cardID = cardID;
this.name = name;
this.password = password;
this.balance = balance;
}
}
import po.Account;
public interface AccountDao {
int addAccount(Account account); //开户
Account depositAccount(int cardID,double many); //存款
Account withdrawalAccount(int cardID,double many); //取款
Account transferAccount(int cardID,double many,int cardID2); //转账
Account foundAccount(int cardID); //用户查询
Account lookAccount(int cardID); //展示信息
}
package jnxyjsj.lyh.dao;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.mysql.jdbc.PreparedStatement;
import po.Account;
public class AccountDaoImpl implements AccountDao{
/*
* 对数据库增删改查的操作
* */
Connection con=null;
PreparedStatement psmt=null;
PreparedStatement psmt2=null;
PreparedStatement psmt3=null;
ResultSet rs=null;
/*
* 开户—————在数据库中增加用户
* */
@Override
public int addAccount(Account account) {
// TODO Auto-generated method stub
int i=0;
try {
con=DButil.getConnection();
String sql="insert into account(cardID,name,password,balance) values(?,?,?,-10)";
psmt=con.prepareStatement(sql);
psmt.setInt(1, account.getCardID());
psmt.setString(2, account.getName());
psmt.setString(3, account.getPassword());
i=psmt.executeUpdate();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally {
if(psmt!=null) {
try {
psmt.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(con!=null) {
try {
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
return i;
}
/*
* 存款操作,改变某一ID账号所对应的balance值
* */
@Override
public Account depositAccount(int cardID, double many) {
// TODO Auto-generated method stub
try {
con=D