Mick’s Wicks makes candles in various sizes. Create a class for the business nam
ID: 3768981 • 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
public class Candle { public static int color; //Declaring Variables public static int height; public static int price; Candle(int startColor, int startHeight, int startPrice) { //Constructor color = startColor; height = startHeight; price = startPrice; } public static int getColor() //Public methods { return color; } public void setColor(int color) { Candle.color = color; } public static int getHeight() { return height; } public void setHeight(int height) { Candle.height = height; } public static int getPrice() { return price; } public void setPrice(int price) { Candle.price = 2 * height; } } public class ScentedCandle extends Candle { //Creating subclass to superclass Candle public static int scent; //Delcare Variable public ScentedCandle(int startScent,int startColor, int startHeight,int startPrice) { //Constructor super(startColor, startHeight, startPrice); //Calling from superclass Candle scent = startScent; } public static int getScent() //Public methods { return scent; } public void setScent(int scent) { ScentedCandle.scent = scent; } public static int getPrice() { return price; } @Override public void setPrice(int price) { Candle.price = 3 * height; } } public class DemoCandles { //Here is where I'm lost and have no clue public static void main(String[] args) { Candle getColor; //Declaring Variables Candle getHeight; Candle getPrice; ScentedCandle getScent; getColor = new Candle(); getHeight = new Candle(); getPrice = new Candle(); getScent = new ScentedCandle(); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.