Question
Use netbens and USE JAVA Project#3: More with Shapes understand inheritance In class, we talked about a Shape class and looked into TwoDimensionalShape objects in
Use netbens and USE JAVA
Project#3: More with Shapes
understand inheritance
In class, we talked about a Shape class and looked into TwoDimensionalShape objects in some detail. Let's go into three dimensions here.
Begin with this simple Shape class. You are NOT permitted to change this class in any way.
import java.lang.String; public class Shape { protected String name; // user-chosen name for the shape public Shape() { // POST: A default Shape is created with name set to an empty string name = ""; } public void SetName(String name) { // PRE: Assigned(name) // POST: class member name has been set to name this.name = name; } public String toString() { // POST: FCTVAL == String representation of Shape object return "Shape " + name; } }
You'll create three classes called ThreeDimensionalShape, Sphere, and Cube. You'll create simple forms of these classes:
Each of these classes should share data for the location of the center (center of mass, let's say) of the shape via x, y, and z coordinates.
Spheres should additionally know their radii.
Cubes should additionally know the length of any edge.
Each class should have a constructor that allows you to set all of its properties. (You only need the initializer constructor. Providing a default constructor is not required and is just extra work for you today, so don't.)
Each should have a toString() method that tells what type of shape and all known information about it.
In the interest of time, do not add additional functionality. Instead, you'll be required to write about additional sensible functionality in your report.
Task 1: Implement the ThreeDimensionalShape, Sphere, and Cube classes.
Task 2: Create a test driver called Lab6Main wherein you create an array of 4 shapes and use all three constructors at least once. Test the toString() methods on these objects. Also, in the interest of time, you may forego comments other than header comments in the test driver (but classes must absolutely be documented).
Report: Create a lab report using the lab report template with your source code (use separate headings for each file) and output from running the test driver. Also, write a short discussion (roughly 4-7 sentences) including (a) what you've learned about inheritance and (b) some additional functions you would find appropriate for these classes. Also draw (hand, PowerPoint, Word, etc.) a inheritance hierarchy and include it in the report.
Note: (1) You must use the class names, including the test driver, indicated in this lab description. (2) Do NOT zip your files. Instead, include them one by one in your drop box (but still only one submission.) Your homework will receive lower grade if you fail to do either one.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started