We will write a television class. A television object will have the following attributes (fields in the class):
The television object will also be able to control the state of its attributes. These controls become methods in our class.
We will also need a constructor method that will be used to create an instance of a Television. see image.
1.See the given Television.java file.
2.The 2 constant fields and the 3 remaining fields listed in the UML diagram have been declared.
3.Read and try to understand the constructor that has two parameters, a manufacturer's brand and a screen size. These parameters will bring in information.
4.Initialize the powerOn field to false (power is off), the volume to 20, and the channel to 2 inside the constructor.
5.Compile and fix the syntax errors. Do not run.
1.Define access methods called getChannel, getManufacturer, and getScreenSize that return the value of the corresponding field. Follow the sample given as getVolume.
2.Read and try to understand the method given in the Televesion.java. Define decreaseVolume method that will decrease the volume by 1.
3.Compile and fix the syntax errors. Do not run.
1.You can only execute (run) a program that has a main method, so there is a driver program that is already written to test out your Television class. Copy the file TelevisionDemo.java to the same directory as Television.java.
2.Compile and run TelevisionDemo and follow the prompts. If your output matches the output below, Television.java is complete and correct. You will not need to modify it further for this lab.
OUTPUT (boldface is user input)
A 55 inch Toshiba has been turned on.
What channel do you want? 56
Channel: 56 Volume: 21
Too loud!! I am lowering the volume.
Channel: 56 Volume: 15
1.Edit the TelevisionDemo.java file. Declare another Television object called portable.
2.Instantiate portable to be a Sharp 19 inch television.
3.Use a call to the power method to turn the power on.
4.Use calls to the accessor methods to print what television was turned on.
5.Use calls to the mutator methods to change the channel to the user's preference and decrease the volume by two.
6.Use calls to the accessor methods to print the changed state of the portable.
7.Compile and run TelevisionDemo again. See the given output sample (outputSample.doc)