X814: Cloning 3 Complex Deep Copy

For the following question assume the following class definition of Ball and of NewClass:

public class Ball {
        private double diameter;
        private String color;
        private boolean isInflatable;

        public Ball(double d, String c, boolean inf) {
            diameter = d;
            color = c;
            isInflatable = inf;
        }

        public double getDiameter() {
            return diameter;
        }

        public String getColor() {
            return color;
        }

        public boolean getIsInflatable() {
            return isInflatable;
        }
public static class NewClass {
        private Ball variable1;
        private String[] variable2;
        private double variable3;

        public NewClass(Ball v1, String[] v2, double v3) {
            variable1 = v1;
            variable2 = v2;
            variable3 = v3;
        }


        public Ball getVariable1() {
            return variable1;
        }


        public String[] getVariable2() {
            return variable2;
        }


        public double getVariable3() {
            return variable3;
        }


        public void setVariable1(Ball variable1) {
            this.variable1 = variable1;
        }


        public void setVariable2(String[] variable2) {
            this.variable2 = variable2;
        }


        public void setVariable3(double variable3) {
            this.variable3 = variable3;
        }

    }// end NewClass

For this question, write a method that will take in an object of type NewClass and return a deep copy of that object. Note: you may want to make separate helper methods for this question to help create deep copies of each of NewClass' fields.

Your Answer:

Reset

Practice a different Java exercise

Feedback

Your feedback will appear here when you check your answer.