Hi, so this exercise has two separate sections of editable code. The assignment is to fix the two errors. Do I need to create a getter method to get rid of the error? Here are the full instructions:
The following code segment overrides the processActors method to implement BlushingActor, but it contains two errors, one of which causes a compile-time error and the other of which will sometimes cause a runtime exception. Study the code and correct the errors. Test that your corrected definition gives rise to Actors that behave in the manner described above.
Here is my attempt at fixing the first error in section 1:
public class BlushingActor extends Critter { public void processActors( ArrayList<Actor> actors ) { Color c = getColor(); int red = c.getRed(); int green = c.getGreen(); int blue = c.getBlue(); if ( actors.size() > 0 ) red = 255; green = 235; blue = 110; else red = Math.min( 0, red - 10); setColor( red, c.getGreen(), c.getBlue() ); } }
And here is section 2:
Actor alice = new Bug(), blusher = new BlushingActor(); blusher.setColor( Color.BLACK ); (new Rock()).putSelfInGrid( grid, new Location( 3, 5 ) ); (new Rock()).putSelfInGrid( grid, new Location( 0, 10 ) ); (new Rock()).putSelfInGrid( grid, new Location( 7, 16 ) ); (new Rock()).putSelfInGrid( grid, new Location( 15, 19 ) ); (new Rock()).putSelfInGrid( grid, new Location( 19, 2 ) ); alice.putSelfInGrid( grid, new Location( 5, 3 ) ); blusher.putSelfInGrid( grid, new Location( 7, 7 ) );
I get this error when I try to run it:
"error 'else' without if"
That's different from the original error, but am I just messing this code up further?
Oh, and for section 1, I think I can give you the original code: