CSC 221: Computer Programming I
Fall 2005

HW3: Class Design & Conditionals


Few tasks in life are more complex than selecting a phone service. Numerous phone service providers exists, both nationally and locally, and each of those in turn offers numerous calling plans to choose from. This can be viewed as positive for the consumer, who is able to choose plans tailored to personal calling patterns, or negative due to the overall complexity of the system. In fact, Scott Adams described the phone service industry as a "confusopoly", where a group of companies with similar products resort to confusing the customer as opposed to competing directly on price (The Dilbert Future, Scott Adams, Harper-Collins Publishers, Inc., 1997).

Focusing on a specific type of service, cellular with free long distance, still leaves a wide range of options. The following are just five of the many cellular service plans currently available in the Omaha area (10/10/05).

Sprint PCS Fair and Flexible America 400
contract length: 24 months
activation fee: $35.00
monthly fee: $34.99
prepaid anytime minutes: 400
charge per additional minute: 5 cents

Sprint PCS Fair and Flexible America 700
contract length: 24 months
activation fee: $35.00
monthly fee: $49.99
prepaid anytime minutes: 700
charge per additional minute: 5 cents

U.S. Cellular National 800
contract length: 24 months
activation fee: $30.00
monthly fee: $49.95
prepaid anytime minutes: 800
charge per additional minute: 40 cents
          
Verizon Wireless America's Choice 450
contract length: 24 months
activation fee: $35.00
monthly fee: $39.99
prepaid anytime minutes: 450
charge per additional minute: 45 cents

Verizon Wireless America's Choice 900
contract length: 24 months
activation fee: $35.00
monthly fee: $59.99
prepaid anytime minutes: 900
charge per additional minute: 40 cents

For this assignment, you are to design and write classes that allow the consumer to compare these five plans under different calling conditions. The consumer should be able to enter the number of minutes they expect to use in a given month, then see the monthly cost for each of the plans. When computing the monthly cost, the activiation fee should be prorated over the length of the contract. That is, if the service plan is 24 months long, then 1/24th of the activation fee will be paid each month. If the number of minutes used by the consumer exceeds the number of prepaid minutes in the plan, then the per minute charge is applied to each additional minute.

For example, under the U.S. Cellular National 800 plan, the monthly portion of the activation fee is $30.00/24 = $1.25. If the customer used 800 or fewer minutes, then the cost for that month would be $1.25 + $49.95 = $51.20. If they used 1,000 minutes, however, the cost would be $1.25 + $49.95 + $0.40*200 = $131.20.

In order to model a service plan, you should define a class named ServicePlan, which has the following basic form:

public class ServicePlan
{
    FIELDS FOR STORING THE DETAILS OF THE SERVICE PLAN

    public ServicePlan(PARAMETERS FOR SPECIFYING THE DETAILS OF THE SERVICE PLAN)
    {
        INITIALIZE THE FIELDS
    }

    public String getName()
    {
        RETURN THE PLAN NAME
    }
    
    public double monthlyCost(int minutesUsed)
    {
        CALCULATE AND RETURN THE COST UNDER THIS PLAN
    }
}

Note that the constructor will have parameters for each of the different aspects of a service plan (e.g., contract length, activation fee). Fields will need to be declared to store this information, which can then be accessed by the getName and monthlyCost methods. The monthlyCost method should behave reasonably given any integer input.

Once you have the ServicePlan class completed and tested, write an additional class named ComparePlans, which can be used to compare all five plans. The class should have fields representing the five different service plans, and a method named compareCosts. The compareCosts method should take a single parameter, a number of minutes, and display the names and monthly costs for each of the five plans given that number of used minutes. To get the cost printed with two digits to the right of the decimal place, you should use the Java formatted print statement: System.out.printf. See the text for details.

WARNING: The format and style of your class implementations will affect your grade. Be sure to use meaningful names for your fields, and indent consistently. Each class should have a comment block at the top providing your name, the date, and a description of the class. Similarly, each method should have a comment block describing its purpose and any parameters and/or return values.