Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
COMP 131: Object-Oriented Programming with Java Spring 2006 Homework Assignment 8 Due by 11:59pm, Sunday, May 14, 2006 QualityManager BillingItem VoiceCall TextMessage Your task in this problem is to design and implement Java classes for the billing system of a cell phone service provider. The type hierarchy for the billing system is given above. The company bills customers for voice calls and text messages. The costs of voice calls and text messages are computed differently. The company keeps track of the duration of a voice call (in seconds) and the number of characters in a text message. The ultimate goal for this system is to print out a billing statement for the cell phone service provider. Each line of the statement corresponds to a single voice call or text message, and prints all the relevant information about the call or message. Here is a sample output of the billing statement program. Call 0 From 2125551212 to 2123381748 was a text message of 0 characters and had cost 0 Call 1 From 2125551212 to 2123381748 was a voice call of duration 450 seconds and had cost 3.90 YTL Call 2 From 2125551212 to 2123381748 was a text message of 40 characters and had cost 0 Call 3 From 2125551212 to 2123381748 was a text message of 60 characters and had cost 1 YTL Call 4 From 2125551212 to 2123381748 was a text message of 80 characters and had cost 2 YTL Call 5 From 2125551212 to 2123381748 was a text message of 100 characters and had cost 3 YTL Call 6 From 2125551212 to 2123381748 was a voice call of duration 2700 seconds and had cost 26.40 YTL but was discounted to 13.20 YTL due to low voice quality. Call 7 From 2125551212 to 2123381748 was a voice call of duration 3150 seconds and had cost 30.90 YTL but was discounted to 0 due to unacceptable voice quality. Call 8 From 2125551212 to 2123381748 was a text message of 160 characters and had cost 6 YTL Call 9 From 2125551212 to 2123381748 was a text message of 180 characters and had cost 7 YTL Part of the code that tests the billing system is provided in the file BillingTester.java. Examine this file first, before writing any code. You are required to complete the code in BillingTester.java and implement the rest of your classes so that BillingTester.java compiles and executes without errors. Note, especially, that BillingTester.java uses an array of BillingItem objects to store 10 billing items and calls the cost() method for each object in the array. Text messages are priced as follows: The first 40 characters of a message are free For every extra 10 characters, the charge is 50 YKR Voice calls are priced as follows: The first minute of a voice call is free The charge for every extra 10 seconds is 10 YKR The quality of the connection during a voice call can be HIGH, LOW or UNACCEPTABLE. These constants are already defined in the enum VoiceQuality. You are required to make use of this enum when referring to voice quality. If the quality of a connection is HIGH, it is charged as described above. If the quality is LOW, the call is charged half price. If the quality is UNACCEPTABLE, the call is free. The Java interface QualityManager is also provided for you. This interface lists two methods, reportQuality(), which returns the quality of the call, and discountedCost(), which returns the discount for the cost of the call if the quality of the connection is not HIGH, as explained above. VoiceCall is required to implement QualityManager and BillingTester uses methods of this interface while printing the billing statement for the company. Part 1-A: Implement a BillingItem class [10 points] A partial implementation for this class is not provided. BillingItem must I. II. III. IV. have a no-argument constructor, have a constructor whose arguments are the phone numbers of the caller and destination, provide a reasonable toString method provide get and set methods for its fields. The set methods should make sure that the field values are legal values. Phone numbers are required to be ten-digit numbers. Fields representing phone numbers must be set to a default value if no properly formatted value is supplied. V. have other fields/methods as necessary Make sure that BillingItem does not have fields and/or methods that are never used. Part 1-B: Implement a VoiceCall class. [15 points] A partial implementation for this class is not provided This class should I. have a no-argument constructor II. have a constructor whose arguments are the phone numbers of the caller and destination, the duration of the phone call, and the quality of the voice connection during the phone call III. provide a reasonable toString method IV. provide get and set methods for its fields. The set methods should make sure that the field values make sense. V. Must implement the interface QualityManager and have methods that compute regular and discounted call prices as explained above VI. have any other fields and methods as necessary Do not unnecessarily override methods. Do not duplicate work already done in the superclass. Part 1-C: Implement a TextMessage class [15 points] A partial implementation for this class is not provided This class should I. have a no-argument constructor, II. have a constructor whose arguments are the phone numbers of the caller and destination, and the length of the voice message, III. provide a reasonable toString method, IV. provide get and set methods for its fields. The set methods should make sure that the field values make sense. V. have any other fields/methods as necessary Do not unnecessarily override methods. Do not duplicate work already done in the superclass BillingItem. Part 1-D: Complete the implementation of the BillingTest class [10 points] Most of the implementation for this class is given. You are only required to add code in a designated place in this class in order to print the discounted price of a call when appropriate.