Create another class called Television. Television is an Appliance. It only has the following additional private attributes:
type (whether Smart or Non-Smart)
volume (0 - 100)
channel (1 - 100)
It should have the following methods:
getters
void volumeUp() - increases the volume by 1 (possible only when TV is ON)
void volumeDown() - decreases the volume by 1 (possible only when TV is ON)
void channelUp() - increases the channel by 1 (possible only when TV is ON)
void channelDown() - decreases the channel by 1 (possible only when TV is ON)
String toString() - overriding Appliance's. It should include type, volume, and channel in this format ("Brand: xxxx, Cost: PhP xxxx.xx, Power: xx, Type: xxxx, Volume: xx, Channel: xx").
A lone constructor is to be implemented with a type, brand, and cost as an argument. It sets the volume to 0 and channel to 1. And it prints "Television Constructor" as well
public class Television extends Appilance {
private String type;
private int volume;
private int channel;
public Television(String type, String brand, double cost) {
super(brand, cost);
this.type = type;
volume = 0;
channel = 1;
System.out.println("Television Constructor");
}
public String getType() {
return type;
}
public int getVolume() {
return volume;
}
public int getChannel() {
return channel;
}
public void volumeUp() {
if (isPower()) {
volume++;
}
}
public void volumeDown() {
if (isPower()) {
volume--;
}
}
public void channelUp() {
if (isPower()) {
channel++;
}
}
public void channelDown() {
if (isPower()) {
channel--;
}
}
@Override
public String toString() {
return super.toString() + ", Type: " + type + ", Volume: " + volume + ", Channel: " + channel;
}
}
Comments
Thank you for Answering my question
Leave a comment