Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA QUESTION For this assignment you will implement one class, called TV, that models some aspects of the behavior of simple television. A TV has

JAVA QUESTIONimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

For this assignment you will implement one class, called TV, that models some aspects of the behavior of simple television. A TV has a current channel and volume. The volume level ranges from 0.0 to 1.0. The possible range of channels is determined by two parameters that we will refer to as start and numChannels. In general there will always be numChannels consecutive channels, the lowest of which is start; that is, the range of values is from start up to start + numChannels 1, inclusive. The volume is adjusted with methods volumeUp and volumeDown, but never goes above 1.0 or below 0.0. The volume is incremented or decremented by the value of the constant VOLUME_INCREMENT. The channel is adjusted with methods channelUp and channelDown, but never goes below start or above start + numChannels - 1. The channel can also be set directly with the setChannel method. The method gotoPreviousChannel sets the channel to the most recent previous channel number. It is also possible to "reprogram" the TV to set a different start channel or number of channels. Please note that you do not need any conditional statements (i.e. "if" statements) or anything else we haven't covered, for this assignment. There will be a couple of places where you need to choose the larger or smaller of two numbers, which can be done with the methods Math.min() or Math.min(). For the wrapping behavior of the channel numbers, you can use the mod (%) operator. (You will not be directly penalized for using conditional statements, but your code will become longer and more complicated, and if it becomes overly complicated and hard to read, the TA will start taking off points.) Specification The specification for this asssignment includes this pdf along with any "official" clarifications announced on Canvas. There is one public constant: public static final double VOLUME_INCREMENT = 0.07; There is one public constructor: public TV (int givenStart, int givenNumChannels) Constructs a new TV with channels givenstart through givenStart + givenNumChannels 1. Initially the volume is 0.5 and the channel is equal to givenstart. public void channelDown () Changes the channel down by 1, wrapping around to start + numChannels - 1 if the current channel is start. public void channelUp () Changes the channel up by 1, wrapping around to start if the current channel is start + numChannels 1. public String display ( ) Returns a string representing the current channel and volume in the form "Channel x Volume y$", where x is the current channel and y the volume, multiplied by 100 and rounded to the nearest integer. For example, if the channel is 8 and the volume is .765, this method returns the exact string "Channel 8 Volume 778". public int getChannel() Returns the current channel. public double getVolume () Returns the current volume. public void goto PreviousChannel() Sets the current channel to the most recent previous channel. If no channel has ever been set for this TV using one of the methods channelDown, channelUp, or setChannel, this method sets the channel to start. public void resetstart(int givenStart) Resets this TV so that its available channels are now from givenstart through givenStart + numChannels - 1. If the current channel or previous channel is outside the new range of channel numbers, their values are adjusted to be the nearest value within the new range. public void resetNumChannels (int givenNumChannels) Resets this TV so that its available channels are now from start through start + givenNumChannels 1. If the current channel or previous channel is outside the new range of channel numbers, their values are adjusted to be the nearest value within the new range. public void setChannel (int channelNumber) Sets the channel to the given channel number. However, if the given value is greater than start + numChannels 1, it is set to start + numChannels 1, and if the given value is less than start, it is set to start. public void volume Down () Lowers the volume by VOLUME_INCREMENT, but not below 0.0. public void volumeUp () Raises the volume by VOLUME_INCREMENT, but not above 1.0

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

Data Management Databases And Organizations

Authors: Richard T. Watson

3rd Edition

0471418455, 978-0471418450

More Books

Students also viewed these Databases questions