![]() |
Dick Baldwins Class Level lab project help.
Need some help on this. I'm still trying to figure it out myself. Not sure if I can explain this.
[COLOR="Black"]Here is the instructions for the lab project[/COLOR] The program named Alice0150a The source code for this program is shown in Listing 1. Define your new class To define your new class, you need to: * Create a new world. * Add a Hare object to the world. * Select the Hare object in the object tree. * Select the methods tab below the object tree. * Write the new method named spin shown in Listing 1. Test your method To test your method, you need to write and run the main method shown in Listing 1. Note that I included the primitive method named move in addition to the new method named spin in the main method to demonstrate that the new method is available for execution in addition to the primitive methods. Save your new class To save your new class, you need to: * Right click on the Hare object in the object tree. * Select the save object... item in the popup menu. * Save the file with the name SpinningHare.a2c in the directory of your choice. [B]THIS IS WHAT THE CODE SHOULD BE[/B] Alice0150a's Code Created by: Dick Baldwin world Methods public void main ( ) { // Copyright 2007 R.G.Baldwin // The real purpose of this program is to define and // save a new class named SpinningHare.a2c // This class adds a method named spin to the standard // Hare class. Objects of this class can be created // and added to a world by importing the class // from the File menu. hare .move( BACKWARD , 0.5 meters ); hare.spin ( numberRevs = 10 , duration = 10 ); hare .move( FORWARD , 0.5 meters ); } hare Methods public void spin ( Number numberRevs, Number duration) { // This method is added to the Hare class to create // a new class named SpinningHare. hare .turn( LEFT , numberRevs revolutions ); duration = duration seconds } [B]This is what my code looks like[/B] Created by: Mary world Methods world.main ( ) No variables hare move backward 0.5 meters hare.spin hare move forward 0.5 meters hare Methods hare.spin ( ) No variables hare turn left numberRevs revolutions duration = duration seconds **** Notice the hare.spin line. I have to add something there, but everytime I drag the new spin method I made, it just looks like that. hare.spin and gives me no arrows or any way of adding to it. You know what I mean. Like the hare move one is hare "space" move and than you can click on the arrow and choose forward. This shows up as hare (dot) spin and that's it. It's over. Also, this is small but just wondering why mine just says world.main and hare.spin ( ) and not public void spin or public void main Final Notes, I created the two variables by clicking on the hare object, going to the properties tab and clicking on new variable. I created the new method by clicking on the hare object and under methods, I chose new method. I than called it spin. I than created the two variables and than created the code for the hare.spin method, which looks correct as it looks the same as the one showing in Listing 1. I than click on the world object and edit the main method. I have no problems with the move forward or backward code and I wouldn't have a problem with the spin one either, except when I click on the hare object and drag the hare.spin method over into the main method, it just drags in as hare.spin thus not allowing me continue on with the numberrevs and duration being 10. |
I think I figured it out. I thought that numberRevs and duration were variables within the the new spin method for the hare. I than realized (after trying to see if it would make a difference) that they are parameters. Once I changed them to be parameters, I was allowed to drag the new spin method over to the main method and specify the parameters making it
hare.spin numberRevs=10 duration=10 I ran the code and it worked. |
akkk, I have to go to bed now as I have to wake up and take care of a 1 year old and 2.5 year old quite early. I did get further, but after right clicking on the hare object and clicking save as object and saving it, I than have problems with what I think I'm suppose to do next. I'm going to have to read that chapter over again. I create a new world, I do file, import and import the new hare class I had saved. I than add two more objects into it. But when I click on the other 2 objects, I don't see the new spin method that I created. I do see it on the orginal hare object though.
|
All times are GMT -5. The time now is 09:24 AM. |
Copyright ©2023, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.