In the programming language Java, in need of help with these two.java files. Account.java. No need to write a whole new set ofcodes need help filling out the portion that says "Fill in thecode".
Bank.javapublic class Bank {private final Map<String, Customer>customerMap;private final Map<String, Account>accountMap;private staticBank bankInstance;private Bank() {customerMap = new HashMap<>();accountMap = new HashMap<>();}public static synchronized Bank getBankInstance() {if (bankInstance == null) {bankInstance = new Bank();}return bankInstance;}public synchronized Customer createCustomer(StringcustomerName, StringcustomerId, Date registrationDate)throws BankException {/* Fill in the code and return the Customer. Exception ifcustomerId already exists */return null;}public synchronized Customer lookupCustomer(StringcustomerId)throws BankException {/* Fill in the code and return the Customer. Exception ifcustomerId doesn't exist */return null;}public synchronized Account createAccount(StringcustomerId, AccountTypetypeAccount,String accountId, DateopenDate, int initialAmount)throws BankException {/* Fill in the code and return either a CheckingAccount ora SavingsAccount. Exception for any other AccountType*/return null;}public synchronized Account lookupAccount(String accountId) {/* Fill in the code and return the Account. Exception ifaccountId doesn't exist */return null;}public synchronized void setJointOwner(StringaccountId, StringprimaryOwnerId,String jointOwnerId, Date jointOwnershipDate){Account account =this.lookupAccount(accountId);Customer primaryOwner =this.lookupCustomer(primaryOwnerId);Customer jointOwner =this.lookupCustomer(jointOwnerId);if ((account != null) && (primaryOwner != null) &&(jointOwner != null)) {if ( (account.getPrimaryOwner() == primaryOwner) &&(account.getJointOwner() == null) ) {account.setJointOwner(jointOwner, jointOwnershipDate);}}}public synchronized void createTransaction(TransactionTypetransactionType, Datedate, int amount,String customerId, StringsourceAccountId,String destinationAccountId) {
Account.java
public abstract class Account {private final String accountId;private final Date openDate;private Date closeDate;private final Customer primaryOwner;private Customer jointOwner;private AccountStatus accountStatus;private Date jointOwnershipDate;private int currentBalance;private final List<Transaction>transactionList;public Account(Customer primaryOwner, StringaccountId, Date openDate) {this.accountId = accountId;this.openDate = openDate;this.accountStatus =AccountStatus.Open;this.currentBalance = 0;this.transactionList = newArrayList<>();this.primaryOwner = primaryOwner;primaryOwner.addAccount(this);}public Customer getPrimaryOwner() {return this.primaryOwner;}public String getAccountId() {return this.accountId;}public Date getOpenDate() {return this.openDate;}public AccountStatus getAccountStatus() {return this.accountStatus;}public int getCurrentBalance() {return this.currentBalance;}public void setJointOwner(CustomerjointOwner, Date jointOwnershipDate) {this.jointOwner = jointOwner;this.jointOwnershipDate =jointOwnershipDate;jointOwner.addAccount(this);}public Customer getJointOwner() {return this.jointOwner;}public Date getJointOwnershipDate() {return this.jointOwnershipDate;}protected synchronized void addTransaction(Transaction t) {if (this.accountStatus == AccountStatus.Close)throw new BankException("Account " + this.getAccountId() +"closed... Transaction not allowed");if (t instanceof DepositTransaction) {/* Fill in the code- invoke the deposit method with the transactionamount,- add the transaction to the transactionList- set the ending balance of the transaction as theaccount's current balance- invoke the transaction's print method*/} else if (t instanceof WithdrawTransaction) {/* Fill in the code- invoke the withdraw method with the transaction amount ifit is less than or equal to the current balance, otherwise changethe description of the transaction- add the transaction to the transactionList- set the ending balance of the transaction as theaccount's current balance- invoke the transaction's print method*/} else if (t instanceof TransferTransaction) {TransferTransaction tr = (TransferTransaction)t;if (tr.getToAccount().accountStatus ==AccountStatus.Close)throw new BankException("Account " + this.getAccountId() + "closed... Transaction not allowed");tr.setDescription("Transfer from " + this.getAccountId() + " to " +tr.getToAccount().getAccountId());this.transactionList.add(tr);tr.getToAccount().transactionList.add(tr);tr.print(null);}}private synchronized void deposit(int amount) {this.currentBalance += amount;}private synchronized void withdraw(int amount) {this.currentBalance -= amount;}public synchronized void closeAccount(Date closeDate) {this.accountStatus =AccountStatus.Close;this.closeDate = closeDate;}public void printStatement(Date toDate) {System.out.println("\n\tTransactions for Account " +this.accountId + " Primary Owner: " + this.primaryOwner.getName() +"\n");/* Fill in the code to iterate over the transactionList andinvoke the print method for each transaction */}}
In the programming language Java, in need of help with these two .java files. Account.java. No need to write a whole new
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am