Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Q Search ask #1 Creating a New Class 1. In a new file, create a class definition

ID: 3884220 • Letter: Q

Question


Q Search ask #1 Creating a New Class 1. In a new file, create a class definition called Television. 2. Put a program header (comments or documentation) at the top of t // The purpose of this class is to model a television // Your name and today's date 3. Declare the 2 constant fields listed in the UML diagram. 4. Declare the 3 remaining fields listed in the UMIL diagram. 5. Write a comment for each field indicating what it represents 6. Save this file as Television java. 7. Compile and debug. Do not run. ask #2 writing a Constructor 1. Create a constructor definition that has two parameters, a manufacturer's brand 2. Inside the constructor, assign the values 3. Initialize the poweron field to false (power is off), the vo l ume to 20, and the 4. Write comments describing the purpose of the constructor above the method 5. Compile and debug. Do not run and a screen size. These parameters will bring in information. corresponding fields. channel to 2. header taken in from the parameters to the Task #3 Methods 1. Define accessor methods called getvolume, getChannel, getManufacturer, and getScreenSize that return the value of the corresponding field. Define a mutator method called setChannel that accepts a value to be stored in the channel field. 2. 3. Define a mutator method called power that changes the state from true to false or from false to true. This can be accomplished by using the NOT operator (!). If the boolean variable powerOn is true, then !powerOn is false and vice versa. Use the assignment statement poweron= !poweron ; to change the state of powerOn and then store it back into powerOn (remember assignment statements evaluate the right hand side first, then assign the result to the left hand side variable. 4. Define two mutator methods to change the volume. One method should be called increaseVolume and will increase the volume by 1. The other method should be called decreaseVol ume and will decrease the vol ume by 1. 5. Write javadoc comments above each method header Copyright © 2016 Pearson Education, Inc., Hoboken NJ

Explanation / Answer

Note : As in this question as it didnt provided to create the Driver class.I didnt wrote it.If u need just tell me.Thank You.

_________________

Television.java

public class Television {

// Declaring instance variables
private String manufacturer;
private int volume;
private boolean powerOn;
private float screenSize;
private int channel;

// Parameterized constructor
public Television(String manufacturer, float screenSize) {
super();
this.manufacturer = manufacturer;
this.screenSize = screenSize;
this.powerOn = false;
this.volume = 20;
this.channel = 2;
}

/*
* This method return the manufacturer name
*
* @Params : void
*
* @return String
*/
public String getManufacturer() {
return manufacturer;
}

/*
* This method return the volume
*
* @Params : void
*
* @return int
*/
public int getVolume() {
return volume;
}

/*
* This method return the screen size
*
* @Params : void
*
* @return float
*/
public float getScreenSize() {
return screenSize;
}

/*
* This method return the channel no
*
* @Params : void
*
* @return int
*/
public int getChannel() {
return channel;
}

/*
* This method sets the channel number
*
* @Params : int
*
* @return void
*/
public void setChannel(int channel) {
this.channel = channel;
}

/*
* This method return the power on or off status
*
* @Params : void
*
* @return boolean
*/
public boolean getPower() {
return powerOn;
}

/*
* This method turn on or off the television
*
* @Params : void
*
* @return void
*/
public void power() {
this.powerOn = !powerOn;
}

/*
* This method increase the volume
*
* @Params : void
*
* @return void
*/
public void increaseVolume() {
volume++;
}

/*
* This method decrease the volume
*
* @Params : void
*
* @return void
*/
public void decreaseVolume() {
volume--;
}

}

_______________________