In the programming language Java, need help with these three.java files. Bank.java, Customer.java. No need to writea whole new set of codes just need help filling out the portionthat says "Fill in the code"
Bank.javapublic class Bank { private finalMap<String, Customer>customerMap; private finalMap<String, Account>accountMap; private staticBank bankInstance; private Bank() { customerMap = newHashMap<>(); accountMap = new HashMap<>(); } public static synchronized Bank getBankInstance(){ if (bankInstance == null){bankInstance = newBank(); } return bankInstance; } public synchronized Customer createCustomer(StringcustomerName, StringcustomerId, Date registrationDate) throws BankException{ /* Fill in the code andreturn the Customer. Exception if customerId already exists*/ return null; } public synchronized Customer lookupCustomer(StringcustomerId) throws BankException{/* Fill in the code andreturn the Customer. Exception if customerId doesn't exist*/ return null; } public synchronized Account createAccount(StringcustomerId, AccountTypetypeAccount,StringaccountId, DateopenDate, int initialAmount) throws BankException{/* Fill in the code andreturn either a CheckingAccount or a SavingsAccount. Exception forany other AccountType */ return null; } public synchronized Account lookupAccount(StringaccountId) {/* Fill in the code andreturn the Account. Exception if accountId doesn't exist*/ return null; } public synchronized void setJointOwner(StringaccountId, StringprimaryOwnerId,StringjointOwnerId, Date jointOwnershipDate){ Account account =this.lookupAccount(accountId); CustomerprimaryOwner =this.lookupCustomer(primaryOwnerId); CustomerjointOwner =this.lookupCustomer(jointOwnerId); if ((account !=null) && (primaryOwner != null) && (jointOwner !=null)) { if ((account.getPrimaryOwner() == primaryOwner) &&(account.getJointOwner() == null) ) { account.setJointOwner(jointOwner, jointOwnershipDate);} } } public synchronized voidcreateTransaction(TransactionTypetransactionType, Datedate, int amount,StringcustomerId, StringsourceAccountId,StringdestinationAccountId) {/* Fill in thecode - Based on thetransactionType, invoke makeDeposit(...), or makeWithdrawal(...),or makeTransfer(...) - ThedestinationAccountId is only applicable if this is a Transferrequest */ switch (transactionType) { case Deposit -> { break;} case Withdraw -> { break;} case Transfer -> { } } } private synchronized void makeDeposit(Datedate, intamount, StringcustomerId, String accountId) { Customer customer =this.lookupCustomer(customerId); Account account =this.lookupAccount(accountId); newDepositTransaction(date, amount, customer, account); } private synchronized void makeWithdrawal(Datedate, intamount, StringcustomerId, String accountId) { Customer customer =this.lookupCustomer(customerId); Account account =this.lookupAccount(accountId); if (account !=null && ((account.getPrimaryOwner() == customer) || (account.getJointOwner() != null &&account.getJointOwner() == customer)) ) { newWithdrawTransaction(date, amount, customer, account); } else newBankException("Customer is not owner or jointowner"); } private synchronized void makeTransfer(Datedate, intamount, StringcustomerId, StringfromAccountId, String toAccountId) { Customer customer =this.lookupCustomer(customerId); AccountfromAccount =this.lookupAccount(fromAccountId); Account toAccount= this.lookupAccount(toAccountId); if (fromAccount!= null && ((fromAccount.getPrimaryOwner() == customer) || (fromAccount.getJointOwner() != null&& fromAccount.getJointOwner() == customer)) ){ newTransferTransaction(date, amount, customer, fromAccount, toAccount); } else newBankException("Customer is not owner or jointowner"); } public synchronized void printStatement(StringcustomerId, Date toDate) { Customer customer =this.lookupCustomer(customerId); if (customer !=null) customer.printStatement(toDate); }}
Customer.java
public class Customer { private final String name; private final StringcustomerId; private final DateregistrationDate; private finalList<Account> accountList; public Customer(Stringname, StringcustomerId, Date registrationDate) { this.name =name; this.customerId =customerId;this.registrationDate =registrationDate; this.accountList= new ArrayList<>(); } public String getName() { returnthis.name; } public String getCustomerId() { returnthis.customerId; } public Date getRegistrationDate() { returnthis.registrationDate; } public void addAccount(Account account) { /* Fill in the code to addthe account to the customer's accountList */ } public void printStatement(Date toDate) { System.out.println("\nBEGINACCOUNT STATEMENT - " + this.getName() + " - " +DateFormat.getDateInstance().format(toDate)); /* Fill in the code to iterateover the customer's accountList and invoke printStatement for eachaccount */ System.out.println("\nENDACCOUNT STATEMENT\n"); }}
In the programming language Java, need help with these three .java files. Bank.java, Customer.java. No need to write a
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am