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

2019/9/14

Help with organizing my programming so it looks better and fixing errors

1
2
KIOP KIOP

2019/9/14

#
import greenfoot.*;

/**
 * This is a stick man. Make him run and jump.
 * 
 * @author 
 * @version 
 */
public class Stickman extends Actor
{
    /**
     * Make the stickman act.
     */
    public void act() 
    { 
     //3.31: Make the stickman move to the right so that when you run scenario he walks over to the right side of the screen//
      move(5); 
     int soundLevel;
     moveLeftIfNoise();
     //The stickman moves at edge
     if(isAtEdge()) 
     gameOver();
    } 
}
/* 3.32 Using an if statemt and the micorphone input method to make sticman move right only when you make some noise
 * 
 */ 
public void soundLevel() 
{ 
 int soundLevel 
 // Greenfoot getMicLevel value is stored in the soundLevel//
 soundLevel = Greenfoot.getMicLevel();
 //It checks whether if soundLevel is greater than three//
 if(soundLevel>3)
 { 
 /* It allows the stickman to move according to the sound level */
 move(soundLevel):
}
}
/** 3.34 Move the code that moves left when you make noise into its own method.Call this method moveLeftIfNoise.Test.
 * 
 */
public Void moveLeftIfNoise ()
{ 
 /* This method will play sound while moving left */
 Greenfoot.playSound("slurp.wav");
//This allows the stickman to move left//
move(-4);
} 
}
/**3.35 Add another method to your class called gameOver.This method should be called if the stickman reaches the edge of the screen
 */
 public void gameOver()
 { 
  //This predefined method is used to play the sound//
  Greenfoot.playSound("slurp.wav");
  //This predefined method is used to stop the stickman
  Greenfoot.stop();
}
}
KIOP KIOP

2019/9/14

#
Im doing excercises out of the Greenfoot book and Each exercise I got to work if I put it in there by itself but I struggle when I try to put the code in for multiple excercises.
danpost danpost

2019/9/14

#
Here is what I have spotted: * line 43: "Void" should not be capitalized (should be "void"); * line 28: "soundLevel" method is not being called from anywhere (add call in act method); * line 18: "soundLevel" variable is not used within the method (remove line).
KIOP KIOP

2019/9/14

#
import greenfoot.*;

/**
 * This is a stick man. Make him run and jump.
 * 
 * @author 
 * @version 
 */
public class Stickman extends Actor
{
    /**
     * Make the stickman act.
     */
    public void act() 
    { 
     //3.31: Make the stickman move to the right so that when you run scenario he walks over to the right side of the screen//
      move(5); 
      soundLevel;
     moveLeftIfNoise();
     //The stickman moves at edge
     if(isAtEdge()) 
     gameOver();
    } 
}
/* 3.32 Using an if statemt and the micorphone input method to make sticman move right only when you make some noise
 * 
 */ 
public void soundLevel() 
{ 
  int soundLevel; 
 // Greenfoot getMicLevel value is stored in the soundLevel//
 soundLevel = Greenfoot.getMicLevel();
 //It checks whether if soundLevel is greater than three//
 if(soundLevel>3)
 { 
 /* It allows the stickman to move according to the sound level */
 move(soundLevel):
}
}
/** 3.34 Move the code that moves left when you make noise into its own method.Call this method moveLeftIfNoise.Test.
 * 
 */
public void moveLeftIfNoise ()
{ 
 /* This method will play sound while moving left */
 Greenfoot.playSound("slurp.wav");
//This allows the stickman to move left//
move(-4);
} 
}
/**3.35 Add another method to your class called gameOver.This method should be called if the stickman reaches the edge of the screen
 */
 public void gameOver()
 { 
  //This predefined method is used to play the sound//
  Greenfoot.playSound("slurp.wav");
  //This predefined method is used to stop the stickman
  Greenfoot.stop();
}
}
KIOP KIOP

2019/9/14

#
Line 18 I received an error trying to declare soundlevel it called it not a statement. Line 28 I received a class or enum expected Line 32 and 34 I received also class or enum expected line 43 I received a class or enum expected also Line 48 and 49 I also received a class or enum expected Line 58 and 59 I also received a class or enum expected error
danpost danpost

2019/9/14

#
KIOP wrote...
Line 18 I received an error trying to declare soundlevel it called it not a statement. Line 28 I received a class or enum expected Line 32 and 34 I received also class or enum expected line 43 I received a class or enum expected also Line 48 and 49 I also received a class or enum expected Line 58 and 59 I also received a class or enum expected error
Line 18: "trying to declare"? Is that what you are trying to do? All others: class or enum exxpected due to early closing of the class (check bracket pairings)
KIOP KIOP

