你要先學會截圖哦,你發(fā)的看不清楚,重新寫了一個你參考參考!

創(chuàng)新互聯公司專注于安康企業(yè)網站建設,成都響應式網站建設公司,成都做商城網站。安康網站建設公司,為安康等地區(qū)提供建站服務。全流程按需求定制設計,專業(yè)設計,全程項目跟蹤,創(chuàng)新互聯公司專業(yè)和態(tài)度為您提供的服務
import java.awt.GridLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
public class Day30A extends JFrame {
private static final long serialVersionUID = 1L;
private JLabel labelName,labelId,labelPass,labelMoney,labelSelect,labelCar;
private JComboBoxString jcb;
private JPanel jp1,jp2,jp3,jp4,jp5,jp6,jp7;
private ButtonGroup btg;
private JRadioButton jr1,jr2;
Day30A(){
this.setTitle("注冊賬戶");
this.setLayout(new GridLayout(7,1));
this.setSize(300,280);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
init();
this.setVisible(true);
}
private void init() {
String str="卡片類型1,卡片類型2,卡片類型3,卡片類型4,卡片類型5";
jcb=new JComboBox(str.split(","));
labelId=new JLabel("賬號: ");
labelName=new JLabel("姓名: ");
labelPass=new JLabel("密碼: ");
labelMoney=new JLabel("開戶金額:");
labelSelect=new JLabel("存款類型:");
labelCar=new JLabel("卡片類型:");
addFun1();
addFun2();
}
private void addFun2() {
this.add(jp1);
this.add(jp2);
this.add(jp3);
this.add(jp4);
this.add(jp5);
this.add(jp6);
this.add(jp7);
}
private void addFun1() {
jp1=new JPanel();
jp1.add(labelId);
jp1.add(new JTextField(15));
jp2=new JPanel();
jp2.add(labelName);
jp2.add(new JTextField(15));
jp3=new JPanel();
jp3.add(labelPass);
jp3.add(new JTextField(15));
jp4=new JPanel();
jp4.add(labelMoney);
jp4.add(new JTextField(13));
jp5=new JPanel();
jp5.add(labelSelect);
btg=new ButtonGroup();
jr1=new JRadioButton("定期");
jr2=new JRadioButton("活期",true);
btg.add(jr1);
btg.add(jr2);
jp5.add(jr1);
jp5.add(jr2);
jp6=new JPanel();
jp6.add(labelCar);
jp6.add(jcb);
jp7=new JPanel();
jp7.add(new JButton("確定"));
jp7.add(new JButton("取消"));
}
public static void main(String[] args) {
new Day30A();
}
}
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是password b是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";
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;
}
else
{System.out.print("確認密碼錯誤!");br return null;}
}
else
{ return null;
}
}
public ArrayListClientMessage disPlayAll(Connection con ) throws Exception
{
String sql="select * from ATMTransaction where ClientName=? ";
PreparedStatement ps=con.prepareStatement(sql);
ps.setString(1,b);
System.out.println(b+"****b****");
ResultSet rs=ps.executeQuery();
ArrayListClientMessage message=new ArrayListClientMessage();
while(rs.next()){
message.add(this.getClientMessage(rs));
}
return message;
}
public float showBalance(Connection con ) throws Exception
{
String sql="select balance from Client where ClientName=?";
PreparedStatement ps=con.prepareStatement(sql);
ps.setString(1, b);
ResultSet rs=ps.executeQuery();
if(rs.next())
{
float s;
s=rs.getFloat("balance");
return s;
}
else return 0 ;
}
}
分確實太少,不過看你是新手,就給你寫個吧。
import java.util.*;
public class Account
{
private String id; //帳號
private static double money; //總額
private double annualiInterestRate; //當前年利率
private Date riqi; //開戶日期
public Account()
{
}
//設置器和訪問器
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public double getAnnualiInterestRate() {
return annualiInterestRate;
}
public void setAnnualiInterestRate(double annualiInterestRate) {
this.annualiInterestRate = annualiInterestRate;
}
public Date getRiqi() {
return riqi;
}
public void setRiqi(Date riqi) {
this.riqi = riqi;
}
//幾個方法
public double getMonthlyInterestRate() //返回月利率
{
return annualiInterestRate/12;
}
public void withDraw(double temp) //從賬戶提取特定數額的款
{
money=money-temp; //取款后的余額
}
public void deposit(double info) //向帳戶中存入特定數額的款
{
money=money+info; //存款后的余額
}
public void show()
{
System.out.println("該帳戶余額為:"+money+",月利率為:"+this.getMonthlyInterestRate()+",開戶日期是:"+new Date());
}
public static void main(String[] args)
{
Account acc=new Account();
acc.setId("1122");
acc.money=20000.0;
acc.setAnnualiInterestRate(0.045);
acc.withDraw(2500.0);
acc.deposit(3000.0);
acc.show();
}
}
main方法不對啊
少了public
public static void main(String[] args) {}
這次是對的
文章標題:賬戶java代碼 java賬號
URL地址:http://chinadenli.net/article10/hepjgo.html
成都網站建設公司_創(chuàng)新互聯,為您提供微信小程序、營銷型網站建設、微信公眾號、靜態(tài)網站、商城網站、
聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