Question 2: Given the following information Braun Hair Dryer, 220 Power Voltage,
ID: 3706963 • Letter: Q
Question
Question 2: Given the following information Braun Hair Dryer, 220 Power Voltage, 3m Cord Length, Temperature 220C, 1800 Watt power, Cooling Settings are not available Baby Liss Hair Straightener, 220-240 Power voltage, 2m Cord Length, Temperature 200C, 15 sec heating time, Ceramic Coating plates, Temperature range 150C-200C, Ionic Styling Technology Philips Hair Dryer, 220-240 Power Voltage, 3.5m Cord Length, Temperature 220C, 2000 Watt power, Cooling Settings are available Bruan Hair Straightener, 220-240 Power voltage, 2m Cord Length, Temperature 240C, 20 sec heating time, Metal Coating plates, Temperature range 150C-240C, Anti-Static Styling Technology Drive 3 classes; class HairStyler (a super class), class Dryer and class Straightener (subclasses). Your classes should have whatever variables you think needed to reflect the given information, think carefully what is needed to be assigned to the super class and what should be assigned to the sub classesExplanation / Answer
Hello, I have a solution for you. Implemented everything as per the requirements.
// HairStyler.java
public class HairStyler {
// common attributes of all sub classes
private String name;
private String voltageRange;
private int cordLength;
private int temperature;
// constructor with arguments
public HairStyler(String name, String voltageRange, int cordLength,
int temperature) {
this.name = name;
this.voltageRange = voltageRange;
this.cordLength = cordLength;
this.temperature = temperature;
}
// getters and setters
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getVoltageRange() {
return voltageRange;
}
public void setVoltageRange(String voltageRange) {
this.voltageRange = voltageRange;
}
public int getCordLength() {
return cordLength;
}
public void setCordLength(int cordLength) {
this.cordLength = cordLength;
}
public int getTemperature() {
return temperature;
}
public void setTemperature(int temperature) {
this.temperature = temperature;
}
/**
* returns a String containing all details in proper formatted order
*/
@Override
public String toString() {
return name + ", " + voltageRange + " Power Voltage, " + cordLength
+ "m Cord Length, Temperature " + temperature + "C";
}
}
// Dryer.java
public class Dryer extends HairStyler {
//specific attributes of Dryer
private int power;
private boolean coolingSettingsAvailable;
//constructor with arguments
public Dryer(String name, String voltageRange, int cordLength,
int temperature, int power, boolean coolingSettingsAvailable) {
//passing values to super class
super(name, voltageRange, cordLength, temperature);
this.power = power;
this.coolingSettingsAvailable = coolingSettingsAvailable;
}
// getters and setters
public int getPower() {
return power;
}
public void setPower(int power) {
this.power = power;
}
public boolean isCoolingSettingsAvailable() {
return coolingSettingsAvailable;
}
public void setCoolingSettingsAvailable(boolean coolingSettingsAvailable) {
this.coolingSettingsAvailable = coolingSettingsAvailable;
}
@Override
public String toString() {
String cooling = "";
if (coolingSettingsAvailable) {
cooling = "available";
} else {
cooling = "not available";
}
/**
* Appending extra details to the String returned by super class
*/
return super.toString() + ", " + power
+ " Watt Power, Cooling settings are " + cooling;
}
}
// Straightener.java
public class Straightener extends HairStyler {
//specific attributes of Straightner
private int heatingTime;
private String coatingPlateType;
private String temperatureRange;
private String stylingTechnology;
// constructor with arguments
public Straightener(String name, String voltageRange, int cordLength,
int temperature, int heatingTime, String coatingPlateType,
String temperatureRange, String stylingTechnology) {
// passing values to super class
super(name, voltageRange, cordLength, temperature);
this.heatingTime = heatingTime;
this.coatingPlateType = coatingPlateType;
this.temperatureRange = temperatureRange;
this.stylingTechnology = stylingTechnology;
}
// getters and setters
public int getHeatingTime() {
return heatingTime;
}
public void setHeatingTime(int heatingTime) {
this.heatingTime = heatingTime;
}
public String getCoatingPlateType() {
return coatingPlateType;
}
public void setCoatingPlateType(String coatingPlateType) {
this.coatingPlateType = coatingPlateType;
}
public String getTemperatureRange() {
return temperatureRange;
}
public void setTemperatureRange(String temperatureRange) {
this.temperatureRange = temperatureRange;
}
public String getStylingTechnology() {
return stylingTechnology;
}
public void setStylingTechnology(String stylingTechnology) {
this.stylingTechnology = stylingTechnology;
}
@Override
public String toString() {
/**
* Appending extra details to the String returned by super class
*/
return super.toString() + ", " + heatingTime + " sec Heating Time, "
+ coatingPlateType + " Coating Plates, Temperature Range: "
+ temperatureRange + ", " + stylingTechnology
+ " Styling Technology";
}
}
// Driver.java
public class Driver {
public static void main(String[] args) {
/**
* Creating one dryer and one straightener, printing it
*/
Dryer dryer1 = new Dryer("Braun Hair Dryer", "220", 3, 220, 1800, false);
Straightener straightener1 = new Straightener(
"Baby Liss Hair Straightener", "220-240", 2, 200, 15,
"Ceramic", "150C-200C", "Ionic");
System.out.println(dryer1);
System.out.println(straightener1);
}
}
/*OUTPUT*/
Braun Hair Dryer, 220 Power Voltage, 3m Cord Length, Temperature 220C, 1800 Watt Power, Cooling settings are not available
Baby Liss Hair Straightener, 220-240 Power Voltage, 2m Cord Length, Temperature 200C, 15 sec Heating Time, Ceramic Coating Plates, Temperature Range: 150C-200C, Ionic Styling Technology
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.