⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 user.java

📁 java实现的取款机 前台为图形界面 后面数据用xml存储
💻 JAVA
字号:

package atm;
import java.util.*;
import java.io.*;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;
public class User implements Serializable 
{
     private String account;
     private int password;
     private int money;
     private List history =  new ArrayList();
     public User()
     {
 		password = 0;
 		money = 0;
     }
     
     public User(String acc,int pwd)
     {
 		this.account = acc;
 		this.password = pwd;
     }
     public User(String acc, int pwd, int money)
     {
    	 this.account = acc;
    	 this.password = pwd;
    	 this.money = money;
     }   
     
	 public List sqlHistory() throws InstantiationException, IllegalAccessException, ClassNotFoundException, IOException, JDOMException
	 {

		 SAXBuilder builder = new SAXBuilder();
		 history.clear();
		 Document read_doc = builder.build("history.xml");
		 Element stu = read_doc.getRootElement();
		 List list = stu.getChildren("history");
		 for(int i = 0;i < list.size();i++)
		 {
		    Element e = (Element)list.get(i);
	        String account = e.getChildText("mainaccount"); 
	        String date = e.getChildText("date");                      
	        String money = e.getChildText("money");
	        String type = e.getChildText("type");
	        String secaccount = e.getChildText("secaccount");
	        if(account.equals(this.account))
	          history.add(new History(account, secaccount, date, Integer.parseInt(money), type));
		 }
		 return history;
	}
	 
	public User load() throws IOException, ClassNotFoundException, JDOMException
	{
		SAXBuilder builder = new SAXBuilder();
	    Document read_doc = builder.build("user.xml");
	    Element stu = read_doc.getRootElement();
	    List list = stu.getChildren("user");
	    User user = null;
	    for(int i = 0;i < list.size();i++)
	    {
	         Element e = (Element)list.get(i);
	         String account = e.getChildText("account");          
	         String pwd = e.getChildText("pwd");                      
	         String money = e.getChildText("money");
	         if(account.equals(this.account))
	        	 return user = new User(account, Integer.parseInt(pwd), Integer.parseInt(money));
	    } 
	    return user;
		
	}	
	
    public   void  addHistory(String acc1, String acc2, String date, int money,String Type) throws IOException, ClassNotFoundException
	{
	     try 
	     {
	         new History(acc1, acc2, date, money,Type).addHistory();
		 } catch (JDOMException e) 
		 {
			e.printStackTrace();
		 } 
	}
    
	public void updateMoney() throws IOException, ClassNotFoundException, JDOMException
	{
		SAXBuilder builder = new SAXBuilder();
	    Document read_doc = builder.build("user.xml");
	    Element stu = read_doc.getRootElement();
	    List list = stu.getChildren("user");
	    for(int i = 0;i < list.size();i++)
	    {
	         Element e = (Element)list.get(i);
	         String account = e.getChildText("account");          
	         String pwd = e.getChildText("pwd");                      
	         if(account.equals(this.account))
	         {
	        	 e.getChild("money").setText(Integer.toString(this.money));
	         }
	         XMLOutputter outputter=new XMLOutputter();//保存Document的修改到XML文件中
	         outputter.output(read_doc,new FileOutputStream("user.xml"));	             
	    } 
	}

	public void setHistory(List history)
	{
	     this.history = history;
	}
	
    public void setMoney(int money)
    {
			this.money = money;
    }
	public void setPassword(int password)
	{
		this.password = password;
	}
	 
	public String getAccount()
	{
		return account;
	}
	
	public void setAccount(String account) 
	{
		this.account = account;
	}
	
	public List getHistory()
	{
		return history;
	}
	
	public int getMoney() 
	{
		return money;
	}
	
	public int getPassword() 
	{
		return password;
	}
   
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -