It says my error is my else is without an If.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * MyCat is your own cat. Get it to do things by writing code in its act method. * * @author (your name) * @version (a version number or a date) */ public class MyCat extends Cat { /** * Act - do whatever the MyCat wants to do. */ public void act() { //checks if cat is bored by calling the method "isBored()" which is inherited from the cat class// if(isBored()) { //If it is bored,then dance dance(); } //checks if cat is hungry by calling the method "isHungry()" which is inherited from the cat class// if(isHungry()) { // If it is hungry, then it eats eat(); } //check if cat is tried if(tired==true) { //If so make the cat sleep for some time sleep(4); // Then make the cat to shourt hooray shourtHooray(); } else { //If the cats is tired it only shourts hooray shoutHooray(); } //check if cat is alone if(isALone()) { //If so make the cat sleep for some time sleep(4); } else { //If the cat is not alone it shouts hooray shoutHooray(); } } (})
* * @author (your name) * @version (a version number or a date) */ public class MyCat extends Cat { /** * Act - do whatever the MyCat wants to do. */ public void act() { //Excercise 2.35 soulution to if cat is bored// if(isBored()) { //If it is bored,then dance dance(); } //Excercise 2.36 solution to fi cat is then it it eats// if(isHungry()) { // If it is hungry, then it eats eat(); } //Excercise 2.37 soultion to if cat is tired then eats or shouts hooray if(tired==true) { //If so make the cat sleep for some time sleep(4); // Then make the cat to shourt hooray shourtHooray(); } else { //If the cats is tired it only shourts hooray shoutHooray(); } //Soultion to excercise 2.38 checks if cat is alone then it sleeps and if cat is not alone then it shouts Hooray if(isALone()) { //If so make the cat sleep for some time sleep(4); } else { //If the cat is not alone it shouts hooray shoutHooray(); } } }