Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Design a Java program that simulates bank accounts. Your main function should contain a menu to allow the user to create, modify, retrieve (display) and

Design a Java program that simulates bank accounts. Your main function should contain a menu to allow the user to create, modify, retrieve (display) and delete a bank account.

To modify/retrieve a bank account you need to enter either a last name or SSN.

You need to design a class for Date, a class for person, and a class for BankAccount. A Person inherites from date as each person has

a birth date, in addition to first name, last name, address and SSN.

A BankAccount has a maximum of three holders (person) and a balance, an interest rate, opening date, last date interest was payed. *Use vectors for holders*

A method to compute the interest.

The code for Date and Person is already completed down below.

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

public class Date {

private int day;

private int month;

private int year;

private static int[] Days = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

public Date() {

day = 1;

month = 1;

year = 1970;

}

public Date(int m, int d, int y) {

day = d;

month = m;

year = y;

}

public Date(String s) {

setDate(s);

}

public void setDate(String s) {

try {

if (s.contains("/")) {

// the format is mm/dd/yyyy

String[] result = s.split("/");

year = Integer.parseInt(result[2]);

setMonth(Integer.parseInt(result[0]));

setDay(Integer.parseInt(result[1]));

} else if (s.indexOf('-') > 0) {

String[] result = s.split("-");

year = Integer.parseInt(result[0]);

setMonth(Integer.parseInt(result[1]));

setDay(Integer.parseInt(result[2]));

} else

throw new Exception("Invalid date");

} catch (Exception e) {

System.out.println(e.getMessage());

}

}

public String toString() {

String st = month + "/" + day + "/" + year;

return st;

}

// getters

public int getDay() {

return day;

}

public int getMonth() {

return month;

}

public int getYear() {

return year;

}

// setters

public void setYear(int y) {

year = y;

}

public void setMonth(int m) {

try {

if (m < 1 || m > 12) {

throw new Exception("Invalid month");

}

month = m;

} catch (Exception e) {

System.out.println(e.getMessage());

}

}

public void setDay(int d) {

try {

if ((isLeap() && month == 2)) {

if (d < 1 || d > 29) {

throw new Exception("Invalid day, because of leap year");

}

day = d;

}

else{

if(d < 1 || d > Days[month]){

throw new Exception("Invalid day");

}

day = d;

}

} catch (Exception e) {

System.out.println(e.getMessage());

}

day = d;

}

public boolean isLeap() {

if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)

return true;

return false;

}

}

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

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());

}

}

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: 3

blur-text-image

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

Database Design And Implementation

Authors: Edward Sciore

2nd Edition

3030338355, 978-3030338350

Students also viewed these Databases questions