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. object
    2. repository

  2. (2 pts) Name one benefit to defining a ``toString'' method for a class.

  3. (2 pts) What is the purpose of a constructor?

  4. (10 pts) NOTE: This question is focused on non-OOP use of classes. Suppose a cell phone company keeps track of cell phone plans using the following class:
    class CellPlan
    {
       String phoneNumber; // account number
       int minutesAllowed; // number of free talk minutes per month
       int minutesLeft;    // number of minutes used so far
    }
    
    A basic plan consists of a phone number and the number of free talk minutes allowed per month. A third field tracks the number of minutes used so far in a given month.

    Write a method that accepts an array of CellPlan objects and an integer indicating the number of plans in the array as parameters. The method should be called warningList and should produce a list of phone numbers that have not yet used up all of their minutes but have 10 or fewer minutes left.

  5. Suppose the cell phone company programmers have decided to modify the design of the CellPlan class in the previous problem to fit the ``pure object model''. In this problem you will write a new CellPlan class.
    1. (4 pts) Write a JavaDoc block for the class.
    2. (4 pts) Write the header and declare the attributes.
    3. (4 pts) Write a constructor for the class that accepts the phone number as a parameter and sets both minutesAllowed and minutesLeft to 1000.
    4. (4 pts) Write a toString method that returns the phone number followed by a space followed by the minutes left following by a forward slash followed by the minutes allowed.
    5. (2 pts) Write a getter method for the minutesLeft attribute.
    6. (4 pts) Write a method named madeCall that is to be called every time a phone call is completed for that cell phone plan. The method should accept the duration of the call in minutes and should update the minutes left appropriately.
    7. (4 pts) Explain how the code you wrote in problem 4 would have to change if it were using this new CellPlan class.
    8. (4 pts) Suppose you had just modified the CellPlan class as described above in your workspace. Write the sequence of git statements you would use to record your work and post it to your bitbucket.org homework account.
    9. (4 pts) Draw a UML diagram that depicts the new design of the CellPlan class.
    10. (4 pts) Under what circumstances could it make sense to designate the minutesAllowed attribute as static?
    11. (6 pts) Write code (presumably in main()) that will create a CellPlan for the phone number 555-1234. For that new instance, register a 39 minute phone call and will then display the phone number, minutes left, and minutes allowed for it.

Quick Links