JavaDeploy
SiteMap
Readers Writers
Java Streams
Java Programming
Java Language
Java Fundamentals
«Prev
Next»
Java Programming
Java Technology
Useful Technology
Acquiring Java SDK
Java Compiler
Tic Tac Toe Applet
Java Applet Viewer
Java TM Interpreter
Java SDK Conclusion
OO Programming
OO Fundamentals
Understanding Classes
Object Communication
Defining Objects
Adding Behavior Methods
OO Programming Conclusion
OO Programming - Quiz
122
Java Programs
Java Api
Applications Applets
Java main() method
Static Class Member
Command Line Arguments
Building String Characters
Standard IO Communication
Application Construction
122
Program Flow
Conditional Branching
Conditional Ternary Operator
Switch Statement
For Loops
foreach Loop
Nested Loops
while Loops
doWhile Loop
Break Statement
Control Flow Conclusion
Programming Fundamentals
Identifiers, Keywords, Literals
Java Comments
Java Data Types
Storing Data Arrays
Manipulating Text
Evaluating Expressions
Numeric Operators
Boolean Assignment Operators
Compound Operators
Java Language Conclusion
Object Classes
Inheritance Fundamentals
Overriding Methods - Exercise
Objective:
Override a method and write a test program to invoke the overridden method.
Exercise Grading
The full credit for this exercise is 10 points. To receive full credit, you will need to successfully create the source code for the class and test program. You will submit your source code on this page.
Exercise Instructions
Write the source code for a class
AccountWithFee
that is derived from the
Account
class which you built previously in this module. The
AccountWithFee
class models an investment account that includes a monthly management fee. You should add an instance variable named
fee
that reflects the monthly fee charged to the account. You should then override both of the
compound()
methods to subtract the monthly fee when calculating the new balance.
Modify the test program,
AccountTest
, to create both an
Account
object and an
AccountWithFee
object. Set the values of the instance variables
balance
and
rate
to 1000.0 and 0.09 respectively in both objects. Set the
fee
instance variable of your
AccountWithFee
object to 5.0. Your objects now represent investment accounts with a balance of $1,000 and an annual interest rate of 9%. The second account also charges a $5 monthly management fee. Invoke the
compound()
method using 60 months for both accounts and display the new balances. The balances of the two accounts after 5 years should be $1565.68 and $1188.56 respectively. The seemingly insignificant monthly fee does not appear so insignificant after 5 years.
Hints
You do not need to worry about formatting your output or rounding the balance to the nearest cent.
What to submit
In the text box below, cut and paste the source code for
Account
,
AccountWithFee
and
AccountTest
. Click the
Submit
button to submit your source code.