Ask your own question, for FREE!
Computer Science 14 Online
OpenStudy (anonymous):

Find cube of a variable by using a class cube and calling it by pointer argument?

OpenStudy (e.mccormick):

How far did you get and in what language?

OpenStudy (anonymous):

For Java the class could be constructed as follows, you can reference the class in your mainline code and use a pointer to call it and return the value. Hope this helps. public class Cube { private double depth; // Cube's depth private Square square; // no-argument constructor public Cube() { square = new Square( 0, 0, 0 ); depth = 0; } // constructor with arguments public Cube( int xValue, int yValue, double sideValue ) { square = new Square( xValue, yValue, sideValue ); setDepth( sideValue ); } // set Cube's depth public void setDepth( double depthValue ) { depth = ( depthValue < 0.0 ? 0.0 : depthValue ); } // get Cube's depth public double getDepth() { return depth; } // set x public void setX( int x ) { square.setX( x ); } // return x public int getX() { return square.getX(); } // set y public void setY( int y ) { square.setY( y ); } // return y public int getY() { return square.getY(); } // set side length public void setSideLength( double lengthValue ) { square.setSideLength( lengthValue ); } // return side length public double getSideLength() { return square.getSideLength(); } // calculate Cube area public double getArea() { return 6 * square.getArea(); } // calculate Cube volume public double getVolume() { return square.getArea() * getDepth(); } // return String representation of Cube object public String toString() { return square.toString() + "; Depth = " + getDepth(); } } // end class Cube

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!