Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Driver class to Test Your Shape Hierarchy 1. Create one object of each concrete class - using the data given below - and

Write a Driver class to Test Your Shape Hierarchy 1. Create one object of each concrete class - using the data given below - and store them in an array of Shapes. Programming Assignment #5 (Inheritance and Polymorphism) I. Create a Point3D Class Create a class to represent a point in Three-Dimensional space. This class will have private int instance variables x, y, and z, to store the coordinates of the point, a constructor, an overridden toString() method to return the coordinates as a String, and get" methods that return the values of each of the instance variables. The data can be "hardwired" into the code, no need for user input - too many input values 2. Using a loop, traverse the array and print the following information only for each object - the actual class of the shape (Sphere, Cone, etc), all the input data, and the surface area 3. Sort the array in descending order by volume. To get credit, this must be done via a call to a sort method of the Arrays class. No credit for sorting ascending and then reversing the array II. Define an Abstract class to Represent a 3-D Shape Your Shape 3D class must meet these specifications: 1. has a private instance variable of class Point3D "member object") that stores the center of the shape (aka: a 4. Using a loop, print ONLY the class name and volume for each object in the sorted array. 5. Sort the array again, but this time in ascending order by the distance from the origin. To earn credit, this must be done via a call to a sort method of the Arrays class. Hint: create a class that implements java's Comparator interface. 6. Using a loop, print ONLY the class name and distance from the origin for each object in the sorted array. For maximum credit, this member object should be created in the Shape 3D constructor. I.e., the implementation of the center should be "hidden" from the client code (the test class) and....also from all subclasses. (See CompositionDemo.java) Test Data to be Used 2. overrides toString() to return a string containing the coordinates of the center (hint: call the toString() method of the Point3D class) 3. has a concrete method that computes and returns the distance of the center of the shape from the origin (i.e., point 0,0,0) 4. has abstract methods that compute and return the surface area and the volume of a shape 5. implements Java's Comparable interface so that Shape objects are ordered by volume, descending Sphere: Center at (2,5,8), radius of 14 Cone: Center at (-5,4,-1), radius 11, height 15 Cylinder: Center at (3,7,-5), radius 12, height 14 Parallelepiped: Center at (7,16,9), length 19, width 9, height 13 VI. Formulae The distance of a point in 3D space from point (0,0,0) is the hypotenuse of a right triangle where the adjacent sides have lengths of z, and sqrt (x + y), as shown in class. Sphere: area = 4 II r volume = III. Derive Concrete Subclasses for Sphere, Parallelepiped, Cylinder, and Cone Shapes The constructor for each of these classes takes parameters for the x, y, and z coordinates of the center. In addition, the Sphere constructor takes the radius, the Parallelepiped constructor the length, width, and height, the Cone constructor the height and radius, and the Cylinder constructor the radius and height 4 3 I r Cylinder: volume = [1 r2 h area = 2 11 r2 + 2 Orh volume = [1 r2 h Cone: area = [1 r(r + s) 2. Since these are concrete classes, each must implement the abstract methods of the superclass that compute and return the surface area and the volume where s (the slant height) = 1 r2 + h2 3. Each class will also override toString to return a string containing the class name, coordinates of the center, and the other data values (radius, length, width, etc.) Parallelepiped: AKA a "right rectangular prism, it's a box, like a shoe box. Figure it out.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Linear Algebra And Its Applications

Authors: David Lay, Steven Lay, Judi McDonald

6th Global Edition

978-1292351216, 1292351217

More Books

Students also viewed these Programming questions