java - Syntax error, telling me it wants ; and several other things -


just trying run through code assignment i'm doing. simple life of me can't figure out why above error @ first line

(public waterlog.......).  

later want pass line:

[ log = new waterlog(8, damcapacity); ] 

any appreciated, new sorry.

public class waterlog(integer windowsize, integer maxentry) {  private integer size = windowsize; private integer max = maxentry; private arraylist thelog(int windowsize); private int counter = 0;   public void addentry(integer newentry) throws simulationexception {      thelog.add(0, newentry);     counter++;  }  public integer getentry(integer index) throws simulationexception {      if (thelog.isempty() || thelog.size() < index) {         return null;     }     return thelog.get(index);  }  public integer variation() throws simulationexception {      int old, recent = 0;     recent = thelog.get(0);     old = thelog.get(thelog.size-1);     return recent-old; }  public integer numentries() {      return counter;  }  } 

assuming simulationexception defined correctly:

class waterlog{  private integer size; private integer max ; private arraylist<integer> thelog; //parameterize lists private int counter = 0;  public waterlog(integer windowsize, integer maxentry) //this behavior    looking { this.size = windowsize; this.max = maxentry; thelog = new arraylist<integer>(windowsize); }  public void addentry(integer newentry) throws simulationexception {  thelog.add(0, newentry); counter++;  }  public integer getentry(integer index) throws simulationexception {  if (thelog.isempty() || thelog.size() < index) { //java case sensitive     return null; } return thelog.get(index);  }  public integer variation() throws simulationexception {  int old, recent = 0; recent = thelog.get(0); old = thelog.get(thelog.size()-1); //again, watch case, size method return recent-old; }  public integer numentries() {  return counter;  }  } 

see comments added.

edit: explain bit further going on, let's take @ doing.

public class waterlog(integer windowsize, integer maxentry) {  private integer size = windowsize; private integer max = maxentry; private arraylist thelog(int windowsize); private int counter = 0; 

you seem have confused class constructor. variables defined attributes, correct. needed use syntax showed in answer create constructor. same reason, don't have access variables windowsize. remedy this, allow them still defined outside constructor, assigned values inside it, have access windowsize , maxentry.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -