Ask a question to Desklib · AI bot


Chapter 6 Lab: Assignment DropBox

Added on -2019-09-20

| 7 pages
| 1757 words

Trusted by 2+ million users,
1000+ happy students everyday

Copyright © 2016 Pearson Education, Inc., Hoboken NJChapter 6 Lab: ClassesLab Submission Instructions1)Indicate which tasks you completed: 2)Copy screen shots of your program execution for tasks 4 and 5 and paste them below. Upload this file to Canvas under this assignment DropBox.3)Upload a text file containing a copy of your completed code for Task5 (or the last task you have completed a working program) to Canvas under this assignment DropBox.LabObjectivesBe able to declare a newclassBe able to write aconstructorBe able to write instance methods that return avalueBe able to instantiate anobjectBe able to use calls to instance methods to access a change the state of anobjectIntroductionEveryone is familiar with a television. It is the class we are going to create in this lab. First we need a blueprint. All manufacturers have the same basic elements in the televisions they produce as well as many options. We are going to work with a few basic elements that are common to all televisions. Think about a television in general. It has a brand name (i.e. it is made by a specific manufacturer). The television screen has a specific size. It has some basic controls. There is a control to turn the power on and off. There is a control to change the channel. There is also a control for the volume. At any point in time, the television’s state can be described by how these controls are set.We will write the Television class. Each object that is created from theTelevision class must be able to hold information about that instance of aTelevisionin fields. So a Televisionobject will have the following attributes:manufacturer. The manufacturerattribute will hold the brand name. This cannot change once the television is created, so will be a namedconstant.screenSize. The screenSize attribute will hold the size of the television screen.
Copyright © 2016 Pearson Education, Inc., Hoboken NJThis cannot change once the television has been created so will be a named constant.powerOn. The powerOn attribute will hold the value true if the power is on and falseif the power is The channel attribute will hold the value of the station that the television isshowing.volume. The volume attribute will hold a number value representing the loudness (0 being nosound).These attributes become fields in our class.The Television object will also be able to control the state of its attributes. These controls become methods in our class.setChannel. The setChannel method will store the desired station in thechannelfield.power. The power method will toggle the power between on and off, changing thevaluestoredinthepowerOnfieldfromtruetofalseorfromfalseto true.increaseVolume. The increaseVolume method will increase the valuestored in the volumefield by 1.decreaseVolume. The decreaseVolume method will decrease the valuestored in the volumefield by 1.getChannel.ThegetChannelmethodwillreturnthevaluestoredinthechannelfield.getVolume. The getVolume method will return the value stored in thevolumefield.getManufacturer. The getManufacturer method will return theconstant value stored in the MANUFACTURERfield.getScreenSize. The getScreenSize method will return the constantvalue stored in the SCREEN_SIZEfield.We will also need a constructor method that will be used to create an instance of a Television.These ideas can be brought together to form a UML (Unified Modeling Language) diagram for this class, as shown below.Television
Copyright © 2016 Pearson Education, Inc., Hoboken NJ-MANUFACTURER: String-SCREEN_SIZE: int-powerOn: boolean-channel: int-volume: int+Television(brand: String, size: int):+setChannel (station: int): void+power( ): void+increaseVolume( ): void+decreaseVolume( ): void+getChannel( ): int+getVolume( ): int+getManufacturer( ): String+getScreenSize( ): intTask #1 Creating a New Class1.In a new file, create a class definition calledTelevision.2.Put a program header (comments or documentation) at the top of thefile// The purpose of this class is to model a television// Your name and today’s date3.Declare the 2 constant fields MANUFACTURER and SCREEN_SIZE listed in the UMLdiagram.4.Declare the 3 remaining fields listed in the UMLdiagram.5.Write a comment for each field indicating what itrepresents.6.Save this file and debug. Do notrun.Task #2 Writing a Constructor1.Create a constructor definition that has two parameters, a manufacturer’s brand and a screen size. These parameters will bring ininformation.2.Inside the constructor, assign the values taken in from the parameters to the correspondingfields.3.Initializethe powerOnfield tofalse(powerisoff),thevolumeto 20,and the

Found this document preview useful?

You are reading a preview
Upload your documents to download
Become a Desklib member to get accesss

Students who viewed this