06 Prepare : Checkpoint B
Overview
This checkpoint is intended to help you practice the syntax of inheritance, specifically, the syntax of calling methods from a base class.
You are to write a program to track cell phones. You determine that there are two types of cell phones: traditional phones that have a phone number, and smart phones that have a phone number but also contain an email address.
Instructions
Write a class Phone that contains a phone number, and then a class SmartPhone that extends the Phone class to add an email address according to the following:
The
Phoneclass should contain three integers for the different parts of a phone number. Here is its class diagram:The
prompt_numbermethod of thePhoneclass should ask the user to enter each element of a phone number.The
displaymethod of thePhoneclass should display the number in the format "(areaCode)prefix-suffix".The
SmartPhoneclass should extend thePhoneclass and add the following:The
promptmethod of theSmartPhoneclass should call theprompt_numbermethod defined in the base class and then additionally prompt for an email address.The
displaymethod of theSmartPhoneclass should call thedisplaymethod defined in the base class and then display the email address. (Yes, it must call it, and yes, they must both be named display.)In
mainfunction, create aPhoneobject, call itsprompt_numbermethod, and then itsdisplaymethod.After that, also in
main, create aSmartPhoneobject, call itspromptmethod, and then itsdisplaymethod.For simplicity, you may again put all of your classes in the same file.
| Phone |
|---|
| area_code : int |
| prefix : int |
| suffix : int |
| prompt_number() : void |
| display() : void |
| SmartPhone |
|---|
| email : string |
| prompt() : void |
| display() : void |
Sample Output
The following is an example of output for this program:
Phone:
Area Code: 801
Prefix: 123
Suffix: 4567
Phone info:
(801)123-4567
Smart phone:
Area Code: 208
Prefix: 867
Suffix: 5309
Email: jenny@test.com
Phone info:
(208)867-5309
jenny@test.com
Automatic Grading Script (TestBed)
This assignment is pass/fail. In order to receive credit, it must pass the auto-grading test script (TestBed). You can run this script as many times as you like while you are working on the assignment. The same test script will be run by the instructor for credit, so you should not be surprised at the result.
In addition, because the point of this exercise is to help you practice the use of inheritance, you must use inheritance to receive credit for this assignment.
To run the test script, log in to the CS Department Linux system and run the testBed command, providing the class and test script to run as well as the Python program to use, for example:
testBed cs241/check06b check06b.py
Submission
Submit your program by logging into the CS Department Linux system, and running the submit command with your filename, for example:
submit check06b.py
You should then select the appropriate course (CS 241), instructor, and assignment from the list.