E N D
物件導向實習08 97.11.25
HW Page.418 8.4 • (Rectangle Class) 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 methods should verify that length and width are each floating-point numbers larger than 0.0 and less that 20.0. Write a program to test class Rectangle.
HW Page 418 8.6 • Modify class time2 of Fig. 8.5 to include a tick method that increments the time stored in a Time2 object by one second. Provide method incrementMinute to increment the minute and method incrementHour to increment the hour. The Time2 object should always remain in a consistent state. Write a program that tests the tick method, the incrementMinute method and the incrementHour method to ensure that they work correctly. Be sure to test the following cases:
HW Page 418 8.6 (cont.) • A) incrementing into the next minute. • B) incrementing into the next hour and • C) incrementing into the next day (i.e. 11:59:59 PM to 12:00:00 AM).