java编写银行卡:包含属性卡号,密码和余额,要求卡号不能修改,密码修改需要提供?提倡独立完成作业Java编程银行代码,培养独立思考能力 。
思路Java编程银行代码:可以新建一个银行卡类BankCardJava编程银行代码,内部属性包含一个私有Java编程银行代码的不可变常量卡号cardNo,私有的可变量密码password,私有的可变量余额cardBalance 。
参考代码如下:(仅供参考)
用java编的银行账户系统代码package pack.money.persistent;import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;import pack.money.entity.Client;
import pack.money.entity.ClientMessage;
public class ClientPersistent {
//private static int a=0;
private static String t,b;//t是passwordb是clinetname
private static ClientPersistent sp;
public static ClientPersistent getClientPersistent() {
if (sp == null) {
sp = new ClientPersistent();
}
return sp;
}
private ClientMessage getClientMessage(ResultSet rs) throws Exception{
ClientMessage student=new ClientMessage();
student.setMoney(rs.getFloat("money"));
student.setType(rs.getString("type"));
student.setClientName(rs.getString("ClientName"));
student.setTransactionID(rs.getInt("TransactionID"));
return student;
}
public Client login(Connection con,String ClientName,String password) throws Exception{
String sql="select balance,password,ClientName from Client where ClientName=? and password=?";
PreparedStatement ps=con.prepareStatement(sql);
ps.setString(1, ClientName);
ps.setString(2, password);
ResultSet rs=ps.executeQuery();
t=password;
b=ClientName;
System.out.println(t);
System.out.println(b);
if(rs.next()){
Client client=new Client();
client.setClientName(rs.getString("ClientName"));
client.setPassword(rs.getString("password"));
return client;}
throw new Exception("Can not login, the accountID or password has error. ");
} public void save(Connection con ,String money)throws Exception
{// a++;
String s="save";
float g=Float.parseFloat(money);
String sql="update Client set balance=balance+? where ClientName=?";
String sql1="insert into ATMTransaction(ClientName,Type,money)values(?,?,?) ";
PreparedStatement ps=con.prepareStatement(sql);
PreparedStatement ps1=con.prepareStatement(sql1);
ps.setFloat(1, g);
ps.setString(2,b);
//ps1.setInt(1,a);
ps1.setString(1,b);
ps1.setString(2,s);
ps1.setFloat(3,g);
ps.executeUpdate();
ps1.executeUpdate();
}
public void withDraw (Connection con ,String money)throws Exception
{//a++;
String s="WithDraw";
【Java编程银行代码 银行java程序】float x=Float.parseFloat(money);
String sql="update Client set balance=balance-? where ClientName=?";
String sql1="insert into ATMTransaction(ClientName,Type,money) values(?,?,?)";
PreparedStatement ps=con.prepareStatement(sql);
PreparedStatement ps1=con.prepareStatement(sql1);
ps.setFloat(1, x);
ps.setString(2,b);
//ps1.setInt(1,a);
ps1.setString(1,b);
ps1.setString(2,s);
ps1.setFloat(3,x);
ps.executeUpdate();
ps1.executeUpdate();
}
public String changePassword(Connection con, String OldPassWord,String newPassWord1,String newPassWord2)
throws Exception
{
if(t.equals(OldPassWord))
{
if(newPassWord1.equals(newPassWord2))
{
String sql="update Client set password=? where ClientName=?";
PreparedStatement ps=con.prepareStatement(sql);
ps.setString(1, newPassWord1);
ps.setString(2,b);
ps.executeUpdate();
String j="dsfasdf";
return j;
推荐阅读
- 快手直播怎么结束的语音,快手直播间语音怎么关
- 包含ios音乐调速bpm软件的词条
- fc模拟器游戏机,fc模拟器 游戏
- 怎么看单机游戏的帧数,单机游戏怎么看fps
- mysql5.7怎么进入 mysql数据库如何进入
- 徐汇区erp系统电话号码,徐汇公司
- 怎样连接国外服务器教程,怎么连接外服服务器
- 模拟经营类的游戏电脑单机,模拟经营类游戏电脑单机版
- 鸿蒙系统有没有安卓的缺点,鸿蒙系统有没有安卓系统好