📄 command.java
字号:
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.ArrayList;
/**
* This class can be assume that it is the centralize of Bank system.
* After the BankSys class call this class, this class deals with validation of input by calling DataValidation class and
* reading from the file.
* Moreover, this class will call the Customer and Account class to do the Bank operation including NEW customer, OPEN account,
* DEPOSIT and WITHDRAW.
*/
public class Command {
private String inputCommand;
public static int maxOwner;
public static int maxAccount;
public static String accountFileName;
public static String customerFileName;
public static String transactionFileName;
/**
* This method calling FileProcessing class to read from BankSys.ini, Customer file, Account file and Transaction file.
* After done reading, it will set all value to appropriate variable.
*/
public void preProcess(){
ArrayList<Account> accountArrayList = new ArrayList<Account>();
ArrayList<Customer> customerArrayList = new ArrayList<Customer>();
ArrayList<Transaction> transactionArrayList= new ArrayList<Transaction>();
FileProcessing fileProcessingObject = new FileProcessing();
fileProcessingObject.preBankSysInI();
accountArrayList = fileProcessingObject.readAccountFromFile(accountArrayList, Command.accountFileName);
customerArrayList = fileProcessingObject.readCustomerFromFile(customerArrayList, Command.customerFileName);
transactionArrayList = fileProcessingObject.readTransactionFromFile(transactionArrayList, Command.transactionFileName);
readInput(accountArrayList, customerArrayList, transactionArrayList);
}
/**
* This method receive and validation all the input command.
* After validation, it will call the suitable method to do the operation.
* @param accountArrayList : ArrayList of Account class set after reading from account file and this ArrayList will be used entire system
* @param customerArrayList : ArrayList of Customer class set after reading from Customer file and this ArrayList will be used entire system
* @param transactionArrayList : ArrayList of Transaction class set after reading from Transaction file and this ArrayList will be used entire system
*/
public void readInput( ArrayList<Account> accountArrayList,
ArrayList<Customer> customerArrayList,
ArrayList<Transaction> transactionArrayList){
DataValidation checkInput = new DataValidation();
String delimiters = " ";
String command = "START";
System.out.println("OzBank system welcome............");
while (!(command.toUpperCase().equals("EXIT"))){
System.out.println("Please input your command:");
try{
Scanner keyboard = new Scanner(System.in);
inputCommand = keyboard.nextLine();
StringTokenizer commandFactory = new StringTokenizer(inputCommand, delimiters);
command = commandFactory.nextToken();
if (command.equalsIgnoreCase("NEW"))
{
try
{
checkInput.isCompleteCommand(inputCommand);
checkInput.checkForNewCustomer(inputCommand, customerArrayList);
newCustomer(commandFactory, customerArrayList);
}
catch(CommandException e)
{
System.out.print(e.getMessage());
}
}
else if(command.equalsIgnoreCase("OPEN_SAVING"))
{
try
{
checkInput.isCompleteCommand(inputCommand);
checkInput.checkForOpenAccount(inputCommand);
checkInput.checkBusinessRuleForOpenAccount(inputCommand, SavingAccount.minimumBalance, accountArrayList, customerArrayList);
openSavingAccount(commandFactory, accountArrayList, customerArrayList);
}
catch(CommandException e)
{
System.out.print(e.getMessage());
}
}
else if(command.equalsIgnoreCase("OPEN_CREDIT"))
{
try
{
checkInput.isCompleteCommand(inputCommand);
checkInput.checkForOpenAccount(inputCommand);
checkInput.checkBusinessRuleForOpenAccount(inputCommand, CreditAccount.creditLimit, accountArrayList, customerArrayList);
openCreditAccount(commandFactory,accountArrayList, customerArrayList);
}
catch(CommandException e)
{
System.out.print(e.getMessage());
}
}
else if(command.equalsIgnoreCase("OPEN_LOAN"))
{
try
{
checkInput.isCompleteCommand(inputCommand);
checkInput.checkForOpenLoanAccount(inputCommand);
checkInput.checkBusinessRuleForOpenAccount(inputCommand, LoanAccount.minimumLoanAmount, accountArrayList, customerArrayList);
openLoanAccount(commandFactory, accountArrayList, customerArrayList);
}
catch(CommandException e)
{
System.out.print(e.getMessage());
}
}
else if(command.equalsIgnoreCase("DEPOSIT"))
{
try
{
checkInput.isCompleteCommand(inputCommand);
checkInput.checkForDepositAccount(inputCommand, accountArrayList);
depositAccount(commandFactory, accountArrayList, transactionArrayList);//accountArray, accountArrayList, transactionArrayList);
}
catch(CommandException e)
{
System.out.print(e.getMessage());
}
}
else if(command.equalsIgnoreCase("WITHDRAW"))
{
try
{
checkInput.isCompleteCommand(inputCommand);
checkInput.checkForWithdrawAccount(inputCommand, accountArrayList);;
withdrawAccount(commandFactory, accountArrayList, transactionArrayList);//accountArray, accountArrayList, transactionArrayList);
}
catch(CommandException e)
{
System.out.print(e.getMessage());
}
}
else if(command.equalsIgnoreCase("BALANCE"))
{
try
{
checkInput.isCompleteCommand(inputCommand);
checkInput.checkForAccountBalance(inputCommand, accountArrayList);
accountBalance(commandFactory, accountArrayList);
}
catch(CommandException e)
{
System.out.print(e.getMessage());
}
}
else if(command.equalsIgnoreCase("TRANSACTIONS"))
{
try
{
checkInput.isCompleteCommand(inputCommand);
checkInput.checkForAccountTransaction(inputCommand, accountArrayList);
accountTransaction(commandFactory, accountArrayList);
}
catch(CommandException e)
{
System.out.print(e.getMessage());
}
}
else if(command.equalsIgnoreCase("CLOSE"))
{
try
{
checkInput.isCompleteCommand(inputCommand);
checkInput.checkForCloseAccount(inputCommand, accountArrayList);
closeAccount(commandFactory, accountArrayList);
}
catch(CommandException e)
{
System.out.print(e.getMessage());
}
}
else if(command.equalsIgnoreCase("EXIT"))
{
System.out.println("Exit bye.........");
}
else
{
System.out.println("ERROR COMMAND : No command found!!!");
}
}catch(NoSuchElementException e)
{
inputCommand = "NOTHING";
System.out.println("You have to input the command!!!!");
}
}
}
/**
* This method do create new customer
* @param commandFactory : The entire line of input command.
* @param customerArrayListObject : ArrayList of Customer class set after reading from Customer file.
*/
public void newCustomer(StringTokenizer commandFactory, ArrayList<Customer> customerArrayListObject){
int cusID = Integer.parseInt(commandFactory.nextToken());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -