quick question!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • javatech007
    New Member
    • Nov 2007
    • 51

    #1

    quick question!!

    Hi,
    when I go to compile my program it throws up an error saying:

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


    Is there a common error why this happens??
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by javatech007
    Hi,
    when I go to compile my program it throws up an error saying:

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


    Is there a common error why this happens??
    Sure, most likely you've put statements outside of a method or an initialization
    block but noone can tell for sure because your question was very vague and the
    necessary information you gave was less than vague and incomplete as well.

    Always supply the complete error diagnostic message (copy/paste) and the
    relevant lines of code that caused the error diagnostic. We are not going to guess
    for you.

    kind regards,

    Jos

    Comment

    • javatech007
      New Member
      • Nov 2007
      • 51

      #3
      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

      Comment

      Working...