关闭

简易银行系统

117人阅读 评论(0) 收藏 举报

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();
    }
  }
 } 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:192次
    • 积分:13
    • 等级:
    • 排名:千里之外
    • 原创:1篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章存档
    阅读排行
    评论排行