304311 Java Lab 

Lab 5

Objective

Implementing ADTs as Java-style classes, separating interface from implementation, using access methods and utility methods, introducing static class members, and initializing objects with constructors

Classwork:

  1. Create a class SavingAccount. Use a static class variable to store the annualInterestRate for all account holders. Each object of the class contains a private instance variable savingBalance indicating the amount the saver currently has on deposit. Provide a utility method calculateMonthlyInterest to calculate the monthly interest by multiplying the savingBalance by annualInterestRate divided by 12; this interest should be added to savingbalance. Provide a static method modifyInterest that sets the annualInterestrate to a new value. Write a driver program to test class SavingAccount. Instantiate two SavingAccount objects, saver1 and saver2, with balances of $20000 and $30000, respectively. Initially, set the annualInterestRate to 4%, then print the new balance for saver1 after adding monthly interest by using a button box. Change the annualInterestRate to 5% using the text field and then print the new balance for saver2 also by using the related button box as shown bellow:

  2.  

  3.  Create a class Rectangle. The class has attributes length and width, each of which defaults to 1. it has methods that calculate the perimeter and the area of the rectangle. It has set and get methods for both length and width. The set method should verify that length and width are each floating-point numbers larger than 0.0 and less than 20.0.

 

 

 

 

 

 

 

Lab 1
Lab 2
Lab 3
Lab 4
Lab 5
Lab 6
Lab 7
Lab 8
Lab 9

 � All Copyright Reserved By Fatma & Tahany,Email : [email protected]

Hosted by www.Geocities.ws

1