Java Help Please!!!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • javatech007
    New Member
    • Nov 2007
    • 51

    Java Help Please!!!

    The question is below and it is the only one I cant for a project due tomarrow.

    Question.
    Write a class called shapes that accepts two variables into its constructor called a and b. Along with the getter and setter methods required, write a method called toPrinter() to output the coordinates of the shape in the following format: [a, b].
    Next write a class called orange that is a child class of shapes. This time the constructor accepts in a, b (centre of the orange), and a radius. Override the toPrinter() method in the orange class to include outputting the radius, as well as a and b. Write a method to get the area of the orange. Include any relevant classes to run and test the application.

    I can do the first part but not the second.

    This is what I have so far.

    Code: ( Java )

    class Shapes
    {
    public static void main(String[] args)
    {

    Shapes x = new Shapes(5,6);

    x.toPrinter();

    }

    protected double a;
    protected double b;



    public Shapes(double a, double b)
    {
    this.a = a;
    this.b = b;
    }


    public double geta()
    {
    return a;
    }

    public double getb()
    {
    return b;
    }



    protected void seta(double ia)
    {
    a = ia;
    }

    protected void setb(double ib)
    {
    b = ib;
    }




    void toPrinter()
    {
    System.out.prin tln("The coordinates are [" + a +","+ b + "]");
    }


    }


    class Orange extends Shapes
    {
    Orange y = new Orange(a,b,7);

    y.area();
    y.toPrinter();


    private double radius;
    private double area;

    public Orange (double a, double b, double radius)

    {
    super(a,b);
    this.radius = radius;
    }

    void area()
    {
    this.area = (3.14) *(radius) * (radius);
    }

    void toPrinter()
    {
    System.out.prin tln("The coordinates are [" + a +","+ b + "]");
    System.out.prin tln("The radius is " + radius);
    System.out.prin tln("The area is " + area);
    }



    public double getradius()
    {
    return radius;
    }

    public double getarea()
    {
    return area;
    }



    protected void setradius(doubl e iradius)
    {
    radius = iradius;
    }

    protected void setarea(double iarea)
    {
    area = iarea;
    }


    }


    // the orange class is on a seperate java file. when i go to compile it, an error shows up saying:

    Orange.java:5: <identifier> expected
    y.area();

    Orange.java:6: <identifier> expected
    y.toPrinter();
    ^
    2 errors

    (/Java)
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Don't open multiple threads for one single problem; I close this thread and
    answer your question in your other thread first thing in the (my) morning; it's late
    overhere. And when you post a question think of a reasonable topic title. Your
    current title is simply immature.

    kind regards,

    Jos

    Comment

    Working...