This exercise should be used in conjunction with Exercises 1 and 3. Implement a Sphere class with
Question:
This exercise should be used in conjunction with Exercises 1 and 3. Implement a Sphere class with the following features. Declare two instance variables—center (whose type is Point) and radius (whose type is double). Provide a constructor that receives center and radius values and uses them to initialize the two instance variables. Provide a shift method with an offset parameter (an array that holds x, y, and z values) that adjusts the sphere’s position by shifting the sphere’s center point in the directions specified by the passed-in offset. Provide a scale method with a factor parameter (a double) that adjusts the sphere’s radius by multiplying it by the passed-in factor. Implement the shift and scale methods so they support chaining. Provide a describe method that displays
(1) The x, y, and z coordinates for the sphere’s center point and
(2) The sphere’s radius.
Exercise 1:
Implement a Point class with the following features. Declare a position instance variable—an array of doubles that holds the point’s x, y, and z coordinate values. Provide a constructor that receives x, y, and z values and instantiates the position array with those values. Provide a shift method with an offset parameter (an array that holds x, y, and z values) that adjusts the point’s position in the directions specified by the passed-in offset. Implement the shift method so that it supports chaining. Provide an accessor method that returns the point’s position instance variable.
Exercise 3:
Implement a SphereDriver class with a main method that performs the following tasks. Instantiate a Point at x=10, y=15, and z=20. Instantiate a Sphere centered at that point and having a radius of 8. Call that sphere’s describe method. Shift the sphere’s location by +3.0 in the x-direction, −2.5 in the y-direction, and +4.0 in the z-direction. Increase its radius by a factor of 1.5. Then call its describe method again.
Step by Step Answer:
Introduction To Programming With Java A Problem Solving Approach
ISBN: 9781260575248
3rd International Edition
Authors: John Dean