In the programming language Java, need help with these three .java files. Account.java. No need to write a whole new set of codes just need help filling out the portion that says "Fill in the code",
Bank.javapublic class Bank {private final Map<String, Customer> customerMap;private final Map<String, Account> accountMap;private static Bank 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(String customerName, String customerId, Date registrationDate)throws BankException {/* Fill in the code and return the Customer. Exception if customerId already exists */return null;}public synchronized Customer lookupCustomer(String customerId)throws BankException {/* Fill in the code and return the Customer. Exception if customerId doesn't exist */return null;}public synchronized Account createAccount(String customerId, AccountType typeAccount,String accountId, Date openDate, int initialAmount)throws BankException {/* Fill in the code and return either a CheckingAccount or a SavingsAccount. Exception for any other AccountType */return null;}public synchronized Account lookupAccount(String accountId) {/* Fill in the code and return the Account. Exception if accountId doesn't exist */return null;}public synchronized void setJointOwner(String accountId, String primaryOwnerId,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(TransactionType transactionType, Date date, int amount,String customerId, String sourceAccountId,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, String accountId, Date openDate) { this.accountId = accountId; this.openDate = openDate; this.accountStatus = AccountStatus.Open; this.currentBalance = 0; this.transactionList = new ArrayList<>(); 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(Customer jointOwner, 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 transaction amount, - add the transaction to the transactionList - set the ending balance of the transaction as the account'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 if it is less than or equal to the current balance, otherwise change the description of the transaction - add the transaction to the transactionList - set the ending balance of the transaction as the account'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 and invoke the print method for each transaction */ }}
In the programming language Java, need help with these three .java files. Account.java. No need to write a whole new set
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am