Question: I have some errors in BankMain where I included Vector. Can you fix the errors so that Vector in BankAccount class can work in BankMain

I have some errors in BankMain where I included Vector. Can you fix the errors so that Vector in BankAccount class can work in BankMain class

import java.util.Scanner;

public class Person extends Date {

private String fName, lName, Address;

private int ssn;

//default constructor

public Person() {

//we call the default constructor of Date

super();

//set all private members to default values

fName = "unknown";

lName = "unknown";

Address = "unknown";

ssn = 0;

}

public Person (String dob, String fn, String ln, String addr, int s) {

super(dob);

fName = fn;

lName = ln;

Address = addr;

ssn = s;

}

//getters

public String getFName() {

return fName;

}

public String getLName() {

return lName;

}

public String getAddress() {

return Address;

}

public int getSSN() {

return ssn;

}

//setters

public void setFName(String n) {

fName = n;

}

public void setLName(String n) {

lName = n;

}

public void setAddress(String a){

Address = a;

}

public void setSSN(int n) {

ssn = n;

}

public void setDOB(String s){

this.setDate(s);

}

public void setDOB(int m, int d, int y){

String date = m+"/"+d+"/"+y;

this.setDate(date);

}

public String toString() {

String st = "DoB: " + super.toString() + ", SSN: " + ssn + ", First Name: "

+ fName + ", Last Name: " + lName + " Address: "+ Address;

return st;

}

public void read(Scanner in) {

System.out.println("Enter your birth day (mm/dd/yyyy):");

String d = in.nextLine();

this.setDate(d);

System.out.println("Enter SSN: " );

this.setSSN(in.nextInt());

this.setFName(in.nextLine());//the carriage return will be still inthe buffer

//nextLinen if invoked will read one character (carriage return) and return

//we need to empty the buffer before reading a string, we read a line for nothing

System.out.println("Enter first name: " );

this.setFName(in.nextLine());

System.out.println("Enter last name: " );

this.setLName(in.nextLine());

System.out.println("Enter address: " );

this.setAddress(in.nextLine());

}

}

//////////////////////////////////////////////

import java.util.Vector; public class BankAccount {

private Vector holder;

private double balance;

private double interestRate;

private Date openingdate;

private Date interestdateLPaid;

private Person person;

public BankAccount(double b, double i, Vector holders, Date o){

balance = b;

interestRate = i;

holder = holders;

openingdate = o;

interestdateLPaid = new Date();

}

public double getBalance() {

return balance;

}

public double getInterest() {

return interestRate;

}

public String getOpeningDate() {

return openingdate.toString();

}

public String getInterestDateLPaid(){

return interestdateLPaid.toString();

}

public VectorgetHolder(){

return holder;

}

public void setHolder(VectorinHolder) {

holder=inHolder;

}

public String getLastName(){

return person.getLName();

}

public int getSSN(){

return person.getSSN();

}

public void deposit(double amount){

balance = balance + amount;

}

public void withdraw(double amount){

balance = balance - amount;

}

public void addInterest(String d){

balance = balance + balance * interestRate;

interestdateLPaid = new Date(d);

}

public void setFName(String n){

person.setFName(n);

}

public void setLName(String n){

person.setLName(n);

}

public void setAddress(String a){

person.setAddress(a);

}

public void setSSN(int n){

person.setSSN(n);

}

public void setDOB(String s){

person.setDate(s);

}

public void setDOB(int m, int d, int y){

String date = m+"/"+d+"/"+y;

person.setDate(date);

}

public String toString(){

String st = "Bank Account Information: " +"Account Holder: " +person.toString() + " " +" Balance Amount: " + getBalance() +" Opening Date: " + getOpeningDate() +" Date Intrest was Last Added: " + getInterestDateLPaid()+"\1n";

return st;

}

}

////////////////////////////////////////////////////////////////////////////

import java.util.Scanner;

import java.util.*;

