Program Design II - Exam #1

Write your answers on the answer sheets provided. You may reference printouts of any source code you have written. Other resources are not allowed. NOTE: All code you write on the exam should follow Java programming conventions.

  1. (3 pts each) Briefly define each of the following terms:
    1. pure object model
    2. getter method
    3. constructor

  2. (4 pts) Name one benefit of adhering to the pure object model. Name one downside of adhering to the pure object model.

  3. NOTE: This question is focused on non-OOP use of classes. Suppose an online book club charges a monthly fee and in return members get one credit per month that can be redeemed for a book. The book club also keep track of how many months someone has been a member.
    /*
     * Holds a book club member. They earn 1 credit per month.
     * Author: T.Sergeant
     * Date  : Today
     */
    class Member
    {
       String memberName; // name of the book club member
       int months;        // number of months of membership
       int credits;       // number of unredeemed credits
    }
    

    1. (4 pts) Rewrite the documentation so it follows JavaDoc format. NOTE: don't change what the documentation says ... just its format.

    2. (6 pts) Write a method that accepts an array of Member objects and an integer indicating the number of members in the array as parameters. The method should be called activeMembers and should produce a list of members that have been members for at least a year and who have 1 (or fewer) credits.

  4. In this problem we will continue working with the Member class but will modify to be more in line with a typical object-oriented approach.
    1. (2 pts) Rewrite the class so that its attributes are private.
    2. (4 pts) Write a constructor for the class that accepts a member's name a parameter and sets both months and credits to 1.
    3. (4 pts) Write a toString method that returns the member name followed by a space followed by credits available followed by a space followed by the number of months they have been a member in parentheses.
    4. (6 pts) Write a method named boughtBook that is to be called whenever the customer buys a book. The method should return false if there are no book credits available. Otherwise it should subtract one from credits and return true.
    5. (4 pts) Suppose, in your workspace, you had just modified the Member class as described above. Write the sequence of git statements you would use to record your work and post it to your bitbucket.org homework account.
    6. (4 pts) Draw a UML diagram that depicts the new design of the Member class.
    7. (4 pts) Suppose a typical member pays $19.99 per month for and we want to add an attribute to the Member class called monthlyFee. Under what circumstances would it make sense for this new attribute to be static? Under what circumstances should it be non-static?
    8. (4 pts) Suppose we add a static attribute monthlyFee as a float and set it to 19.99. Write a method called getProfit that returns the amount of profit generated from this book club member's dues since they have been a member. The profit is calculated as the revenue minus the cost. The revenue is the total amount of money the member has paid since becoming a member. The cost is $7.50 for each credit they redeemed.
    9. Write code (presumably in main()) that will:
      1. (4 pts) Create an array of 100 Member objects whose names are ``Member 1'', ``Member 2'', etc.
      2. (2 pts) Write code to calculate and display the total profit represented by all the members in the array.
      3. (2 pts) Write code to display the first member in the array.

Quick Links