Television class
package abc1;
public class Television {
//Member variables as stated in question
private int channel;
private int volumeLevel;
private boolean status;
//getter methods
int getChannel() {
return channel;
}
int getVolume() {
return volumeLevel;
}
boolean getStatus() {
return status;
}
//no-arg constructor and default values of the variables
Television(){
channel = 1;
volumeLevel = 1;
status = false;
}
void volumeUp() {
if(volumeLevel<7) {
volumeLevel++;
}
System.out.println("Volume is " + volumeLevel);
}
void volumeDown() {
if(volumeLevel>0) {
volumeLevel--;
}
System.out.println("Volume is " + volumeLevel);
}
void channelUp() {
channel = (getChannel() +1);
if(channel>120)
channel = (channel % 120) -1 ;
System.out.println("Channel is " + getChannel() );
}
void channelDown() {
channel = channel - 1;
if(channel<0)
channel = channel + 121;
System.out.println("Channel is " + channel );
}
void setChannel(int i) {
if(i>=0 && i<=120)
channel = i;
}
void turnOn() {
status = true;
System.out.println("TV is switched on.");
}
void turnOff() {
status = false;
System.out.println("TV is switched off. ");
}
public String toString() {
String str = "";
str = str + "TV set: ";
if(status==true)
str = str + "on ";
else
str = str + "off ";
str = str + " Volume: " + volumeLevel + " ";
str = str + " Channel: " + channel;
return str;
}
}
Test program
package abc1;
public class TestTv {
public static void main(String[] args) {
Television tv1, tv2;
tv1 = new Television();
tv2 = new Television();
System.out.println("Is TV 1 switched on.");
System.out.println(tv1.getStatus());
System.out.println("Is TV 2 switched on.");
System.out.println(tv2.getStatus());
System.out.println("Turning on TV 1 ");
tv1.turnOn();
System.out.println("Turning on TV 2 ");
tv2.turnOn();
System.out.println("Checking channel no on TV 1 ");
System.out.println(tv1.getChannel());
System.out.println("Checking channel no on TV 2 ");
System.out.println(tv2.getChannel());
System.out.println("Checking volume level on TV 1 ");
System.out.println(tv1.getVolume());
System.out.println("Checking volume level on TV 2 ");
System.out.println(tv2.getVolume());
System.out.println("Is TV 1 swithced on. ");
System.out.println(tv1.getStatus());
System.out.println("Is TV 2 switched on. ");
System.out.println(tv2.getStatus());
System.out.println("Setting TV 1 to channel 0 ");
tv1.setChannel(0);
System.out.println(tv1.toString());
System.out.println("Setting TV 2 to channel 120 ");
tv2.setChannel(120);
System.out.println(tv2.toString());
System.out.println("Increasing channel no on TV 1 ");
tv1.channelUp();
System.out.println("Increasing channel no on TV 2 ");
tv2.channelUp();
System.out.println("Decreasing channel no on TV 1 ");
tv1.channelDown();
System.out.println("Decreasing channel no on TV 2 ");
tv2.channelDown();
System.out.println("Increasing volume on TV 1 ");
tv1.volumeUp();
System.out.println("Increasing volume on TV 2");
tv2.volumeUp();
System.out.println("Decreasing volume on TV 1 ");
tv1.volumeDown();
System.out.println("Decreasing volume on TV 2 ");
tv2.volumeDown();
System.out.println(tv1.toString() + "\n" + tv2.toString());
}
}
Code screenshot for Television class
Code screenshot for Test class
Sample output
Help please 1) Define a Java class for defining the activity of a TV set. The...
** IN JAVA **: Design and implement class Radio to represent a radio object. The class defines the following attributes (variables) and methods:Assume that the station and volume settings range from 1 to 10.A private variable of type int named station to represent a station number. Set toA private variable of type int named volume to represent the volume setting. Set to 1.A private variable of type boolean named on to represent the radio on or off. Set to false.A...
1. Please write the following program in Python 3. Also, please create a UML and write the test program. Please show all outputs. (The Fan class) Design a class named Fan to represent a fan. The class contains: Three constants named SLOW, MEDIUM, and FAST with the values 1, 2, and 3 to denote the fan speed. A private int data field named speed that specifies the speed of the fan. A private bool data field named on that specifies...
SOLVE IN PYTHON: Exercise #2: Design and implement class Radio to represent a radio object. The class defines the following attributes (variables) and methods: Assume that the station and volume settings range from 1 to 10. A private variable of type int named station to represent a station number. Set to 1. A private variable of type int named volume to represent the volume setting. Set to 1. A private variable of type boolean named on to represent the radio...
PYTHON Exercise #2: Design and implement class Radio to represent a radio object. The class defines the following attributes (variables) and methods: Assume that the station and volume settings range from 1 to 10. 1. A private variable of type int named station to represent a station number. Set to 1. 2. A private variable of type int named volume to represent the volume setting. Set to 1. 3. A private variable of type boolean named on to represent the...
please write in Java and include the two classes Design a class named Fan (Fan.java) to represent a fan. The class contains: An int field named speed that specifies the speed of the fan. A boolean field named fanStatus that specifies whether the fan is on (default false). A double field named radius that specifies the radius of the fan (default 5). A string field named color that specifies the color of the fan (default blue). A no-arg (default) constructor...
using visual studios C# implementing using system; be sure I can copy and paste. Exercise #2: Design and implement class Radio to represent a radio object. The class defines the following attributes (variables) and methods: Assume that the station and volume settings range from 1 to 10. 1. A private variable of type int named station to represent a station number. Set to 1. 2. A private variable of type int named volume to represent the volume setting. Set to...
Note: According to the question, please write source code in java only using the class method. Sample Run (output) should be the same as displayed in the question below. Make sure the source code is working properly and no errors. Exercise #2: Design and implement class Radio to represent a radio object. The class defines the following attributes (variables) and methods Assume that the station and volume settings range from 1 to 10 1. A private variable of type int...
THE FOLLOWING PROGRAM IS NEEDED IN JAVA LANGUAGE Design a class torepresent account, include the following members: -Data Members a)Name of depositor-Stringb)Account Number –intc)Type of account –Boolean d)Balance amount -doublee)AnnualInterestrate -double Methods: -(a)To assign initial values (use constructor)(b)To deposit an amount.(c)TO withdraw amount with the restriction the minimum balance is 50 rs. Ifyouwithdraw amount reduced the balance below 50 then print the error message.(d)Display the name and balance of the account.(e)Get_Monthly_intrestRate() -Return the monthly interestrate whichis nothing but Annualintrestrate/12. Annualinterestrate...
(The Account class) Design a class named Account that contains: A private int data field named id for the account (default 0). A private double data field named balance for the account (default 0). A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. A private Date data field named dateCreated that stores the date when the account was created. A no-arg constructor that creates a default...
9.7 (The Account class) Design a class named Account that contains: • A private int data field named id for the account (default o). • A private double data field named balance for the account (default o). • A private double data field named annualInterestRate that stores the current interest rate (default o). Assume that all accounts have the same interest rate. • A private Date data field named dateCreated that stores the date when the account was created. •...