9.1 | ( The Triangle class ) Design a class named Triangle that extends GeometricObject . The class contains:
For the formula to compute the area of a triangle, see Exercise 5.19. The toString() method is implemented as follows : return "Triangle: side1 = " + side1 + " side2 = " + side2 + " side3 = " + side3; Draw the UML diagram that involves the classes Triangle and GeometricObject . Implement the class. Write a test program that creates a Triangle object with sides 1 , 1.5 , 1 , sets color yellow and filled true , and displays the area, perimeter, color, and whether filled or not. |
9.2 | ( The Person , Student , Employee , Faculty , and Staff classes ) Design a class named Person and its two subclasses named Student and Employee . Make Faculty and Staff subclasses of Employee . A person has a name , address, phone number, and email address. A student has a class status (freshman, sophomore, junior, or senior). Define the status as a constant. An employee has an office, salary, and date- hired . Define a class named MyDate that contains the fields year , month , and day . A faculty member has office hours and a rank. A staff member has a title. Override the toString method in each class to display the class name and the person's name. Draw the UML diagram for the classes. Implement the classes. Write a test program that creates a Person , Student , Employee , Faculty , and Staff , and invokes their toString() methods. |
9.3 | ( Subclasses of Account ) In Exercise 7.3, the Account class was created to model a bank account. An account has the properties account number, balance, annual interest rate, and date created, and methods to deposit and withdraw. Create two subclasses for checking and saving accounts. A checking account has an overdraft limit, but a savings account cannot be overdrawn. Draw the UML diagram for the classes. Implement the classes. Write a test program that creates objects of Account , SavingsAccount , and CheckingAccount , and invokes their toString() methods. |
9.4 | ( Implementing MyStack using inheritance ) In Listing 9.8, MyStack is implemented using composition. Create a new stack class that extends MyArrayList . Draw the UML diagram for the classes. Implement MyStack . |
9.5 | ( The Course class ) Rewrite the Course class in Listing 7.11. Use an ArrayList to replace an array to store students. |
9.6 | ( Using ArrayList ) Write a program that creates an ArrayList , adds a Loan object, a Date object, a string, a JFrame object, and a Circle object to the list, and uses a loop to display all the elements in the list by invoking the object's toString() method. |