简易银行系统

来源:互联网 发布:淘宝手机大卖场 编辑:程序博客网 时间:2024/06/09 16:25

import java.io.*;
public class BankAccount
 {
 protected String Name;
 protected int Account;

 public BankAccount( String UserName, int UserAccount)
  {
   SetName(UserName);
   SetAccount(UserAccount);
  }

 public void SetName ( String UserName)
  {
   Name=UserName;
  }


 public void SetAccount( int UserAccount )
  {
   Account=UserAccount;
  }
 
 protected void Action() throws IOException
  {
   
  }
 }

import java.io.*;
import java.util.*;
public class Deposit extends BankAccount
{
 private int DepositNumber;
 File file;
 
 public Deposit(String UserName,int UserAccount,int UserNumber)
  {
   super(UserName,UserAccount);
   DepositNumber=UserNumber;

  }
 
 protected void Action() throws IOException
  {
   file = new File(Name);
   if (file.exists())
    {
     BufferedReader input=new BufferedReader(new FileReader(Name));
     String line;
     while ((line = input.readLine()) !=null)
      {
       StringTokenizer tokens = new StringTokenizer(line);
       SetAccount(Integer.parseInt(tokens.nextToken()));
      }
     input.close();
     PrintWriter output = new PrintWriter(new FileWriter(file));
     output.print(Account+DepositNumber);
     output.close();
    }
   else
    { 
     PrintWriter output = new PrintWriter(new FileWriter(file));
     output.print(DepositNumber);
     output.close();
    }
  }
}
      
    
     import java.io.*;
import javax.swing.JOptionPane;
import java.util.*;

public class WithDraw extends  BankAccount
 {
 private int WithDrawNumber;
 
 public WithDraw (String UserName,int UserAccount,int UserNumber)
  {
   super(UserName,UserAccount);
   WithDrawNumber=UserNumber;
  }
  
 protected void Action() throws IOException
  {
   BufferedReader input=new BufferedReader(new FileReader(Name));
     String line;
     while ((line = input.readLine()) !=null)
      {
       StringTokenizer tokens = new StringTokenizer(line);
       SetAccount(Integer.parseInt(tokens.nextToken()));
      }
     input.close();
     
   if (WithDrawNumber>Account)
    JOptionPane.showMessageDialog(null, "Not enough money!");
   else
    {
    PrintWriter output = new PrintWriter(new FileWriter(Name));
     output.print(Account-WithDrawNumber);
     output.close();
    }
  }
 } 

原创粉丝点击