![]() You should use this method to create the string.Ĭompile your Car class and correct any errors. String.format() operates just like printf(). It should only create and return the string. Make the constructor's parameters the same names as the private attributes, and use the this keyword when assigning the values.Ĭreate a toString() method that accepts no parameters and returns a string in the format "A %d %s that is going %d mph".ĭo NOT print anything in the method (no System.out). Write the code for the following steps above the act() method.Ĭreate three private variables within the class: an integer that holds the car's year, a string that holds the car's make, and an integer that holds the car's speed.Ĭreate a constructor that accepts the model year and make, and sets the speed to 0. After placing the car, select "Controls > Save the World" from the menu.ĭouble-click the Car rectangle (on the right) to open Car.java. Press the compile 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. Run Greenfoot (from the Linux menu) and then select "Scenario > New." from the Greenfoot menu. Today we will create a new simulation from scratch. Write constructor, accessor, and mutator methods.īefore the break, we took our first look at game design with Greenfoot. 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). Object-oriented programming changes the view of a program as a series of steps to an interaction between objects. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |