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

📄 复件 (2) bankusst.java

📁 JAVA自编的银行管理程序。功能粗糙了点
💻 JAVA
字号:
import java.io.*;
import java.util.Vector;

abstract class Account{
	private String type;
	private double balance;
	private int accountNum;
	Vector transactions=new Vector();
	public Account(String i,double j,int k){
		type=i;
		balance=j;
		accountNum=k;
	}
	public double getBalance(){
		return balance;
	}
	public int getAccountNum(){
		return accountNum;
	}
	public String getType(){
		return type;
	}
	public void addTransaction(Transaction k){
		transactions.addElement(k);
	}
	public void setBalance(double num){
		balance=num;
	}
	public void deposit(double num){
		balance=balance+num;
	}
	public abstract void withDrawal(double num);
	public abstract void displayAccountDetails();
	public void displayAccount(){
		System.out.print("Account's info is... Type:"+type+" balance:"+balance+" accountNum:"+accountNum);
	}
	public void displayAllTransactions(){
		for (int i=0;i<transactions.size();i++){
		Transaction transactionFromVector=(Transaction)transactions.elementAt(i);
		transactionFromVector.displayDetails();}
	}
}

class CurrentAccount extends Account{
	private int creditLimit;
	public CurrentAccount(String i,double j,int k,int m){
		super(i,j,k);
		creditLimit=m;
	}
	public void displayAccountDetails(){
		super.displayAccount();
		System.out.println(" creditLimit:"+creditLimit);
	}
	public void withDrawal(double num){
		if (super.getBalance()-num>=creditLimit){
			super.setBalance(super.getBalance()-num);}
		else {System.out.println("Warning, you can't get any more money...");}
	}
}

class SavingAccount extends Account{
	private double interestRate;
	public SavingAccount(String i,double j,int k,double m){
		super(i,j,k);
		interestRate=m;
	}
	public void displayAccountDetails(){
		super.displayAccount();
		System.out.println(" interestRate:"+interestRate+" you got "+calInterestRate()+" interest");
	}
	public double calInterestRate(){
		double result;
		result=super.getBalance()*this.interestRate;
		return result;
	}
	public void withDrawal(double num){
		if (super.getBalance()-num>=0){
			super.setBalance(super.getBalance()-num);}
		else {System.out.println("Sorry, not enough money in your account...");}
	}
}

class Customer{
	private String name;
	private String address;
	Vector Accounts=new Vector();
	
	public Customer(String i,String j){
		name=i;
		address=j;
	}
	public void addAccount(Account k){
		Accounts.addElement(k);
	}
	public void displayAll(){
		System.out.println("Customer info is... name:"+name+" address:"+address);
		for (int i=0;i<Accounts.size();i++){
			Account accountFromVector=(Account)Accounts.elementAt(i);
			accountFromVector.displayAccountDetails();
			}
	}
}

abstract class Transaction{
	private Account belongAccount;
	private Customer customerShow;
	private double money;
	private String type;
	
	public Transaction(Account k,double num,Customer j,String m){
		belongAccount=k;
		money=num;
		customerShow=j;
		type=m;
	}
	public void displayDetails(){
		System.out.println("The operation's imformation is... Type:"+type+" num:"+money+" belongs to:"+this.belongAccount.getAccountNum());
	}
}

class depositTransaction extends Transaction{
	public depositTransaction(Account k,double num,Customer j){
		super(k,num,j,"deposit");
		k.deposit(num);
	}
}

class withDrawalTransaction extends Transaction{
	public withDrawalTransaction(Account k,double num,Customer j){
		super(k,num,j,"withDrawal");
		k.withDrawal(num);
	}
}

public class BankUsst{
	public static void main(String args[]){
		int accountTest=1;
		Customer cust1=null;
		Account ac1=null;
		Transaction ta1=null;Transaction ta2=null;
		cust1=new Customer("jocund","shanghai");
		for (int i=0;i<3;i++){
		System.out.println("What kind of Account you want to create...");
		System.out.println("1.Current Account     2.Saving Account");
		try{
			BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
			String choices=in.readLine();
			int choice=Integer.parseInt(choices);
			if (choice==1){
				ac1=new CurrentAccount("Current",0.0,accountTest,-100);accountTest++;
				cust1.addAccount(ac1);
				ac1.displayAccountDetails();
			}
			else if (choice==2){
				ac1=new SavingAccount("Saving",0.0,accountTest,0.23);accountTest++;
				cust1.addAccount(ac1);
				ac1.displayAccountDetails();
			}
			else{System.out.println("Error");}
			//start of the transaction;
			while (true){
				System.out.println("1.Save money...   2.WithDrawal money...   3.Exit...");
				choices=in.readLine();
				choice=Integer.parseInt(choices);
				if (choice==1){
					ta1=new depositTransaction(ac1,100,cust1);
					ac1.addTransaction(ta1);
					ac1.displayAccountDetails();
				}
				else if (choice==2){
					ta2=new withDrawalTransaction(ac1,100,cust1);
					ac1.addTransaction(ta2);
					ac1.displayAccountDetails();
				}
				else if (choice==3){
					ac1.displayAllTransactions();
					break;
				}}//end while
		}catch(Exception e){System.out.println(e.getMessage());}}//end for
		cust1.displayAll();
	}
}

⌨️ 快捷键说明

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