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

Write an application that creates on object of each class Circle, Square, Sphere

ID: 3628570 • Letter: W

Question

Write an application that creates on object of each class Circle, Square, Sphere, and Cube, invoke their toString methods. The output should show the is-a relationship between that object's class and it's superclasses.

I have written eight applications and a program to satisfy this question. I am having problems calling the toString methods to display the output of the program or test. I need help with invoking multiple toString methods in one application. I have one out put and that output is from the Shape(super class). Can you help me?

// File name: Circle.java
// Programmer Name: Barbara A. Parson
// Class: IS 207
// Lab No: 1
// Exercise No: Coding Exercises 1, 2, 3.
// Brief Description of Project: Create object of the
// class Circle, Square, Sphere, and Cube, and invoke
// toString methods.

public class Circle extends TwoDimensionalShape
{
// set variable "name"
String name = "Circle";

// get name "value"
public String getName()
{
return name;
} // end method getName()

// return String representation of Shape object
public String toString()
{
return String.format( "%s is a %s", this.name, super.toString() );
}

} // end class Circle
// File name: Square.java
// Programmer Name: Barbara A. Parson
// Class: IS 207
// Lab No: 1
// Exercise No: Coding Exercises 1, 2, 3.
// Brief Description of Project: Create object of the
// class Circle, Square, Sphere, and Cube, and invoke
// toString methods.

public class Square extends TwoDimensionalShape
{
// set variable "name"
String name = "Square";

// get name "value"
public String getName()
{
return name;
} // end method getName()

// return String representation of Shape object
public String toString()
{
return String.format( "%s is a %s", this.name, super.toString() );
}

} // end class Square
// File name: ShapeTest.java
// Programmer Name: Barbara A. Parson
// Class: IS 207
// Lab No: 1
// Exercise No: Coding Exercises 1, 2, 3.
// Brief Description of Project: Create object of the
// class Circle, Square, Sphere, and Cube, and invoke
// toString methods.

public class ShapeTest
{
public static void main( String[] args )
{
Shape shape = new Shape();

System.out.printf( "%s %s %s %s %s %s %s %s",
shape.toString() );
} // end of main method
} // end of ShapeTest
// File name: Sphere.java
// Programmer Name: Barbara A. Parson
// Class: IS 207
// Lab No: 1
// Exercise No: Coding Exercises 1, 2, 3.
// Brief Description of Project: Create object of the
// class Circle, Square, Sphere, and Cube, and invoke
// toString methods.

public class Sphere extends ThreeDimensionalShape
{
// set variable "name"
String name = "Sphere";

// get name "value"
public String getName()
{
return name;
} // end method getName()

// return String representation of Shape object
public String toString()
{
return String.format( "%s is a %s", this.name, super.toString() );
}

} // end class Sphere
// File name: Cube.java
// Programmer Name: Barbara A. Parson
// Class: IS 207
// Lab No: 1
// Exercise No: Coding Exercises 1, 2, 3.
// Brief Description of Project: Create object of the
// class Circle, Square, Sphere, and Cube, and invoke
// toString methods.

public class Cube extends ThreeDimensionalShape
{
// set variable "name"
String name = "Cube";

// get name "value"
public String getName()
{
return name;
} // end method getName()

// return String representation of Shape object
public String toString()
{
return String.format( "%s is a %s", this.name, super.toString() );
}

} // end class Cube
// File name: TwoDimensionalShape.java
// Programmer Name: Barbara A. Parson
// Class: IS 207
// Lab No: 1
// Exercise No: Coding Exercises 1, 2, 3.
// Brief Description of Project: is-a relatonship

public class TwoDimensionalShape extends Shape
{
// set variable "name"
String name = "Two Dimensional Shape";

// get name "value"
public String getName()
{
return name;
} // end method getName()

// return String representation of Shape object
@Override
public String toString()
{
return String.format( "%s is a %s", this.name, super.toString() );
}

} // end class TwoDimensionalShape
// File name: ThreeDimensionalShape.java
// Programmer Name: Barbara A. Parson
// Class: IS 207
// Lab No: 1
// Exercise No: Coding Exercises 1, 2, 3.
// Brief Description of Project: is-a relationship

public class ThreeDimensionalShape extends Shape
{
// set variable "name"
String name = "Three Dimensional Shape";

// get name "value"
public String getName()
{
return name;
} // end method getName()

// return String representation of Shape object
@Override
public String toString()
{
return String.format( "%s is a %s", this.name, super.toString() );
}

} // end class ThreeDimensionalShape
// File name: Shape.java
// Programmer Name: Barbara A. Parson
// Class: IS 207
// Lab No: 1
// Exercise No: Coding Exercises 1, 2, 3.
// Brief Description of Project: is-a relationship

public class Shape
{
// set variable "name"
String name = "Shape";

// get name "value"
public String getName()
{
return name;
} // end method getName()

// return String representation of Shape object
public String toString()
{
return String.format( "%s is the superclass.", this.name );
}

} // end class Shape

Explanation / Answer

public static void main(String[] args)
{
      //create on object of each class Circle, Square, Sphere, and Cube
      Shape circle = new Circle();
      Shape square = new Square();
      Shape sphere = new Sphere();
      Shape cube = new Cube();


      // print each object
      System.out.println(circle); // printing circle automatically calls circle.toString()
      System.out.println(square):
      System.out.println(sphere);
      System.out.println(cube);
}

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