Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Design a class called TV. Your class should have the following: 3 instance variables: channel represents channels in the range 1-120. volume - represents the

Design a class called TV.

Your class should have the following:

3 instance variables:

channel represents channels in the range 1-120.

volume - represents the volume in the range 1-50.

isOn represents if the TV is on or off. It should be of type boolean and be assigned a default value false;

2 Constructors:

- no-arg constructor that sets values of channel and volume to 1, and isOn to false.

- constructor that has 2 parameters, that initializes the variables channel and volume;

8 instance(non-static) methods (All of them should have void return type). Please implement the logic of the method based on the given descrption :

turnOn() : Turns the TV on.

turnOff() : Turns the TV off.

setChannel(int newChannel) : if the TV is on and the channel is in the range between 1 and 120, both included, set the channel to the newChannel.

setVolume(int newVolumeLevel) : if the TV is on and the volume is in the range between 1 and 50, both included, set the volume to the newVolume.

channelUp() : if the TV is on and the channel is less than 120, increase the channel by one.

channelDown() : if the TV is on and the channel is more than 1, decrease the channel by one.

volumeUp() : if the TV is on and the volume is less than 50, increase the volume by one.

volumeDown() : if the TV is on and the volume is more than 1, decrease the volume by one.

Once your TV class is ready, create a separate Driver class with the main method and test your TV class:

1.Create 2 TV objects.

2.Call the methods of the TV class by turning the TV on, changing the channel, changing the volume, etc.

3.Print out 3 instance variable values.

In java please follow the steps

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Programming The Perl DBI Database Programming With Perl

Authors: Tim Bunce, Alligator Descartes

1st Edition

1565926994, 978-1565926998

More Books

Students also viewed these Databases questions