Question: This exercise should be used in conjunction with Exercises 1 and 2. Implement a SphereDriver class with a main method that performs the following tasks.

This exercise should be used in conjunction with Exercises 1 and 2. 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.

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 2:

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.

Step by Step Solution

3.50 Rating (153 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To accomplish this task you need to create three classes Point Sphere and SphereDriver Below is the implementation of these classes in Java To change this license header choose License Headers in Proj... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Introduction To Programming With Java A Problem Solving Approach Questions!