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

Chapter 8 Given the class Shoe in question one, write the following in class Hig

ID: 3703732 • Letter: C

Question

Chapter 8 Given the class Shoe in question one, write the following in class HighHeel (20 pts) 3. A default constructor which sets height to a default value, and also calls the inherited class's default constructor. A parameterized constructor which takes in values corresponding to the inherited class's instance variables, along with the height. It should make sure to set the values of the instance variables for both the inherited class and this class. Also check for valid values. a. b. c. Override the method printlnfo. This should call the inherited class's printlnfo along with also printing the height. public class HighHeel //don't forget to put something here private int height;//Assumed to be between 2 and 6 inclusively /Put the constructors and overridden method here

Explanation / Answer

1)

package my;

public class Shoe {

private String color;

private String size;

/**

* @return the color

*/

public String getColor() {

return color;

}

/**

* @param color the color to set

*/

public void setColor(String color) {

this.color = color;

}

/**

* @return the size

*/

public String getSize() {

return size;

}

/**

* @param size the size to set

*/

public void setSize(String size) {

this.size = size;

}

public Shoe() {

this.color = "BLACK";

this.size = "9";

}

public Shoe(String color, String size) {

super();

this.color = color;

this.size = size;

}

public String printInfo(){

return "Shoe Details : Color : "+ this.color+"size : "+this.size;

}

}

2)

package my;

import my.Shoe;

public class HighHeel extends Shoe{

private int height;

private int DEFALUT_HEIGHT = 3;

public HighHeel(String color, String size,int height) {

super(color, size);

if(height <2 || height >6 ){

this.height = 3;

}else{

this.height = height;

}

// TODO Auto-generated constructor stub

}

public HighHeel(String color, String size) {

super(color, size);

this.height = 3;

// TODO Auto-generated constructor stub

}

@Override

public String printInfo() {

// TODO Auto-generated method stub

String printInfo= super.printInfo();

printInfo = printInfo + " height : "+ this.height;

return printInfo;

}

}

3)

package my.players;

import my.HighHeel;

public class ShoeTester {

public static void main(String[] args) {

Shoe shoe = new Shoe();

HighHeel h1 = new HighHeel("RED", "7");

HighHeel h2 = new HighHeel("WHITE", "9", 5);

HighHeel h3 = new HighHeel("WHITE", "9", 9);

System.out.println(shoe.printInfo());

System.out.println(h2.printInfo());

System.out.println(h1.printInfo());

System.out.println(h3.printInfo());

}

}