0

This is a VERY basic program to calculate the area of a circle, triangle, or quadrilateral. The interface we run the program on is STOP, so we can only use numbers to run the program once it is compiled. This is the reason there aren't any strings or anything like that. On to my problem, when I compile this code, I get the following error:

Compile Error--parser failed. token: ( msg: [14,10] expecting: 'true', 'false', 'read', '!', '-', decimal integer literal, identifier

This is the first time I go to calculate the area, and I can't figure out why it's not working. All my previous coding has been in C++, so is the equation written incorrectly for JAVA?

int A, b, h, l, w, r;

int x = 0;

{

while (x != 5)
	{
	x = read();
	
	if (x == 1)
		{
		r = read();
		A = (22 * r * r) / 7;
		write (A);
		}
	if (x == 3)
		{
		b = read();
		h = read();
		A = (b * h) / 2;
		write (A);
		}
	if (x == 4)
		{
		l = read();
		w = read();
		A = l * w;
		write (A);
		}
	}
}
3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by stultuske
0

Well, I'm not sure what you're compiling it with, since that error is certainly not a Java compiler error.

The syntax is passably Java, assuming the presence of read() and write() methods in the class and I don't see any glaring errors with it.

0

it would also come in handy to provide us with all your code, for instance the methods read and write that you use.

maybe a hint : try using switch statements instead of a number of if's, if you know that all the tests are on the same integer.

int test = read();
while(test != 5){
  switch(test){
      case 1: //code to run if it 's one
                 break;
      case 2: // code to run if it's two
                 break;
      default: // code t run if it's none of the above mentioned
  }
  test = read();
}

that would make your code a lot easier to understand, and you don't perform unnecessary if's

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.