I for the love of me cannot see what is wrong with my code while using getters and setters. I have a fuelamount class which makes a fuelcounter which is supposed to keep going down.However the setfuel doesnt seem to be working here.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | public class FuelAmount extends Actor { private int fuelcounter= 5 ; int fuelwidth= 10 ; int fuelheight= 100 ; int pixelperfuel=( int )fuelheight/fuelcounter; public FuelAmount() { //update(); } public void act() { setImage( new GreenfootImage( "Fuel Tank:" +getfuel(), 32 ,Color.RED, new Color( 0 , 0 , 0 , 0 ))); } public void update() { setImage( new GreenfootImage(fuelwidth,fuelheight)); GreenfootImage myImage=getImage(); myImage.setColor(Color.WHITE); myImage.drawRect( 0 , 0 ,fuelwidth+ 1 ,fuelheight+ 1 ); myImage.setColor(Color.RED); myImage.fillRect( 1 , 1 ,fuelwidth,fuelcounter*pixelperfuel); } public int getfuel(){ return fuelcounter; } public void setfuel( int fc){ this .fuelcounter=fc; } } |
1 2 3 4 5 | public void act(){ millisec++; if (millisec% 100 == 0 ){ FA.setfuel(FA.getfuel()- 1 ); } |
1 2 3 4 5 | public void act(){ millisec++; if (millisec% 100 == 0 ){ FA.setfuel(FA.getfuel()- 1 ); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | public class FuelAmount extends Actor { private int fuelcounter= 5 ; int fuelwidth= 10 ; int fuelheight= 100 ; int pixelperfuel=( int )fuelheight/fuelcounter; public FuelAmount() { //update(); } public void act() { setImage( new GreenfootImage( "Fuel Tank:" +getfuel(), 32 ,Color.RED, new Color( 0 , 0 , 0 , 0 ))); } public void update() { setImage( new GreenfootImage(fuelwidth,fuelheight)); GreenfootImage myImage=getImage(); myImage.setColor(Color.WHITE); myImage.drawRect( 0 , 0 ,fuelwidth+ 1 ,fuelheight+ 1 ); myImage.setColor(Color.RED); myImage.fillRect( 1 , 1 ,fuelwidth,fuelcounter*pixelperfuel); } public int getfuel(){ return fuelcounter; } public void setfuel( int fc){ this .fuelcounter=fc; } } |
1 2 3 4 5 | public void act(){ millisec++; if (millisec% 100 == 0 ){ FA.setfuel(FA.getfuel()- 1 ); } |