CS 101 - Problem Solving and Object-Oriented Programming Test Program 1 Due: October 8, 1:15 PM Note: Both lab sections have the same due date. This is a FIRM due date. This assignment is a take-home test. As such, the honor code rules are different for this assignment than for labs we have done up to this point. Here are the rules: The only person you may consult with is Professor Lerner. You may not consult with each other, with our TA or lab instructor, or with anyone outside of this class. You may consult your notes, your book, your previous assignments, and the course website. You may download and examine all examples available on the course website. You may not otherwise use the Internet to help complete this test. If you have any questions about whether a particular activity is in violation of the honor code, please do not hesitate to ask. Also, please do not hesitate to ask me questions about the exam. It will never hurt! I reserve the right to not answer a question, but, in general, you should expect asking questions to be helpful. By submitting your solution to this exam via Ella, you are asserting that you have adhered to these honor code rules. This exam contains 2 questions. Therefore, you should submit 2 separate Alice worlds. In your submission, please pay attention to laying out the world as shown and getting the behavior requested. Remember that it is often easier to set up your world by right-clicking on the objects and executing one of their methods rather than using the mouse to do positioning. When considering the functionality, do a little bit at a time. Think about how to do it, write the code and test it. Save your files often! Finally, be sure to include comments. QuickTime movies of the animations are available on the schedule page of the course website at http://www.mtholyoke.edu/~blerner/cs101/lectures.html. (50 points) Animation 1: Dribbling contest Two people have a contest to see who can dribble a basketball for longer. Before beginning the contest, about ½ the time, one of the contestants will say something. The other times, the 2 nd contestant will speak. They should dribble the ball at the same time. One player should lose by dribbling the ball off of his/her foot. The winning player should make one extra dribble and then say some wise comment. 1
Below are some screen shots to help you understand the animation. The starting world. Randomly choose one player to make a comment. The balls when they are near the ground. 2
After several successful dribbles by both players, the ball hits the lunch lady s foot. The ball bounces off her foot and moves quickly out of the scene. The winning player makes a wise remark. 3
Hints The objects used in this scene are: Gym: Found in Environment category of the Web gallery. Basketball: Found in Sports category of the Web gallery. 2 people: You can use any people you like. I used LunchLady and Nerd from the Web gallery. To get to the Web Gallery, do the following. 1. Click on Add Objects. You should see something familiar like the image on the top right. 2. Click on Home 3. You should now see the image on the bottom. 4. Click on Web Gallery to connect to the Internet and see a gallery similar to the Local Gallery but with many more choices available. Here are some hints to help with the animation: Use dummy objects to determine where the ball should move to when it is at the player s hand and when bouncing off the player s foot. Use the Random.nextBoolean function defined in the World object to randomly select which player should speak at the beginning of the game. Define a dribble method. Initially, the method should just get a single player to dribble. Once that works add 2 parameters to the dribble method: which basketball to move where to move the basketball to when at a player s hand (50 points) Animation 2: Ice Skating Routine Four ice skaters are practicing their single Axel jump while a coach looks on from behind them. One at a time they take 2 skating steps, jump, making 1½ revolutions while in the air and landing backwards on one skate. Here are scenes from this animation. The starting world. The skaters are lined up with the coach behind them. They should all be facing the same direction. 4
The first skater begins skating. The skater has jumped and completed ½ revolution in the air. The skater has completed ¾ revolution. 5
The skater has completed 1¼ revolutions. After landing, the skater has is on one foot and skates backwards. When the skater stops moving, she puts her foot down and resumes the usual pose, but now facing the other skaters. 6
This is the final view of the world after all the skaters have gone. Hints The objects used in this scene are: Lake: Found in Environment category of the Local gallery. My version shown above has a lot of the trees removed. It is not necessary for you to remove trees. IceSkater and Coach from the People category. You can use anybody for the coach. If you like, you can use the ice skating world that we used in class as the starting point for this lab, including the skate method that we did in class. You can download that from the course schedule page located at http://www.mtholyoke.edu/~blerner/cs101/lectures.html. Here are some hints for creating this animation: Define a jump method to make a skater jump. Initially, just get an individual skater to jump. After that is working, add a parameter to the method that indicates which skater should jump. When the skater is in the air, she should continue to move in the same direction she was moving before jumping. If you just have her move FORWARD while she is turning, what forward means will change during the turn. (Remember the penguin diving into the hole.) To solve this problem do the following: Make sure all the skaters and the coach are facing exactly the same direction. The easiest way to do this is to right-select each skater but the first and the coach (one at a time) and select methods, orient to, ice skater, the entire ice skater When the ice skater is in the air, instead of just saying move FORWARD add the as- SeenBy argument and select the coach. This will cause the ice skater to move in the direction that is forward with respect to the coach, that is, the direction the coach is facing. If the skaters and coach are all facing the same direction, this will have the desired effect. 7
Grading Animation 1 10 Creating the world 5 Randomly speaking at start 10 One player able to dribble 10 Both players able to dribble 5 Winning and losing actions 10 Comments Animation 2 5 Creating the world 10 One skater doing the jump 10 One skater landing the jump 5 One skater doing the entire routine 10 All skaters doing the entire routine 10 Comments Turning in Your Work Go to ella. Click on COMSC 101 in the toolbar menu across the top. Then click on Assignments in the left column. Click the submit link for this assignment. Click the Add Attachment button. Use the Browse button to upload a local file. Click Continue. Then click the Submit button. Once you have submitted a solution to an assignment, Ella does not allow you to resubmit your assignment. In order to allow you to submit a revision, I will create extra assignments. So, in Ella, you should see assignments something like this: Test Program 1, Question 1 Test Program 1, Question 1, revision 1 Test Program 1, Question 1, revision 2 Test Program 1, Question 2 Test Program 1, Question 2, revision 1 Test Program 1, Question 2, revision 2 You only need to submit a revision if you would like to change your solution after submitting it. Please ask if you are confused about this. 8