Here is my toString() function that lies in the super class. I want to be able to reuse this function in my subclass but modify it to say "Coordinates of Trapezoid" instead of "Coordinates of Quadrilateral".
I've tried using stringbuilder to modify the return value but it didn't work so maybe I'm misusing stringbuilder. Is what I want to do possible or should I just copy/paste the entire method's code into my subclasses method and modify the text there?
public String toString(){ //this function returns a readable view of our quadrilateral object
String message = new String();
message = "Coordinates of Quadrilateral are:\n< " + this.point1.getX() + ", " + this.point1.getY() + " >, < "
+ this.point2.getX() + ", " + this.point2.getY() + " >, < "
+ this.point3.getX() + ", " + this.point3.getY() + " >, < "
+ this.point4.getX() + ", " + this.point4.getY() + " >\n";
return message;
}
Here is my subclass
//this function returns a readable view of our trapezoid
public String toString(){
String modify = super.toString();
StringBuilder sb = new StringBuilder(modify);
sb.replace(16, 28, "Trapezoid");
return modify + "\nHeight is: " + getHeight() + "\nArea is: " + getArea();
}