Creating and Using the CellPhone Class
Suppose you work as a programmer for a company that sells cell phones and wireless service. Your department is creating an application to manage the company’s inventory of cells phones. You have been asked to create a class that represents a cell phone. The class should keep the following data about a cell phone:
The phone’s brand name
The phone’s model
The phone’s retail price
The class should have the following public properties:
Brand—a string property that will store the phone’s brand name
Model—a string property that will store the phone’s model
Price—a decimal property that will store the phone’s retail price
The class should also have a constructor that initializes the properties. The Brand and Model properties will be initialized with empty strings, and the Price property will be initialized with the value 0.
You create the CellPhone class in a project that will create an object of the class and test the object’s properties. The project is named Cell Phone Test and has already been started for you; it is located in the Chap10 folder of the Student Sample Programs. Figure 10-14 shows the application’s form. At run time, you enter sample cell phone data into the text boxes and then click the Create Object button. The application creates an object of the CellPhone class and assigns the data from the text boxes to the object’s properties. It then reads and displays the values of the object’s properties in the brandLabel, modelLabel, and priceLabel controls.