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

I have an assignment out of Joyce Farrells Java Programming 7th edition it is nu

ID: 666867 • Letter: I

Question

I have an assignment out of Joyce Farrells Java Programming 7th edition it is number 2 in chapter 10 (Inheritance).

The problem is:

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.

I'm having trouble with setting the price per inch and over riding the price. Is this code available so I can reference it?

Explanation / Answer

// Candle.java

import java.io.*;
import java.util.*;

public class Candle{
public String color;
public double height;
public double price;
// Setting color
public void set_color(String c){
color = c;
}
// Setting height and price
public void set_height(double h){
height = h;
price = 2*h;
}
// return color
public String get_color(){
return color;
}
// return height
public double get_height(){
return height;
}
// return price
public double get_price(){
return price;
}
}


// ScentedCandle.java

import java.io.*;
import java.util.*;

public class ScentedCandle extends Candle{
public String scent;
// Setting value of scent
public void set_cent(String sc){
scent = sc;
}
// return scent
public String get_cent(){
return scent;
}
// set height and price
public void set_height(double h){
height = h;
price = height*3;
}
}

// DemoCandles.java

public class DemoCandles{
public static void main(String[] args){
Candle c = new Candle();
c.set_height(12);
c.set_color("red");

ScentedCandle s = new ScentedCandle();
s.set_color("green");
s.set_height(18);
s.set_cent("Strong freg");

System.out.println(c.get_price()+" "+s.get_price());
}
}

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