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

Create a superclass named Appliance which has 3 private attributes; name and loc

ID: 3875040 • Letter: C

Question

Create a superclass named Appliance which has 3 private attributes; name and location which are String and value which is a double

Create 2 constructors one with no arguments and the other with the 3 attributes as arguments

Override the method called toString() which will return the string of the name and location. Example: “The TV is located in the bedroom.”

Create a class named TV which inherits the superclass of Appliance.

The subclass TV has 3 additional private attributes; size, channel and volume which are integers.

Create 2 constructors one with no arguments and the other with the 6 attributes as arguments.

Override the method toString() in the TV class which will also override the superclass and adjust to include the channel.

Example       “The TV is located in the bedroom and is on channel 24”

Create a class named Client

Create a main method

Create an object called tv1 which is of type TV using the constructor which the arguments (“Hitachi”,”Bedroom”,399,32,1215,0)

Print out tv1

Explanation / Answer

Appliance.java

public class Appliance {
//Declaring instance variables
private String name;
private String location;
int value;

//Zero argumented constructor
public Appliance() {}

//Parameterized constructor
public Appliance(String name, String location, int value) {
this.name = name;
this.location = location;
this.value = value;
}

//getters and setters
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getLocation() {
return location;
}

public void setLocation(String location) {
this.location = location;
}

public int getValue() {
return value;
}

public void setValue(int value) {
this.value = value;
}

//toString method is used to display the contents of an object inside it
@Override
public String toString() {
return "The " + name + " is located in the " + location;
}

}

__________________

TV.java

public class TV extends Appliance {
//Declaring instance variables
private int size;
private int channel;
private int volume;
//Zero argumented constructor
public TV() {

}
//Parameterized constructor
public TV(String name, String location, int value, int size, int channel, int volume) {
super(name, location, value);
this.size = size;
this.channel = channel;
this.volume = volume;
}
//getters and setters
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public int getChannel() {
return channel;
}
public void setChannel(int channel) {
this.channel = channel;
}
public int getVolume() {
return volume;
}
public void setVolume(int volume) {
this.volume = volume;
}
//toString method is used to display the contents of an object inside it
@Override
public String toString() {
return "The " + getName() + " is located in the " + getLocation() + " and is on channel " + channel;
}

}

_________________

Client.java

public class Client {

public static void main(String[] args) {

//Creating an Instance of TV class object by passing the values as arguments

TV tv1=new TV("Hitachi","Bedroom",399,32,1215,0);

//Displaying the TV class info

System.out.println(tv1);

}

}

_________________

Output:

The Hitachi is located in the Bedroom and is on channel 1215

_______________Could you plz rate me well.Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote