Circle Jack Code

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Circle Jack Code

advaith_dm
This post was updated on .
The following code is the JACK code I have been working to implement drawing of a circle in CPEU emulator:
class Main{
  var int x,y;
  var int r;

  constructor Main(){
  let x=7;
  let y=7;
  let r=3;
  do draw(x,y,r);
  return this;
  }

  function void draw(int cx, int cy, int r) {
  var int dx, dy;
  var int r_squared;
  let dy=-r;
  let r_squared = r*r;
  while(dy<r)
  {
    let dx = Math.sqrt(r_squared-(dy*dy));
    do Screen.drawLine(cx-dx,cy+dy,cx+dx,cy+dy);
    let dy = dy+1;
  }

  return;
}
}



I m getting the following error:
In Main.jack (line 2): Expected }
In Main.jack (line 2): Expected end-of-file
I don't see any areas where my code is wrong but for some reason, I still get this error, please help
Reply | Threaded
Open this post in threaded view
|

Re: Circle Jack Code

Gerrit0
class Main{
  var int x,y;
  var int r;
Look very closely at these lines. What does var mean in a class definition?
Reply | Threaded
Open this post in threaded view
|

Re: Circle Jack Code

advaith_dm
Isnt it the varibale declaration syntax in JACK Language ????!!!!!
Reply | Threaded
Open this post in threaded view
|

Re: Circle Jack Code

Gerrit0
Yes, it is a local variable declaration... but classes don't have local variables, what do they have instead?
Reply | Threaded
Open this post in threaded view
|

Re: Circle Jack Code

WBahn
Administrator
In reply to this post by Gerrit0
The Main class does not have a constructor. It must have a function named main(). See Section 9.2.2. It isn't made explicit, but main() should take no arguments and shouldn't return anything (i.e., be a void function).