public class BankMain {

public static BankAccount getBankAccount(Vector bankAccounts){

Scanner sc = new Scanner(System.in);

boolean check = false;

int index = -1;

int option = 0;

while(!check)

{

System.out.println("Select an option down below to retrieve Bank Account info");

System.out.println("1. Retrieve Bank Account by SSN");

System.out.println("2. Retrieve Bank Account by Person's LastName");

option = sc.nextInt();

sc.nextLine();

if(option < 1 || option > 2){

System.out.println("Option not vaild! Try again.");

}

else{

check = true;

}

}

if(option == 1){

int ssn;

System.out.print("Enter SSN: ");

ssn = sc.nextInt();

for(int i=0; i< bankAccounts.size(); i++)

{

if(bankAccounts.get(i).getSSN() == ssn){

index = i;

}

}

}

else if(option == 2){

String lastName;

System.out.print("Enter Person's LastName: ");

lastName = sc.nextLine();

for(int i=0; i< bankAccounts.size(); i++){

if(bankAccounts.get(i).getLastName().equals(lastName)){

index = i;

}

}

}

if(index < 0){

return null;

}

else{

return bankAccounts.get(index);

}

}

public static void modifyAccount(BankAccount b)

{

Scanner sc = new Scanner(System.in);

boolean check = false;

int option = 0;

while(!check){

System.out.println("Please select an option down below...");

System.out.println("1. Deposit");

System.out.println("2. Withdraw");

System.out.println("3. Add Interest");

option = sc.nextInt();

if(option < 1 || option > 3){

System.out.println("Chosen option not vaild!");

}

else{

check = true;

}

}

if(option == 1){

double depositAmount;

System.out.print("Enter amount to deposit: ");

depositAmount = sc.nextDouble();

b.deposit(depositAmount);

System.out.println("Amount " + depositAmount + " was deposited in account ");

}

else if(option == 2){

double amountWithdrawn;

System.out.print("Enter amount to withdraw: ");

amountWithdrawn = sc.nextDouble();

if(amountWithdrawn > b.getBalance()){

System.out.println("Insufficient funds. Balance can't be withdrawn from!");

}else{

b.withdraw(amountWithdrawn);

System.out.println("Amount " + amountWithdrawn + " was withdrawn from account ");

}

}else if(option == 3){

String interestDate;

System.out.print("Enter date to add interest: ");

interestDate = sc.nextLine();

b.addInterest(interestDate);

System.out.println("Interest has been added to account ");

}

}

public static void main(String[] args) {

boolean go = true;

ArrayList bank = new ArrayList();

while(go){

System.out.println("Please select an option below...");

System.out.println("1. Create Bank Account");

System.out.println("2. Modify Bank Account");

System.out.println("3. Display Bank Account");

System.out.println("4. Delete Bank Account");

System.out.println("5. Exit");

Scanner sc = new Scanner(System.in);

boolean check = false;

int results = 0;

while(!check){

results = sc.nextInt();

sc.nextLine();

if(results < 1 || results > 5){

System.out.println("Menu number not vaild! Try again.");

}

else{

check = true;

}

}

if(results == 1){

Person p = new Person();

p.read(sc);

System.out.println("Enter Opening Balance: ");

double balance = sc.nextDouble();

sc.nextLine();

Date openingDate = new Date();

System.out.println("Enter Opening Date (mm/dd/yyyy):");

String d = sc.nextLine();

openingDate.setDate(d);

System.out.println("Enter Interest Rate: ");

double interest = sc.nextDouble();

sc.nextLine();

BankAccount bankAccount = new BankAccount(balance, interest, Vectorholders, openingDate);

bank.add(bankAccount);

System.out.println("Account was created for " + p.getFName() + " " + p.getLName());

}

else if(results == 2){

BankAccount b = getBankAccount(bank);

if(b.equals(null)){

System.out.print("No Bank Account found for given SSN/LastName!");

}

else{

modifyAccount(b);

}

}

else if(results == 3){

BankAccount b = getBankAccount(bank);

if(b.equals(null)){

System.out.print("Bank Account not found for given SSN/LastName!");

}

else{

System.out.println(b.toString());

}

}

else if(results == 4){

BankAccount b = getBankAccount(bank);

if(b.equals(null)){

System.out.print("Account not found for given SSN/LastName!");

}

else{

bank.remove(b);

System.out.print("Account deleted");

}

}

else if(results == 5){

go = false;

}

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!