📄 复件 bankusst.java
字号:
import java.io.*;
import java.util.Vector;
abstract class Account{
private String type;
private double balance;
private int accountNum;
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 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);
}
}
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();
}
}
}
class Transaction{
Account belongAccount;
Customer customerShow;
private double money;
private String type;
static Vector transactionVector=new Vector();
public void addTransactionVector(Transaction k){
transactionVector.addElement(k);
}
public double deposit(Account k,double num,Customer j){
k.deposit(num);
belongAccount=k;
customerShow=j;
money=num;
type="deposit";
return num;
}
public double withDrawal(Account k,double num,Customer j){
k.withDrawal(num);
belongAccount=k;
customerShow=j;
money=num;
type="withDrawal";
return num;
}
public void displayDetails(){
System.out.println("The operation's imformation is... Type:"+type+" num:"+money);
}
public void displayAll(){
this.customerShow.displayAll();
for (int i=0;i<transactionVector.size();i++){
Transaction transactionFromVector=(Transaction)transactionVector.elementAt(i);
transactionFromVector.displayDetails();
System.out.println("This operation belongs to account..."+transactionFromVector.belongAccount.getAccountNum());
}
}
}
public class BankUsst{
public static void main(String args[]){
int accountTest=1;
Customer cust1=null;
Account ac1=null;
Transaction ta1=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 Transaction();
ta1.deposit(ac1,100,cust1);ta1.addTransactionVector(ta1);
ac1.displayAccountDetails();
}
else if (choice==2){
ta1=new Transaction();
ta1.withDrawal(ac1,100,cust1);ta1.addTransactionVector(ta1);
ac1.displayAccountDetails();
}
else if (choice==3){
ta1.displayAll();
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 + -