

You may want to ask a TA to check over your code.Īt this point, you should have a compiler error in your Road.java file. You should useĬompile your Car class and correct any errors. It should only create and return the string. Parameters and returns a string in the format The same names as the private attributes, and use theĬreate a toString() method that accepts no Holds the car's make, and an integer that holds theĬreate a constructor that accepts the model year and make,Īnd sets the speed to 0.
-p-500.png)
#GREENFOOT MOVING BACKGROUND CODE#
Write the code for the following steps above the act() method.Ĭreate three private variables within the class:Īn integer that holds the car's year, a string that Part 2 - Basic Car methodsĭouble-click the Car rectangle (on the right) to open Car.java. Saving the world automatically creates (or edits) the prepare method which is invoked by the constructor. When you click "Save the World", a new editor window should open with Road.java. If that menu is disabled, try running and resetting the program. After placing the car, select "Controls > Save the World" from the menu. Press the Reset button, and then add a new Car() to the world. Right-click the "Actor" rectangle on the right, and select "New subclass." Name the subclass Car and select a suitable image from the "transport" category. Right-click the "World" rectangle on the right, and select "New subclass." Name the subclass Road and select a suitable image from the "backgrounds" category. We'll create a different World in the next step. Right-click the "MyWorld" rectangle on the right, and select "Delete".

Name your scenario Lab21 (under your CS149 directory). Run Greenfoot (from the Linux menu) and select "Scenario > New Java Scenario." (from the Greenfoot menu). Today we will create a new simulation from scratch. Last time, we took our first look at game design with Greenfoot. Write constructor, accessor, and mutator methods. Objectivesĭesign an interactive simulation using Greenfoot. Your program will control how those objects interact in the "world" (which in the case of Greenfoot, is just another object). You design the objects by specifying what they should look like (attributes) and what behaviors they should have (methods).
#GREENFOOT MOVING BACKGROUND SERIES#
Object-oriented programming changes the view of a program as a series of steps to an interaction between objects. James Madison University, Spring 2018 Semester
