Composition Cube Problems

I have some problems that I do not know what do with.  If anyone could help me that would be great.  I will post all 4 files here and pray someone can help me!  the compositioncube file is the one that I am having problems with, but I may have problems in the other ones as well.  I will post that at the top and the following ones under.

// Compositioncube


public class compositionCube
{
private double depth;
private compositionSquare square;


public compositionCube( double side, int x, int y )
{

      square = new compositionSquare( x, y );
      setDepth( side );

}

//CALCULATE SURFACE AREA
public double area()
{
      return square.area() * 6;

}

//ACCESS FOR DEPTH
public double getDepth()
{
      return depth;

}

//GET SHAPE NAME
public String getName()
{
      return "Cube";
}

//ACCESSOR TO SQUARE'S VALUE FOR AREA
public double getSquareArea()
{

      return square.area();

}

//ACCESSOR TO SQUARE'S NAME
public String getSquareName()
{
      return square.getName();

}

//ACCESSOR TO SQUARE'S ACCESSOR TO POINT'S NAME
public String getSPointName()
{
         //REMEMBER THE OBJECT square HAS ACCESS TO
         //THE getPointName MEHTOD IN THE CLASS CompositionSquare
}

//ACCESSOR TO SQUARE'S ACCESSOR TO POINT'S STRING VALUE
public String getSPointString()
{
         //REMEMBER THE OBJECT square HAS ACCESS TO
         //THE getPointString MEHTOD IN THE CLASS CompositionSquare
}

//ACCESSOR TO SQUARE'S STRING VALUE
public String getSquareString()
{
      return square.toString();

}

//RETURN A STRING DESCRIBING THE CUBE
public String toString()
{
return square.toString() + "; Depth = " + depth;
}

//CALCULATE VOLUME
public double volume()
{
return square.area() * depth;
}
}


********
// Compositionpoint

public class compositionPoint
{
private int x, y;

public compositionPoint( int xCoordinate, int yCoordinate )
{
setPoint( xCoordinate, yCoordinate );
}

public String getName()
{
return "Point";
}

public int getX()
{
return x;
}

public int getY()
{
return y;
}

public void setPoint( int xCoordinate,
int yCoordinate )
{
x = xCoordinate;
y = yCoordinate;
}

public String toString()
{
return "[" + x + ", " + y + "]";
}
}

*******
// Compositionsquare



public class compositionSquare
{
private double side;


private compositionPoint point;


public compositionSquare()
{

this( 0.0, 0, 0 );
}

public compositionSquare( double length, int x, int y )
{

      point = new compositionPoint( x, y );

      setSide( length );
}

//CALCULATES THE AREA OF THE SQUARE
public double area()
{
return side * side;
}

//GET SHAPE NAME
public String getName()
{
return "Square";
}

//THE FOLLOWING TWO METHODS ACCESS POINT'S DATA
public String getPointName()
{
return point.getName();
}

//ACCESSOR TO POINT'S STRING VALUE
public String getPointString()
{
return point.toString();
}

//GET SIDE
public double getSide()
{
return side;
}

//ERROR-CHECKS THEN SETS THE SIDE LENGTH
public void setSide( double length )
{
side = ( length >= 0 ? length : 0 );
}

public String toString()
{
return "Corner = " + point.toString() +
"; Side = " + side;
}
}

*******
// Compositiontest

import java.text.DecimalFormat;

import javax.swing.*;

public class compositionTest
{
//TEST CLASSES POINT, SQUARE AND CUBE
public static void main( String args[] )
{

compositionCube cube = new compositionCube( 3.3, 10, 10 );

DecimalFormat precision2 = new DecimalFormat( "0.00" );

String result = "";

result += "\n" + cube.getSPointName() + ": " + cube.getSPointString();

result += "\n" + cube.getSquareName() + ": " + cube.getSquareString();

result += "\n" + "Area of Square = " + precision2.format( cube.getSquareArea() );

result += "\n" + cube.getName() + ": " + cube.toString();

result += "\n" + "Surface Area of Cube = " + precision2.format( cube.area() );

result += "\n" + "Volume of Cube = " + precision2.format( cube.volume() );

JOptionPane.showMessageDialog( null, result, "Shapes",
JOptionPane.INFORMATION_MESSAGE );

System.exit( 0 );
}
}
brassmonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

imladrisCommented:
It might be more efficient if you indicated what problems you are having. Won't compile? Won't run? Runs but gives wrong results? Don't understand?
0
imladrisCommented:
Also, including at least some of any error messages you are getting (if you are) would be helpful.
0
jimmackCommented:
First problems:

It doesn't compile (for the following reasons):

1) In the compositionCube constructor, you are creating a compositionSquare, but this class doesn't have a constructor that only takes two ints.

2) Again the the compositionCube constructor, this class doesn't have a setDepth method.

        depth = side;

3) Same class.  getSPointName() and getSPointString() don't return anything.

I tried some fixes as follows:

1) and 2) Modified the constructor of compositionCube to:

    public compositionCube(double side, int x, int y)
    {
//        square = new compositionSquare(x, y);
//        setDepth(side);
        square = new compositionSquare(side, x, y);
        depth = side;
    }

3) Returned "Dummy" from each of the two methods.

The result was a window, titled "Shape" displaying:

Dummy:Dummy

Square: Corner = [10, 10]; Side = 3.3

Area of Square = 10.89

Cube: Corner = [10, 10]; Side = 3.3; Depth = 3.3

Surface Area of Cube = 65.34

Volume of Cube = 35.94

Is this what you expect?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jimmackCommented:
If I go one step further and include the code that is implied in the comments of the getSPoint... methods, like so:

    public String getSPointName()
    {
        //REMEMBER THE OBJECT square HAS ACCESS TO
        //THE getPointName MEHTOD IN THE CLASS CompositionSquare
        return (square.getPointName());
    }

    public String getSPointString()
    {
        //REMEMBER THE OBJECT square HAS ACCESS TO
        //THE getPointString MEHTOD IN THE CLASS CompositionSquare
        return (square.getPointString());
    }

The first line in the dialog changes from "Dummy:Dummy" to "Point: [10, 10]"

Again, I have no way of knowing if this is what you actually want.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.