Question
Program #1 (25 points): Design and implement a Java class called Account. The class defines the following data fields and methods: 1. Private int data
Program #1 (25 points): Design and implement a Java class called Account. The class defines the following data fields and methods:
1. Private int data field named id to store the account ID (default value is 0).
2. Private double data field named balance to store the account balance (default value is 0.0).
3. Private double data field named annualInterestRate to store the interest rate (default value is 0.0%). Assume all accounts have same interest rate. Annual interest rate is percentage such as 3.2%, thus you need to divide by 100 to get double value 0.032).
4. Private Date data field named dateCreated to store the date when the account was created.
5. Non-argument constructor method that creates a default account (with default values).
6. Constructor method that creates an account with specified ID and initial balance.
7. Get and Set methods for variables id, balance, and annualInterestRate.
8. Get method for variable dateCreated.
9. Method named getMonthlyInterestRate() that returns the monthly interest rate (i.e., annualInterestRate / 12 , formatted as percentage (%)).
10. Method named getMonthlyInterest() that returns the earned monthly interest amount (i.e., balance * monthlyInterestRate, formatted as currency ($)).
11. Method named withdraw() that withdraws a specific amount from the account.
12. Method named deposit() that deposits a specific amount to the account.
Write a test program named TestAccount to create an account object named myObject as follows:
- Account ID is 123456; Initial balance is $10,000, annual interest rate is 2.5%.
- Withdraw $3,500
- Deposit $500
- Print out the account balance
- Print out the earned monthly interest
- Print out the date the account was created
Now, add method toString()to class Account to allow the user to printout a meaningful description of an account object using all of its instance variables. For example, the following statement in the test program
System.out.print(myObject);
on object myObject would display the account information as follows:
Account ID: 123456
Account Balance: $7,000.00
Interest Rate: 2.50%
Date Opened: Sun Nov 2 14:18:16 EDT 2017
Here is an example of toString()method: //----------------------------------------------------------------------------- // Returns a string representation of student object using name and studentID. //----------------------------------------------------------------------------- public String toString(){ // name and studentID are instance variables in class Student return ("The student name is " + name + ", and the ID is " + studentID); }
Now, modify the test program above to create 2 more account objects (say myAccount and yourAccount) with different initial balance values and different interest rates. Test all class methods on these 2 objects in logical order and display meaningful information after each method call.
Document your code, and organize and space the outputs properly. Use escape characters and formatting objects ($ and %) as needed.
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