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

Simple Container Classes Requirements: ? A general Container class that your oth

ID: 3710237 • Letter: S

Question

Simple Container Classes

Requirements:

? A general Container class that your other classes will inherit from.

? Three different more specific containers that will define their own, more specialized, attributes.

? A toString method to make printing your objects more consistent across all your classes. Be sure to make use of method overriding in your subclasses.

? Make sure that there is a recognizable additional specification created.

For this assignment we will be making use of inheritance to keep from having to redefine many of the common attributes associated with different types of containers. You will be defining a general Container class that will have the common attributes of all types of containers and then you need to define three different types of containers (there are many types of containers, however, some examples may be boxes, bottles, drawers, etc).

At a minimum, you should define the material the container is made of, the color of it, whether it is filled or not, what it is filled with, how much of that it is filled, and a toString method to create a String version of your object for printing. Additionally, define a subclass of one of your subclasses to be an even more specialized version of it.

Explanation / Answer

Container.java

public abstract class Container {

private String madeOf;

private String color;

private boolean isFilled;

private String filledWithWhat;

private double FilledPercentage;

public Container(String madeOf, String color, boolean isFilled, String filledWithWhat, double filledPercentage) {

this.madeOf = madeOf;

this.color = color;

this.isFilled = isFilled;

this.filledWithWhat = filledWithWhat;

FilledPercentage = filledPercentage;

}

public String getMadeOf() {

return madeOf;

}

public void setMadeOf(String madeOf) {

this.madeOf = madeOf;

}

public String getColor() {

return color;

}

public void setColor(String color) {

this.color = color;

}

public boolean isFilled() {

return isFilled;

}

public void setFilled(boolean isFilled) {

this.isFilled = isFilled;

}

public String getFilledWithWhat() {

return filledWithWhat;

}

public void setFilledWithWhat(String filledWithWhat) {

this.filledWithWhat = filledWithWhat;

}

public double getFilledPercentage() {

return FilledPercentage;

}

public void setFilledPercentage(double filledPercentage) {

FilledPercentage = filledPercentage;

}

@Override

public String toString() {

return "Container [madeOf=" + madeOf + ", color=" + color + ", isFilled=" + isFilled + ", filledWithWhat="

+ filledWithWhat + ", FilledPercentage=" + FilledPercentage + "]";

}

}

Box.java

public class Box extends Container {

private String shape;

private double volume;

public Box(String madeOf, String color, boolean isFilled, String filledWithWhat, double filledPercentage,

String shape, double volume) {

super(madeOf, color, isFilled, filledWithWhat, filledPercentage);

this.shape = shape;

this.volume = volume;

}

public String getShape() {

return shape;

}

public void setShape(String shape) {

this.shape = shape;

}

public double getVolume() {

return volume;

}

public void setVolume(double volume) {

this.volume = volume;

}

@Override

public String toString() {

return "Box [shape=" + shape + ", volume=" + volume + ", getMadeOf()=" + getMadeOf() + ", getColor()="

+ getColor() + ", isFilled()=" + isFilled() + ", getFilledWithWhat()=" + getFilledWithWhat()

+ ", getFilledPercentage()=" + getFilledPercentage() + "]";

}

}

Bottle.java

public class Bottle extends Container {

private String capactity;

public Bottle(String madeOf, String color, boolean isFilled, String filledWithWhat, double filledPercentage,

String capactity) {

super(madeOf, color, isFilled, filledWithWhat, filledPercentage);

this.capactity = capactity;

}

public String getCapactity() {

return capactity;

}

public void setCapactity(String capactity) {

this.capactity = capactity;

}

@Override

public String toString() {

return "Bottle [capactity=" + capactity + ", getMadeOf()=" + getMadeOf() + ", getColor()=" + getColor()

+ ", isFilled()=" + isFilled() + ", getFilledWithWhat()=" + getFilledWithWhat()

+ ", getFilledPercentage()=" + getFilledPercentage() + ", toString()=" + super.toString() + "]";

}

}

Drawer.java

public class Drawer extends Container {

private boolean containKey;

public Drawer(String madeOf, String color, boolean isFilled, String filledWithWhat, double filledPercentage,

boolean containKey) {

super(madeOf, color, isFilled, filledWithWhat, filledPercentage);

this.containKey = containKey;

}

public boolean isContainKey() {

return containKey;

}

public void setContainKey(boolean containKey) {

this.containKey = containKey;

}

@Override

public String toString() {

return "Drawer [containKey=" + containKey + ", getMadeOf()=" + getMadeOf() + ", getColor()=" + getColor()

+ ", isFilled()=" + isFilled() + ", getFilledWithWhat()=" + getFilledWithWhat()

+ ", getFilledPercentage()=" + getFilledPercentage() + ", toString()=" + super.toString() + "]";

}

}

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