Chapter 8 Object-Based Programming 305 Fig. 8.7 Fig. (Space web hosting)
Chapter 8 Object-Based Programming 305 Fig. 8.7 Fig. 8.7Fig. 8.FiFi7g. 8.7g.8.7Properties demonstration for class Time3. (Part 5 of 5.) Line 34 declares Time3reference time. Line 41 in the constructor creates an object of class Time3and assigns it to time. The GUI contains three text fields in which the user can input values for the Time3 object s hour, minute and second variables, respectively. Next to each text field is a button the user can click to set the value of a particular Time3 property. Lines 66 90 declare three event-handling methods for the buttons Clickevents. Each event handler alters the values a Time3property (Hour, Minuteor Second). The GUI also contains a button that enables the user to increment the second value by 1. Using the Time3object s properties, method addButton_Click(lines 93 108) determines and sets the new time. For example, 23:59:59 becomes 00:00:00 when the user presses the button. Each modification of the time results in a call to UpdateDisplay, which uses the Time3properties to display the hour, minuteand secondvalues, and also displays the universal-and standard-time representations. Properties are not limited to accessing privatedata properties also can be used to calculate values associated with an object. One example of this would be a student object with a property representing the student s GPA (called GPA). Programmers can either provide code that calculates the student s GPA in the getaccessor for this property, or they can simply return a privatevariable containing the GPA, called gpa. (The value in this variable will need to be calculated in some other way, such as using a CalculateGPAmethod.) The programmer can use either technique, but we recommend using a property that calculates the GPA. Remember that client code should not be required to tell
From our experience, we can recommend PHP Web Hosting services, if you need affordable webhost to host and run your web application.