Exercises
-
F.2 (Rectangle Class) Create a class
Rectangle
with attributeslength
andwidth
, each of which defaults to 1. Provide methods that calculate the rectangle’s perimeter and area. Provide set and get methods for bothlength
andwidth
. The set methods should verify thatlength
andwidth
are each floating-point numbers larger than 0.0 and less than 20.0. Write a program to test classRectangle
. -
F.3 (Savings Account Class) Create class
SavingsAccount
. Use astatic
variableannualInterestRate
to store the annual interest rate for all account holders. Each object of the class should contain aprivate
instance variablesavingsBalance
indicating the amount the saver currently has on deposit. Provide methodcalculateMonthlyInterest
to calculate ...
Get Android How to Program, 3/e now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.