Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Object oriented programming if you know java then answer. i have a question and i got an answer, i am not sure this is

Java

Object oriented programming

if you know java then answer.

i have a question and i got an answer, i am not sure this is right or no, can you please modify it if needed. thank you.

question:

You should have a program that displays a menu in which you can make the following choices:

1- create an account (needs createAccount method (At least one holder, addHolder method can add other holers)

2- delete an account

3- modify account

4- find an account (through account number or a person's name) and display it

5- deposit into an account

6- Widthdraw from account

7- intereste earned for an account

8- exit

answer that i got.,,

1. Account.java

import java.util.Date;

public class Account {

private String accNo;

private String accountHolder;

private Double accountBalance = 0.0;

private Date accOpeningDate;

public void setAccOpeningDate(Date accOpeningDate){ this.accOpeningDate = accOpeningDate; }

public Date getAccOpeningDate(){ return accOpeningDate; }

public void setAccountHolder(String accountHolder) { this.accountHolder = accountHolder; }

public void setAccountNo(String accountNo) { this.accNo = accountNo; }

public String getAccountHolder() { return this.accountHolder; }

public String getAccNo() { return this.accNo; }

public Double getAccountBalance(){ return this.accountBalance; }

public void setAccountBalance(Double accountBalance) { this.accountBalance = accountBalance; }

@Override public String toString() { return "Account{" + "AccountId='" + accNo + '\'' + ", User ='" + accountHolder + '\'' + ", Balance='" + accountBalance + '\'' + ", Opened On='" + accOpeningDate + '\'' + '}'; } }

2. AccountUtility.java

/* This is the utility method where we have implemented all the functionalities required by the user.*/

import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.UUID;

public class AccountUtility {

private int intrestRate = 4; Map accountByUser = new HashMap<>(); Map accountByAccNo = new HashMap<>();

public Account createAccount(String user) { Account account = new Account(); account.setAccountHolder(user); account.setAccountNo(UUID.randomUUID().toString()); account.setAccOpeningDate(new Date()); accountByAccNo.put(account.getAccNo(), account); accountByUser.put(account.getAccountHolder(), account); return account; }

public Account findAccount(String finder) { if (accountByUser.get(finder) != null){ return accountByUser.get(finder); } else if (accountByAccNo.get(finder) != null) { return accountByAccNo.get(finder); } else return null; }

public Account findAccountByAccNo(String accNo) { return accountByAccNo.get(accNo); }

public void deleteAccount(String finder) { Account acc = null; if (accountByUser.get(finder) != null){ acc = accountByUser.get(finder); } else if (accountByAccNo.get(finder) != null){ acc=accountByAccNo.get(finder); } if (acc != null){ accountByAccNo.remove(acc.getAccNo()); accountByUser.remove(acc.getAccountHolder()); } }

public void updateAccount(Account updateAccount) { Account account = accountByAccNo.get(updateAccount.getAccNo()); accountByUser.remove(account.getAccountHolder(), account); accountByUser.put(updateAccount.getAccountHolder(), updateAccount); accountByAccNo.put(updateAccount.getAccNo(), updateAccount); }

public void addFunds(String finder, Double amount) { Account account = null; if (accountByUser.get(finder) != null) { account = accountByUser.get(finder); } else if (accountByAccNo.get(finder) != null){ account=accountByAccNo.get(finder); } account.setAccountBalance(account.getAccountBalance() + amount); accountByUser.put(account.getAccountHolder(), account); accountByAccNo.put(account.getAccNo(), account); }

public Double getEarnedIntrest(Account account) { Date date = account.getAccOpeningDate(); Date currDate = new Date(); int diffInDays = (int)(currDate.getTime() - date.getTime())/(1000*60*60*24); int month = currDate.getMonth() - date.getMonth(); Double balance = account.getAccountBalance(); Double intrest = balance*Math.pow(1+ intrestRate/(100.0 *12.0),(double)month); return intrest; }

public void withdrawFunds(String finder, Double amount) { Account account = null; if (accountByUser.get(finder) != null) { account = accountByUser.get(finder); } else if (accountByAccNo.get(finder) != null){ account=accountByAccNo.get(finder); } if (account.getAccountBalance() < amount) { System.out.println("Account balance insufficient"); return; } account.setAccountBalance(account.getAccountBalance() - amount); accountByUser.put(account.getAccountHolder(), account); accountByAccNo.put(account.getAccNo(), account); } }

3. Bank.java

/* THis is the main class where we are taking user input and doing all the operations */

import java.util.Date;

public class Account {

private String accNo;

private String accountHolder;

private Double accountBalance = 0.0;

private Date accOpeningDate;

public void setAccOpeningDate(Date accOpeningDate){ this.accOpeningDate = accOpeningDate; }

public Date getAccOpeningDate(){ return accOpeningDate; }

public void setAccountHolder(String accountHolder) { this.accountHolder = accountHolder; }

public void setAccountNo(String accountNo) { this.accNo = accountNo; }

public String getAccountHolder() { return this.accountHolder; }

public String getAccNo() { return this.accNo; }

public Double getAccountBalance(){ return this.accountBalance; }

public void setAccountBalance(Double accountBalance) { this.accountBalance = accountBalance; }

@Override public String toString() { return "Account{" + "AccountId='" + accNo + '\'' + ", User ='" + accountHolder + '\'' + ", Balance='" + accountBalance + '\'' + ", Opened On='" + accOpeningDate + '\'' + '}'; } }

please send me a copyable code, i promise to give you a thumbs up,if its right..

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Genetic Databases

Authors: Martin J. Bishop

1st Edition

ISBN: 0121016250, 978-0121016258

More Books

Students also viewed these Databases questions