Question
Design the following two classes: Account that contains: balance: double data field date: Date data field. Use Date class from the java.util package accountNumber: long
Design the following two classes:
Account that contains:
balance: double data field
date: Date data field. Use Date class from the java.util package
accountNumber: long data field. You should generate this value
randomly. The account number should be 9 digits long. You can use
the random method from java Math class.
annualInterestRate: double data field.
customer: customer data field. This is the other class that you will
have to design. See description below.
The accessor and mutator methods for balance, annualInterestRate,
date, and customer.
The accessor method for accountNumber.
A constructor that creates an account with the specified customer,
balance, and interest rate. Also, it should generate the account
number and the current date.
A method called getMonthlyInterestRate that returns the monthly
interest rate. Monthly Interest Rate is the annualInterestRate / 12.
A method called getMonthlyInterest that returns the monthly interest.
Monthly interest is the balance * monthlyInterestRate.
A method called generateAccountNumber that returns a 9 digit
number.
A method called deposit that takes a parameter of type double. This
method will add the value of the parameter to the balance. Make sure
not to accept any negative values.
A method called withdraw that takes a parameter of type double. This
method will subtract the value of the parameter from the balance.
Make sure not to accept any negative values or values greater than
existing balance.
Override toString method. This method should return all the
information about this account.
Customer class that contains:
firstName: String data field.
lastName: String data field
address: String data field
age: int data field
The accessor and mutator methods for firstName, lastName, age, and
address.
id: int data field. The first customer should have an id of 32000 and for
any new customer add 10.
Constructor that creates an customer with the specified first name,
last name, address, and age. Also, it should generate the customers
id.
Override toString method. This method should return all details about
this account (firstName, lastName, address, id, and age)
Override equals method. This method should return true if the calling
object is equal to the other object.
Write a test program that creates an BankAccount object. Make sure to test all the
methods in both the BankAccount and Customer objects.
Note: You dont have to use Scanner to read the users input. It suffice to hard code
the values in the driver. Also, make sure that all your mutator (setter) methods
validate the inputs
THIS IS A DRIVER
Driver:
What to turn in:
This time you have to turn in the whole project in a zip format.
First create a project and call it pa2
Add a package; call the package edu.century.pa2
Add the Driver, BankAccount, and Customer to edu.century.pa2 package
After you are done. Right click on the project name pa2 and generate a zip file. Call the zip file
pa2.zip.
You turn in the pa2.zip.
public
static
void
main(String[]
args
) {
double
balance
= 1330;
double
interestRate
= 4.5;
Customer
customer1
=
new
Customer(
"Sarah"
,
"Smith"
,
"319 grand ave"
, 24);
System.
out
.println(
"customer-1 toString: "
+
customer1
.toString());
Customer
customer2
=
new
Customer(
"John"
,
"Smith"
,
"12 nicollect"
, 34);
System.
out
.println(
"customer-2 toString: "
+
customer2
.toString());
BankAccount
account
=
new
BankAccount(
customer1
,
balance
,
interestRate
);
System.
out
.println(
"Current Balance: "
+
account
.getBalance());
account
.deposit(200);
System.
out
.println(
"Current Balance: "
+
account
.getBalance());
System.
out
.println(
"Account Number: "
+
account
.getAccountNumber());
System.
out
.println(
"Account Created date: "
+
account
.getDate());
System.
out
.println(
"Customer ID: "
+
account
.getCustomer().getId());
System.
out
.println(
"Monthly Inerest Rate: "
+
account
.getMonthlyInterestRate());
System.
out
.println(
"Monthly Interest: "
+
account
.getMonthlyInterest());
System.
out
.println(
"Current Balance: "
+
account
.getBalance());
account
.withdraw(300);
System.
out
.println(
"Monthly Interest: "
+
account
.getMonthlyInterest());
System.
out
.println(
"Account-1 toString output: "
+
account
.toString());
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started