having a problem with a program im working on with inheritance. suppose to output the area, perimeter, and area i think i have it all set up correctly but its not out putting correctly here is the the superclass that inherites to the client form.

public class CIRCLE extends CLIENT
{
    public double radius;
    public double perimeter;
    public double area;

    public CIRCLE(double newRadius, double newPerimeter, double newArea)
    {
        setRADIUS(newRadius);
        setPERIMETER(newPerimeter);
        setAREA(newArea);
    }
    public double getRadius()
    {
        return radius;
    }
    public double getPerimeter()
    {
        return perimeter;
    }
    public double getArea()
    {
        return area;
    }
    public void setRADIUS(double newRadius)
    {
        newRadius = radius;
    }
    public void setPERIMETER(double newPerimeter)
    {
        newPerimeter = 2 * Math.PI * radius;
    }
    public void setAREA(double newArea)
    {
        newArea = Math.PI * Math.pow(radius,2);

    }

}

And here is my CLient...

public class CLIENT 
{

 public static void main(String[] args)
 {
    System.out.println("--------------------");
    CIRCLE cTotal = new CIRCLE (5.0,7.0,2.0);
    System.out.println("Circle = " + cTotal);
 }

}

the output i am getting dosent make since
here it is :

.6.0_30 <Default> - <Default>--------------------

Circle = CIRCLE@addbf1

Process completed.

What is wrong?

well you are trying to print out the object you initiated, first you must call the constructor like you have, then call:

cTotal.setArea();
System.out.println(cTotal.getArea());

I also think your setArea is wrong, it should set the variable for the instance which you called 'area' to the new area not the variable that you pass to it??

The output: CIRCLE@addbf1 is from the default toString() method. Add a toString() method to the CIRCLE class that returns what you want to see printed.

very nice! i got it! just had to add the toString method:

    public String toString()
    {
        return("Radius = "+radius + ",Perimeter = "+perimeter + ",Area = "+area);
    }

and i changes the newRadius = radius to radius = newRadius.

i am now getting:

--------------------
Circle = Radius =5.0,Perimeter =0.0,Area =0.0

Process completed.

I think my equations are wrong. BUT im pretty sure they are right?????!!!!

any thoughts?

thank you very much guys

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.