java - Error message 'Cannot be resolved or is not a field' -
right i'm studying chain of responsibility design pattern , using eclipse.
and i'm trying compile code, have compiling error "islast cannot resolved or not field":
public class overfive implements discount { private discount next; // public boolean islast = false; public void setnext(discount next, boolean last) { this.next = next; this.next.islast = last; // here error. } public double dodiscount(budget budget) { if (budget.getvalue() > 500) { return budget.getvalue() * 0.10; } if (this.next.islast == false) { return next.dodiscount(budget); } else { return 0; } } }
and now, here interface:
public interface discount { double dodiscount(orcamento orcamento); void setnext(discount next, boolean last); }
here's 1 recommendation: study sun java coding standards , take them heart. you're breaking them in small code sample.
java case sensitive: "discount" not same "discount"; "dodiscount" not same "dodiscount".
public interface discount { double dodiscount(orcamento orcamento); void setnext(desconto next, boolean last); void setlast(boolean last); }
and implementation:
public class overfive implements discount { private desconto next; private boolean last = false; public void setlast(boolean last) { this.last = last; } public void setnext(desconto next, boolean last) { this.next = next; this.setlast(last); } // method utter rubbish. won't compile. public double dodiscount(orcamento budget){ if (budget.getvalue() > 500){ return budget.getvalue() * 0.10; }if (this.next.islast == false){ return next.discount(budget); }else{ return 0; } } }
i think code more little confusing. no wonder you're having problems.
Comments
Post a Comment