2019/9/14

#
Line 18: Maybe I am not saying it correctly but I thought by putting the soundlevel; in the public act method the program would recoginize it I would not have errors. Honestly have not idea on how to start to fix those other errors.
danpost danpost

2019/9/14

#
You have a method called soundLevel (lines 28 to 39). To execute its code, the method needs to be called. All method calls require a set of parentheses after the name of the method. Line 18 does not call a method as there are no parentheses.
KIOP KIOP

2019/9/14

#
import greenfoot.*; /** * This is a stick man. Make him run and jump. * * @author * @version */ public class Stickman extends Actor { /** * Make the stickman act. */ public void act() { //3.31: Make the stickman move to the right so that when you run scenario he walks over to the right side of the screen// move(5); soundLevel(); moveLeftIfNoise(); //The stickman moves at edge if(isAtEdge()) gameOver(); } } /* 3.32 Using an if statemt and the micorphone input method to make sticman move right only when you make some noise * */ public void soundLevel() { int soundLevel; // Greenfoot getMicLevel value is stored in the soundLevel// soundLevel() = Greenfoot.getMicLevel(); //It checks whether if soundLevel is greater than three// if(soundLevel>3) { /* It allows the stickman to move according to the sound level */ move(soundLevel): } } /** 3.34 Move the code that moves left when you make noise into its own method.Call this method moveLeftIfNoise.Test. * */ public void moveLeftIfNoise () { /* This method will play sound while moving left */ Greenfoot.playSound("slurp.wav"); //This allows the stickman to move left// move(-4); } } /**3.35 Add another method to your class called gameOver.This method should be called if the stickman reaches the edge of the screen */ public void gameOver() { //This predefined method is used to play the sound// Greenfoot.playSound("slurp.wav"); //This predefined method is used to stop the stickman Greenfoot.stop(); } }
KIOP KIOP

2019/9/14

#
import greenfoot.*;

/**
 * This is a stick man. Make him run and jump.
 * 
 * @author 
 * @version 
 */
public class Stickman extends Actor
{
    /**
     * Make the stickman act.
     */
    public void act() 
    { 
     //3.31: Make the stickman move to the right so that when you run scenario he walks over to the right side of the screen//
      move(5); 
     soundLevel();
     moveLeftIfNoise();
     //The stickman moves at edge
     if(isAtEdge()) 
     gameOver();
    } 
}
/* 3.32 Using an if statemt and the micorphone input method to make sticman move right only when you make some noise
 * 
 */ 
public void soundLevel() 
{ 
  int soundLevel; 
 // Greenfoot getMicLevel value is stored in the soundLevel//
 soundLevel() = Greenfoot.getMicLevel();
 //It checks whether if soundLevel is greater than three//
 if(soundLevel>3)
 { 
 /* It allows the stickman to move according to the sound level */
 move(soundLevel):
}
}
/** 3.34 Move the code that moves left when you make noise into its own method.Call this method moveLeftIfNoise.Test.
 * 
 */
public void moveLeftIfNoise ()
{ 
 /* This method will play sound while moving left */
 Greenfoot.playSound("slurp.wav");
//This allows the stickman to move left//
move(-4);
} 
}
/**3.35 Add another method to your class called gameOver.This method should be called if the stickman reaches the edge of the screen
 */
 public void gameOver()
 { 
  //This predefined method is used to play the sound//
  Greenfoot.playSound("slurp.wav");
  //This predefined method is used to stop the stickman
  Greenfoot.stop();
}
}
KIOP KIOP

2019/9/14

#
I added the parenthes to soundlevel but still having problems getting line 28 soundlevel method to work.
danpost danpost

2019/9/14

#
KIOP wrote...
I added the parenthes to soundlevel but still having problems getting line 28 soundlevel method to work.
danpost wrote...
All others: class or enum exxpected due to early closing of the class (check bracket pairings)
KIOP KIOP

2019/9/14

#
I did check bracket pairing and they are all paired up
danpost danpost

2019/9/14

#
KIOP wrote...
I did check bracket pairing and they are all paired up
I count 6 opening brackets ( '{' ) and 8 closing brackets ( ')' ). Definitely not paired up properly.
KIOP KIOP

2019/9/14

#
Could please give me an example so i would know what to do for the other ones. It hard to see im doing it wrong because if i uploaded each one individually i would have no syntax errors.
There are more replies on the next page.
1
2