This site requires JavaScript, please enable it in your browser!
Greenfoot back
KIOP
KIOP wrote ...

2019/8/30

Help with error in my code

1
2
KIOP KIOP

2019/9/2

#
It says my error is my else is without an If.
KIOP KIOP

2019/9/2

#
I tried this and I still received errors
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(); 
}
}
(})
  
danpost danpost

2019/9/3

#
I never said anything about adding parentheses and a previously fixed error has reappeared.
KIOP KIOP

2019/9/4

#
* 
 * @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(); 
}
}
}
KIOP KIOP

2019/9/4

#
I did put a bracket but I now have an error on 49 33 and 32 saying im using shoutHooray and isalone incorrectly.
danpost danpost

2019/9/4

#
KIOP wrote...
I did put a bracket but I now have an error on 49 33 and 32 saying im using shoutHooray and isalone incorrectly.
Please provide your entire Cat class codes.
You need to login to post a reply.
1
2