📄 command.java
字号:
String lName = commandFactory.nextToken();
String fName = commandFactory.nextToken();
String bDate = commandFactory.nextToken();
String email = commandFactory.nextToken();
String telNO = commandFactory.nextToken();
//Add new Customer object to the ArrayList
customerArrayListObject.add(new Customer(cusID,lName,fName,bDate,email,telNO));
FileProcessing fileProcessingObject = new FileProcessing();
//Write the ArrayList which has new object of Customer to Customer file.
fileProcessingObject.writeToFile(customerArrayListObject, Command.customerFileName);
}
/**
* This method do open new saving account.
* @param commandFactory : The entire line of input command.
* @param accountArrayListObject : ArrayList of Account class set after reading from Account file.
* @param customerArrayListObject : ArrayList of Customer class set after reading from Customer file.
*/
public void openSavingAccount( StringTokenizer commandFactory,
ArrayList<Account> accountArrayListObject,
ArrayList<Customer> customerArrayListObject){
int accNO = Integer.parseInt(commandFactory.nextToken());
double initAmt = Double.parseDouble(commandFactory.nextToken());
ArrayList<Customer> cusArrayListObj = new ArrayList<Customer>();
while(commandFactory.hasMoreTokens()){
int customerID = Integer.parseInt(commandFactory.nextToken());
//Add the owner to the ArrayList and then this ArrayList will be sent to the constructor of SavingAccount class
cusArrayListObj.add(getCustomerObject(customerID,customerArrayListObject));
}
//Add new SavingAccount object to the ArrayList
accountArrayListObject.add(new SavingAccount(accNO,initAmt,initAmt,cusArrayListObj));
FileProcessing fileProcessingObject = new FileProcessing();
//Write ArrayList which has new object of SavingAccount class to account file
fileProcessingObject.writeToFile(accountArrayListObject, Command.accountFileName);
}
/**
* This method do open new credit account.
* @param commandFactory : The entire line of input command.
* @param accountArrayListObject : ArrayList of Account class set after reading from Account file.
* @param customerArrayListObject : ArrayList of Customer class set after reading from Customer file.
*/
public void openCreditAccount( StringTokenizer commandFactory,
ArrayList<Account> accountArrayListObject,
ArrayList<Customer> customerArrayListObject){
int accNO = Integer.parseInt(commandFactory.nextToken());
double initAmt = Double.parseDouble(commandFactory.nextToken());
ArrayList<Customer> cusArrayListObj = new ArrayList<Customer>();
while(commandFactory.hasMoreTokens()){
int customerID = Integer.parseInt(commandFactory.nextToken());
//Add the owner to the ArrayList and then this ArrayList will be sent to the constructor of SavingAccount class
cusArrayListObj.add(getCustomerObject(customerID,customerArrayListObject));
}
//Add new CreditAccount object to the ArrayList
accountArrayListObject.add(new CreditAccount(accNO,initAmt,cusArrayListObj));
FileProcessing fileProcessingObject = new FileProcessing();
//Write ArrayList which has new object of CreditAccount class to account file
fileProcessingObject.writeToFile(accountArrayListObject, Command.accountFileName);
}
/**
* This method do open new loan account.
* @param commandFactory : The entire line of input command.
* @param accountArrayListObject : ArrayList of Account class set after reading from Account file.
* @param customerArrayListObject : ArrayList of Customer class set after reading from Customer file.
*/
public void openLoanAccount( StringTokenizer commandFactory,
ArrayList<Account> accountArrayListObject,
ArrayList<Customer> customerArrayListObject){
int accNO = Integer.parseInt(commandFactory.nextToken());
double initAmt = Double.parseDouble(commandFactory.nextToken());
double interest= Double.parseDouble(commandFactory.nextToken());
double noOfYear= Double.parseDouble(commandFactory.nextToken());
ArrayList<Customer> cusArrayListObj = new ArrayList<Customer>();
while(commandFactory.hasMoreTokens()){
int customerID = Integer.parseInt(commandFactory.nextToken());
//Add the owner to the ArrayList and then this ArrayList will be sent to the constructor of SavingAccount class
cusArrayListObj.add(getCustomerObject(customerID,customerArrayListObject));
}
//Add new LoanAccount object to the ArrayList
accountArrayListObject.add(new LoanAccount(accNO, initAmt, interest, noOfYear, cusArrayListObj));
FileProcessing fileProcessingObject = new FileProcessing();
//Write ArrayList which has new object of LoanAccount class to account file
fileProcessingObject.writeToFile(accountArrayListObject, Command.accountFileName);
}
/**
* This method do close the account by setting the status of account object to 'C'
* @param commandFactory : The entire line of input command.
* @param accountArrayListObject: ArrayList of Account class set after reading from Account file.
*/
public void closeAccount( StringTokenizer commandFactory,
ArrayList<Account> accountArrayListObject)
{
int accNO = Integer.parseInt(commandFactory.nextToken());
//Searching the position in the ArrayList of account object
int searchAccountResult = searchAccount(accNO,accountArrayListObject);
//Set account status to 'C'
accountArrayListObject.get(searchAccountResult).setStatus('C');
//Set account balance amount to 0.00
accountArrayListObject.get(searchAccountResult).setAccountBalance(0.00);
FileProcessing fileProcessingObject = new FileProcessing();
//Write ArrayList which has modified object of Account class to account file
fileProcessingObject.writeToFile(accountArrayListObject,Command.accountFileName);
}
/**
* This method do deposit operation
* @param commandFactory : The entire line of input command.
* @param accountArrayListObject : ArrayList of Account class set after reading from Account file.
* @param transactionArrayListObject: ArrayList of Transaction class set after reading from Transaction file.
*/
public void depositAccount( StringTokenizer commandFactory,
ArrayList<Account> accountArrayListObject,
ArrayList<Transaction> transactionArrayListObject){
int accNO = Integer.parseInt(commandFactory.nextToken());
double depositAmt = Double.parseDouble(commandFactory.nextToken());
//Searching the position in the ArrayList of account object
int searchAccountResult = searchAccount(accNO,accountArrayListObject);
accountArrayListObject.get(searchAccountResult).deposit(accNO, depositAmt, transactionArrayListObject);
FileProcessing fileProcessingObject = new FileProcessing();
//Write ArrayList which has modified object of Account class to account file
fileProcessingObject.writeToFile(accountArrayListObject,Command.accountFileName);
fileProcessingObject.writeToFile(transactionArrayListObject, Command.transactionFileName);
}
/**
* This method do withdraw operation
* @param commandFactory : The entire line of input command.
* @param accountArrayListObject : ArrayList of Account class set after reading from Account file.
* @param transactionArrayListObject: ArrayList of Transaction class set after reading from Transaction file.
*/
public void withdrawAccount(StringTokenizer commandFactory,
ArrayList<Account> accountArrayListObject,
ArrayList<Transaction> transactionArrayListObject)
{
int accNO = Integer.parseInt(commandFactory.nextToken());
double withdrawAmt = Double.parseDouble(commandFactory.nextToken());
//Searching the position in the ArrayList of account object
int searchAccountResult = searchAccount(accNO, accountArrayListObject);
accountArrayListObject.get(searchAccountResult).withdraw(accNO, withdrawAmt, transactionArrayListObject);
FileProcessing fileProcessingObject = new FileProcessing();
//Write ArrayList which has modified object of Account class to account file
fileProcessingObject.writeToFile(accountArrayListObject,Command.accountFileName);
fileProcessingObject.writeToFile(transactionArrayListObject, Command.transactionFileName);
}
/**
* This method do show transaction of account
* @param commandFactory : The entire line of input command.
* @param accountArrayListObject : ArrayList of Account class set after reading from Account file.
*/
public void accountTransaction( StringTokenizer commandFactory,
ArrayList<Account> accountArrayListObject)
{
int accNO = Integer.parseInt(commandFactory.nextToken());
//Searching the position in the ArrayList of account object
int searchAccountResult = searchAccount(accNO, accountArrayListObject);
//Call the transaction method in the Account calss
accountArrayListObject.get(searchAccountResult).transaction(accNO);
}
/**
* This method do show balance amount of account
* @param commandFactory : The entire line of input command.
* @param accountArrayListObject : ArrayList of Account class set after reading from Account file.
*/
public void accountBalance( StringTokenizer commandFactory,
ArrayList<Account> accountArrayListObject)
{
int accNO = Integer.parseInt(commandFactory.nextToken());
//Searching the position in the ArrayList of account object
int searchAccountResult = searchAccount(accNO, accountArrayListObject);
//Call the balace method in the Account calss
accountArrayListObject.get(searchAccountResult).balance(accNO);
}
/**
* This method try to find and return the postion of Customer object by searching through ArrayList of Customer class
* @param customerID : cutomer number or customer id --> four digit number
* @param customerArrayListObject : ArrayList of Customer class set after reading from Customer file.
* @return indexOf Customer object in the ArrayList.
*/
public Customer getCustomerObject(int customerID, ArrayList<Customer> customerArrayListObject){
for(Customer customer :customerArrayListObject){
if(customer.getCustomerID() == customerID){
return customerArrayListObject.get(customerArrayListObject.indexOf(customer));
}
}
return null;
}
/**
* This method try to find and return the position of Account Object by searching through ArrayList of Account class
* @param accountNumber : Account number of Account ID --> seven digit number.
* @param accountArrayListObject: ArrayList of Account class set after reading from Account file.
* @return indexOf Account object in the ArrayList.
*/
public int searchAccount( int accountNumber,
ArrayList<Account> accountArrayListObject){
for(Account account :accountArrayListObject){
if(account.getAccountNumber() == accountNumber){
return accountArrayListObject.indexOf(account);
}
}
return -1;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -