-4

Right. So I'm working on a program for my class and I've come across an area. I did a search and found a few threads on this problem, but none of them seemed to be able to resolve my problem so here I am. The point of the program is to ask the user what type of question they want answered and to have them provide information. With the information gathered, it calls the proper method that does the calculations.

Here is the error that I'm getting:

Geometry.java:9: error: <identifier> expected
public static void circleArea(radius);
                                   ^
Geometry.java:14: error: <identifier> expected
public static void rectangleArea(length, width);
                                      ^
Geometry.java:14: error: <identifier> expected
public static void rectangleArea(length, width);
                                             ^
Geometry.java:19: error: <identifier> expected
public static void triangleArea(height, base);
                                     ^
Geometry.java:19: error: <identifier> expected
public static void triangleArea(height, base);
                                           ^
Geometry.java:24: error: <identifier> expected
public static void circleCircumfrence(radius);
                                           ^
Geometry.java:29: error: <identifier> expected
public static void rectanglePerimeter(length, width);
                                           ^
Geometry.java:29: error: <identifier> expected
public static void rectanglePerimeter(length, width);
                                                  ^
Geometry.java:34: error: <identifier> expected
public static void trianglePerimeter(side1, side2, side3);
                                         ^
Geometry.java:34: error: <identifier> expected
public static void trianglePerimeter(side1, side2, side3);
                                                ^
Geometry.java:34: error: <identifier> expected
public static void trianglePerimeter(side1, side2, side3);
                                                       ^
11 errors

Everything else works and I have my variables defined and what not. Here are the methods created (as per my instructors instructions, the methods are to be as void's):

public static void circleArea(radius);
{
 circArea = Math.PI * Math.pow(radius, 2);
 return circArea;
}
public static void rectangleArea(length, width);
{
  rectArea = (length * width);
  return rectArea;
}
public static void triangleArea(height, base);
{
  triArea = (.05 * base * height);
  return triArea;
}
public static void circleCircumfrence(radius);
{
  circCircum = 2 * (Math.PI * radius);
  return circCircum;
}
public static void rectanglePerimeter(length, width);
{
  rectPeri = (2 * length) + (2 * width);
  return rectPeri;
}
public static void trianglePerimeter(side1, side2, side3);
{
  triPeri = (side1 + side2 + side3);
  return triPeri;
}
WillBro
  • 147
  • 4
  • 16

2 Answers2

2

Your parameters don't have types - give them types.
Your methods don't have return types - give them return types if they return values.

Eg change:

public static void circleArea(radius)

to

public static double circleArea(double radius)

Finally, give the methods a body (remove the semi-colon):

public static double circleArea(double radius) {
    return Math.PI * Math.pow(radius, 2);
}

And no need for a local variable either - just clutters up the code.

Bohemian
  • 412,405
  • 93
  • 575
  • 722
  • Instructor said: methods need to be `void`. – WonderWorld Feb 24 '14 at 01:52
  • 1
    I think the "instructor" needs instructing. The whole exercise shows very poor design. There should be an abstract Shape class (or interface) with an abstract `area()` method and concrete classes should override it. If possible, find another (good) instructor. – Bohemian Feb 24 '14 at 02:12
0
  • You need to provide the variable type in formal parameters. Example:

    // Substitute int with a more appropriate data type
    public static void circleArea(int radius) 
    
  • You shouldn't have semi-colons in between your method signature and method body.

  • You can't return anything from a void method either. You can either change the return type of your method or store the calculated value in a variable inside your class and implement a getter to retrieve the value.
PakkuDon
  • 1,627
  • 4
  • 22
  • 21