Object oriented programming java take your time no rush,, give me a accurate ans
ID: 3841650 • Letter: O
Question
Object oriented programming
java
take your time no rush,, give me a accurate answer please,,,
Bank project,,,
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
those 3 are my previous answer,,,,,,now i need the no. 4 part,, please do it for me pls,,,,
1.
import java.util.Calendar;
import java.util.Scanner;
public class Date {
private int day, month, year;
static int[] Days = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
public Date() {
//Today's date
Calendar cal = Calendar.getInstance();
day = cal.get(Calendar.DAY_OF_MONTH);
month = cal.get(Calendar.MONTH) + 1;
year = cal.get(Calendar.YEAR);
}
public Date(int d, int m, int y) {
day = d;
month = m;
year = y;
}
public Date(String d){
setDate(d);
}
//setDate
public void setDate(String d){
String [] datesp = d.split("[-/]");
month = Integer.parseInt(datesp[0]);
day = Integer.parseInt(datesp[1]);
year = Integer.parseInt(datesp[2]);
}
//copy constructor
public Date(Date d) {
day = d.day;
month = d.month;
year = d.year;
}
//copy constructor
//Accessors and Mutators
public int getDay() {
return day;
}
public int getMonth() {
return month;
}
public int getYear() {
return year;
}
public void setDay(int d) {
day = d;
}
public void setMonth(int m){
month = m;
}
public void setYear(int y){
year = y;
}
public String toString() {
String st = month+"/"+day+"/"+year;
return st;
}
public void display() {
System.out.println(toString());
}
public boolean isLarger(Date d) {
if (this.year > d.year)
return true;
else if (this.year == d.year) {
if (this.month > d.month)
return true;
else if (this.month == d.month){
if (this.day > d.day)
return true;
}
}
return false;
}
public boolean isLeap(int y) {
if ((y%4 == 0 && y%100!=0) || y%400 ==0)
return true;
return false;
}
public int DaysSinceBegin(Date d){
int sum = 0;
for (int i =0; i<d.month-1; i++){
sum += Days[i];
if (i ==1 && isLeap(d.year))
sum++;
}
sum += d.day;
return sum;
}
public int DaysSince(Date d) {
Date Largest, Smallest;
if (this.isLarger(d)){
Largest = this;
Smallest = d;
}else {
Largest = d;
Smallest = this;
}
int DaysSmall = DaysSinceBegin(Smallest);
int DaysLarge = DaysSinceBegin(Largest);
int sum = 0;
for (int i = Smallest.year; i < Largest.year; i++) {
if (isLeap(i))
sum += 366;
else
sum += 365;
}
sum = sum + DaysLarge - DaysSmall;
return sum;
}
//method that allows you to read the date from the keyboard
public void readDate(Scanner sc) {
System.out.println("Enter the date in form mm/dd/yyyy: ");
this.setDate(sc.nextLine());
}
}
2.
import java.util.Scanner;
public class DateTester {
public static void main(String[] args){
Date d = new Date();
Date l = new Date("02-22-2018");
d.display();
l.display();
System.out.println("Diff = " + d.DaysSince(l));
System.out.println("Rev Diff = " + l.DaysSince(d));
Person P = new Person();
P.display();
Scanner keyb = new Scanner(System.in);
P.readPerson(keyb);
P.display();
}
}
3.
import java.util.Scanner;
public class Person extends Date{
private String fName = "", lName="", Address="";
private int SSN = 0;
public Person() {
super();
fName = lName= Address="";
SSN = 0;
}
public Person(int S, String fn, String ln, String add, Date d) {
super(d);
SSN = S;
fName = fn;
lName = ln;
Address = add;
}
//DO the gets
//the sets
public void setSSN(int s) {
SSN = s;
}
//Read reads person fron keyboard
public void readPerson(Scanner sc) {
System.out.println("Enter DoB ");
super.readDate(sc);
System.out.println("Enter SSN: ");
SSN = sc.nextInt();
sc.nextLine();
System.out.println("Enter firstName: ");
fName = sc.nextLine();
System.out.println("Enter lastName: ");
lName = sc.nextLine();
System.out.println("Enter Address: ");
Address = sc.nextLine();
}
public String toString() {
String st = "DoB: " + super.toString() + " SSN: " + SSN
+ " First Name: " + fName + " Last Name: " + lName +
" Address: " + Address;
return st;
}
public void display() {
System.out.println(this.toString());
}
}
so i need to finish the project,, please answer me in a copyable answer,,, take yor tine... due is in 1 week from now,,,
Promise to give you thumbs up,, thank you,,,
Explanation / Answer
This are the files you will need to make to get this working. And please be more clear with problem statements becasue I had to make some assumptions. Thanks
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<String, Account> accountByUser = new HashMap<>();
Map<String, Account> 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 + ''' +
'}';
}
}
In this we have overriden the toString method to be able to print the complete object. This method is present in the top most class Object and is available to all the classes in Java.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.