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

l Lycamobile 6:50 PM Back a) Create a class named blanket with fields for a blan

ID: 3907346 • Letter: L

Question

l Lycamobile 6:50 PM Back a) Create a class named blanket with fields for a blanket's size, color, material, and price. The default constructor sets the values to Twin, White, Cotton, $30. Write another constructor as well to get the values of the first three fields and CALCULATES the price. The base price is $30. Add $10 to the base price for a double blanket, $25 for a queen blanket, and $40 for a king blanket. Also, add $20 for a wool blanket, and $45 for cashmere. In other words, a king-size cashmere blanket costs $115 ($30+ $40 + $45) while a double wool blanket costs $ 60 ($30+ $10$20). Write a method to display all four fields nicely on the screen. Call your code "Blanket.java" b) Create a child class named ElectricBlanket that extends Blanket and includes two additional fields: one for the number of heat settings, and one for whether it has an automatic shut-off. The default values are 1 and false. Write a default constructor and a user-entered constructor. Add $% to the price of the blanket if the does not have automatic shut-off and $10 if

Explanation / Answer

Given below is the code for the question.
To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i
Please do rate the answer if it was helpful. Thank you

Blanket.java
------
enum BlanketSize{ TWIN, KING, QUEEN};
enum BlanketMaterial{COTTON, WOOL, CASHMERE};

public class Blanket {


protected BlanketSize size;
protected int price;
protected String color;
protected BlanketMaterial material;


public Blanket(){
size = BlanketSize.TWIN;
color = "White";
material = BlanketMaterial.COTTON;
price = 30;
}

public Blanket(BlanketSize size, String color, BlanketMaterial material)
{
this.size = size;
this.color = color;
this.material =material;
price = 30;
if(size == BlanketSize.TWIN)
price += 10;
else if(size == BlanketSize.QUEEN)
price += 25;
else if(size == BlanketSize.KING)
price += 40;

if(material == BlanketMaterial.WOOL)
price += 20;
else if(material == BlanketMaterial.CASHMERE)
price += 45;
}

public void display()
{
System.out.println("Blanket Size: "+ size+ ", Color: " + color + ", Material: " + material + ", Price: " + price);
}
}


ElectricBlanket.java
------------

public class ElectricBlanket extends Blanket{
private int numHeatSettings;
private boolean autoShutoff;

public ElectricBlanket(){
super();
numHeatSettings = 1;
autoShutoff = false;
price += 5;
}

public ElectricBlanket(BlanketSize size, String color, BlanketMaterial material, int numHeat, boolean autoOff) {
super(size, color, material);
numHeatSettings = numHeat;
autoShutoff = autoOff;
if(autoShutoff)
price += 10;
else
price += 5;
}

}


BlanketDemo.java
----------

public class DemoBlanket {
public static void main(String[] args) {
Blanket b1 = new Blanket();
Blanket b2 = new Blanket(BlanketSize.KING, "Blue", BlanketMaterial.CASHMERE);
ElectricBlanket b3 = new ElectricBlanket(BlanketSize.QUEEN, "Pink", BlanketMaterial.WOOL, 3, true);
ElectricBlanket b4 = new ElectricBlanket(BlanketSize.TWIN, "Green", BlanketMaterial.COTTON, 2, false);

b1.display();
b2.display();
b3.display();
b4.display();

}
}


output
=====
Blanket Size: TWIN, Color: White, Material: COTTON, Price: 30
Blanket Size: KING, Color: Blue, Material: CASHMERE, Price: 115
Blanket Size: QUEEN, Color: Pink, Material: WOOL, Price: 85
Blanket Size: TWIN, Color: Green, Material: COTTON, Price: 45