Electronic handin will be available after 5PM on Thursday.
A cable television company calculates monthly bills for a customer based on the following table:
Service Rate Basic Cable $35.00 Family Cable $50.00 + $7.99 for each premium channel received Platinum Cable $72.50 + $5.49 for each premium channel received + $4.99 per pay-per-view movie for up to the first 4 movies purchased + $2.49 per pay-per-view movie for any additional movies purchased beyond the first 4 (if any) Digital Video Recorder Box 10% of monthly service rate not including extra charges (a customer may have at most one box)
Using Eclipse, write a Java program that contains a one class named CableTVBillCalculator. This class will contain a Java program that computes the charge for a cable bill based on the charge table given above.
Your main method will ask the user for the following input data:
You may assume that all input numerical data is of the proper form and will not contain negative values. Depending on the input data value(s), the program will calculate and display the amount of the cable bill for the user.
The cable service will be entered at the keyboard as three letters ("BAS" for Basic, "FAM" for Family, "PLA" for Platinum). If the user enters a service that doesn't match the three accepted entries, do not compute a bill; just output a message that the service type is unknown. All numerical measurements (number of premium channels and number of pay-per-view movies) are entered as integers. The digital video recorder box question will be answered with the string "YES" or "NO". If the user enters an answer that does not match these strings, then output a warning and assume the answer is "NO". Your program should ask only those questions that are necessary to determine the cable bill total. (See examples below.)
When you ask the user for the cable service, you should present the user with a menu with the three options:
--Cable Service Menu-- BAS [Basic Cable] FAM [Family Cable] PLA [Platinum Cable] Enter your menu choice:
Use the nextLine() method of the Scanner class to read the menu choice. The input string MUST match one of the three choices above; otherwise, the cable service is unknown. (So, "FAM" is ok but "fam" is not, "FAMILY" is not, and "Fam" is not.)
To avoid floating-point round-off problems, convert all monetary charges to cents. Convert the total cable bill back to dollars and cents only when you display it on the console. (For example, the cable bill for Basic cable service with a DVR box is 3500 cents.)
Once you read in the required data value(s) from the user, call a static method that will compute and return the required cable bill. You will need to write three static methods, one for each cable service type. Use the following signatures for your static methods:
public static int computeBasic(boolean hasDVRBox) // returns the cable bill in cents for a Basic Cable customer // given whether the customer has a DVR box or not public static int computeFamily(int premiumChannels, boolean hasDVRBox) // returns the cable bill in cents for a Family Cable customer // given the number of premium channels purchased as given // and whether the customer has a DVR box or not public static int computePlatinum(int premiumChannels, int numMovies, boolean hasDVRBox) // returns the cable bill in cents for an Platinum Cable customer // given the number of premium channels purchased, the number // of pay-per-view movies viewed and whether the customer has a // DVR box or not
Once your main method calls the appropriate method and receives the returned cable charge, display this charge in dollars and cents. Use the / and % operators to separate out the dollars and cents values. Be careful: What should you do if the number of cents starts with a 0 (e.g. $49.03)?
Here are five separate sample runs of the program (user input is shown in italics).
--Cable Service Menu-- BAS [Basic Cable] FAM [Family Cable] PLA [Platinum Cable] Enter your menu choice: BAS Do you have a DVR Box? (YES/NO) YES Your cable bill is $38.50 --Cable Service Menu-- BAS [Basic Cable] FAM [Family Cable] PLA [Platinum Cable] Enter your menu choice: FAM Do you have a DVR Box? (YES/NO) NO Enter the number of premium channels received: 3 Your cable bill is $73.97 --Cable Service Menu-- BAS [Basic Cable] FAM [Family Cable] PLA [Platinum Cable] Enter your menu choice: PLA Do you have a DVR Box? (YES/NO) Homer WARNING: Using an answer of NO. Enter the number of premium channels received: 6 Enter the number of pay-per-view movies purchased: 3 Your cable bill is $120.41 --Cable Service Menu-- BAS [Basic Cable] FAM [Family Cable] PLA [Platinum Cable] Enter your menu choice: PLA Do you have a DVR Box? (YES/NO) YES Enter the number of premium channels received: 0 Enter the number of pay-per-view movies purchased: 5 Your cable bill is $102.20 --Cable Service Menu-- BAS [Basic Cable] FAM [Family Cable] PLA [Platinum Cable] Enter your menu choice: Basic Cannot compute cable bill - unknown service type.
Compile and test that your program runs correctly. If your program does not compile and run, you will not receive full credit for your assignment. We will use additional test cases besides the ones provided above to test your program.
Your program must contain a comment at the beginning of your program with your name, andrew id, and section.
You should also use standard Java indentation and naming style for identifiers (Examples: ClassName, variableName, methodName()). Starting with this assignment, 1 point will be assigned to this category.
See the course website for instructions on how to hand in your program. Please zip your project folder that is created in Eclipse. This makes it easier for us to grade your work.
Remember that the work you submit must be your own. Also, late hand-ins are not accepted. Please plan ahead and submit early to avoid server overload at the deadline. The deadline is based on the server's clock, not your clock. Please do not email your code to your instructor or course assistant as your official hand-in; these will not be graded.