I have these two methods given called leftEyeColor() and rightEyeColor(). And in each of those methods, I must execute this pseudocode:
For leftEyeColor and rightEyeColor methods:
Get world
Get background
Get x and y coordinates of the eye
(Get color from background at eye coordinates)
Return color. (All of these tasks can be done from the return statement)
I tried to put everything inside the return line and it looks like this:
private Color leftEyeColor()
{
Point eyePos = leftEye();
return getWorld().getBackground().getColorAt(eyePos.getX(),eyePos.getY());
}
private Color rightEyeColor()
{
Point eyePos = rightEye();
return getWorld().getBackground().getColorAt(eyePos.getX(),eyePos.getY()); // this is incomplete - fix it
}
This looks right to me but I am being thrown the error: Greenfoot.Color cannot be converted to java.awt.Color A simple fix would be to simply not import java.awt.Color, however, I don't think I am allowed to remove the import for this assignment unfortunately :(
This is a difference between Greenfoot versions. In Greenfoot 3.1.0,
greenfoot.Color
was introduced and used in place ofjava.awt.Color
everywhere. This was a breaking change: code before 3.1.0 is incompatible with versions 3.1.0+ and vice versa. See https://www.greenfoot.org/doc/font_colorIf the assignment came with the
import java.awt.Color;
already in then it must be from an old version of Greenfoot. The simplest fix for you personally might be to download an old Greenfoot like 3.0.4 (as unfortunately it's easier for you to downgrade than get them to upgrade, even though 3.1.0 is five years old already).