1 / 8

The PoopleRat

The PoopleRat. The PoopleRat will introduce you To some ideas about Object Oriented Programming in Java. You have to program the rat to run through the maze and get to the cheese before it starves to death.

mizell
Download Presentation

The PoopleRat

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The PoopleRat The PoopleRat will introduce you To some ideas about Object Oriented Programming in Java. You have to program the rat to run through the maze and get to the cheese before it starves to death. You program the rat by pressing the buttons on the lower left area, which will compose Java code in the lower right area. When the code is ready, pressing the OK button will send the code to the rat. As the rat moves the bar at the top of the screen shows how much energy the rat has left.

  2. Getting Started To get started press the New button. The code to create a new rat will appear in the text area at the right. A new rat and a new maze will appear In the main window. The Java phrase: PoopleRat rat01 = new PoopleRat(); Creates a new rat called rat01. Create a new rat yourself & see the new maze created.

  3. Moving the rat The three buttons shown make the rat run, turn right or turn left. When you press one of the buttons a message is sent to the rat called rat01. In order to send the message the OK button has to be pressed. (Or the Cancel button if you change your mind.) Make your rat move and turn, notice its energy going down.

  4. Deciding to move the rat Pressing the if ( button allows the rat to make decisions. The decisions that can be made are: clearForward() is true if the rat can run forwards. clearLeft is true if the rat can turn to the left and run. clearRight() is true if the rat can turn to the right and run. clearLeftAndRight() is true if the rat can turn to the left or the right and run. foundCheese() is true if the rat has reached the cheese. The not button can make a true false, or a false true. The else button can tell the rat what to do if the decision is not true. Use the if ( button to show that the rat can make decisions. (e.g. To turn left, only if it is clear on the left) Use the else button to extend the decision. (e.g. to turn right if it cannot turn left).

  5. A decision in detail press if ( if ( press clearForward() if ( rat01.clearForward() press ){ to complete the decision if ( rat01.clearForward()) { press run() to give an instruction if ( rat01.clearForward()) { rat01.run(); press } else { if ( rat01.clearForward()) { rat01.run(); } else { press turnRight() if ( rat01.clearForward()) { rat01.run(); } else { rat01.turnRight(); press } to complete the if if ( rat01.clearForward()) { rat01.run(); } else { rat01.turnRight(); } // end if. press OK to make the rat do it.

  6. More complicated decisions The while ( button makes the rat repeat commands so long as a decision remains true. The decision in this example is ‘while the rat has not reached the cheese’. (In Java the ! Is read as ‘not’). A complicated decision can be made by joining two simple decisions: the and button means that both decisions have to be true. the or button means that either decision can be true. Use the while ( button to try to get the rat to the cheese.

  7. Teaching the rat new methods Press the method button and then type in the name of the new method beside it. Pressing <ENTER> starts the definition of the new method. The method can then be defined. Use the } button to complete the definition of the method and then to OK button to confirm it. The method can then be chosen from the drop down list of methods and sent to the rat for it to do it. Teach your rat new methods such as forwardLeft() or turnAround()

  8. Getting to the cheese These instructions will get the rat to the cheese. You have to work out how to say them in Java. while the rat has not reached the cheese run if it is possible to turn left or right turn left else turn right end if end while If the rat gets stuck pressing the Cancel button will stop it before it dies. Define a method called getCheese() and have your rat reach the cheese with a single command.

More Related