Chapter 6 Lab: Assignment DropBox

Added on - Sep 2019

Trusted by 2+ million users,
1000+ happy students everyday
Showing pages 1 to 3 of 7 pages
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 youhave 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 theclasswe are going to create in this lab.First we need a blueprint. All manufacturers have the same basic elements in thetelevisions they produce as well as many options. We are going to work with a few basicelements that are common to all televisions. Think about a television in general. It has abrand name (i.e. it is made by a specific manufacturer). The television screen has aspecific 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 anypoint in time, the television’s state can be described by how these controls are set.We will write theTelevisionclass. Each object that is created from theTelevisionclass must be able to hold information about that instance of aTelevisionin fields. So aTelevisionobject will have the following attributes:manufacturer. Themanufacturerattribute will hold the brand name.This cannot change once the television is created, so will be a namedconstant.screenSize. ThescreenSizeattribute will hold the size of the televisionscreen.
Copyright © 2016 Pearson Education, Inc., Hoboken NJThis cannot change once the television has been created so will be a namedconstant.powerOn. ThepowerOnattribute will hold the valuetrueif the power is onandfalseif the power is Thechannelattribute will hold the value of the station that thetelevision isshowing.volume. Thevolumeattribute will hold a number value representing theloudness (0 being nosound).These attributes becomefieldsin our class.TheTelevisionobject will also be able to control the state of its attributes. Thesecontrols become methods in our class.setChannel. ThesetChannelmethod will store the desired station inthechannelfield.power. Thepowermethod will toggle the power between on and off,changingthevaluestoredinthepowerOnfieldfromtruetofalseorfromfalsetotrue.increaseVolume. TheincreaseVolumemethod will increase thevaluestored in thevolumefield by 1.decreaseVolume. ThedecreaseVolumemethod will decrease thevaluestored in thevolumefield by 1.getChannel.ThegetChannelmethodwillreturnthevaluestoredinthechannelfield.getVolume. ThegetVolumemethod will return the value stored inthevolumefield.getManufacturer. ThegetManufacturermethod will returntheconstant value stored in theMANUFACTURERfield.getScreenSize. ThegetScreenSizemethod will return theconstantvalue stored in theSCREEN_SIZEfield.We will also need a constructor method that will be used to create an instance of aTelevision.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 fieldsMANUFACTURERandSCREEN_SIZElisted in theUMLdiagram.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 brandand a screen size. These parameters will bring ininformation.2.Inside the constructor, assign the values taken in from the parameters to thecorrespondingfields.3.InitializethepowerOnfield tofalse(powerisoff),thevolumeto 20,and the
Desklib Logo
You are reading a preview
Upload your documents to download or

Become a Desklib member to get access