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

Mick’s Wicks makes candles in various sizes. Create a class for the business nam

ID: 3768020 • Letter: M

Question

Mick’s Wicks makes candles in various sizes. Create a class for the business named Candle that contains data fields for color, height, and price. Create get methods for all three fields. Create set methods for color and height, but not for price. Instead, when height is set, determine the price as $2 per inch. Create a child class named ScentedCandle that contains an additional data field named scent and methods to get and set it. In the child class, override the parent’s setHeight() method to set the price of a ScentedCandle object at $3 per inch. Write an application that instantiates an object of each type and displays the details. Save the files as Candle.java, ScentedCandle.java, and DemoCandles.java.

Explanation / Answer

Here,I given are the program and commenting properly to understanding the program.

public class Candle {

public int color;                       //Declaring of Variables

public int height;

public int price;

Candle(int startColor, int startHeight, int startPrice) {    //initialize Constructor

    color = startColor;

    height = startHeight;

    price = startPrice;

}

public static int getColor() //Public methods for color

{

     return color;

}

public void setColor(int color)

{

     Candle.color = color;

}

public static int getHeight()     //Public methods for height

  

{

     return height;

}

public void setHeight(int height)

{

     Candle.height = height;

}

public static int getPrice()          //Public methods for price

{

     return price;

}

public void setPrice(int price)

{

     Candle.price = height *2;

   }

}

public class ScentedCandle extends Candle {                 //Creating subclass Candle

public int scent;                                       //Delcaring Variable of subclass

public ScentedCandle(int startScent,int startColor, int startHeight,int startPrice)

{     

    super(startColor, startHeight, startPrice);      //Calling from parentclass Candle

       scent = startScent;

}  

public void int getScent()                                   //Public methods

{

      return scent;

}

public void setScent(int scent)

{

      ScentedCandle.scent = scent;

}

public void int getPrice()

{

      return price;

}

   @Override

public void setPrice(int price)

{

      Candle.price = 3 * height;

}

}

public class DemoCandles {

public static void main(String[] args) {

  Candle Can = new Candle(int Color, int Height, int Price) // initialize object

Candle getColor;                       //Declaring Variables

    Candle getHeight;

    Candle getPrice;

    ScentedCandle getScent;

getColor = new Candle();

    getHeight = new Candle();

    getPrice = new Candle();

    getScent = new ScentedCandle();

}

}

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