SSEA Newbies Handout 09 Summer 2012 August 17 th, 2012 Assignment 4: Bouncing Ball and Bizz Bazz Buzz

Similar documents
Assignment #3 Breakout!

Smoother Graphics Taking Control of Painting the Screen

OrbBasic Lesson 1 Goto and Variables: Student Guide

[ the academy_of_code] Senior Beginners

OrbBasic 1: Student Guide

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet.

Practice Midterm Examination #1

CS 134 Programming Exercise 3:

2SKILL. Variables Lesson 6. Remembering numbers (and other stuff)...

+ Inheritance. Sometimes we need to create new more specialized types that are similar to types we have already created.

Animations involving numbers

Chapter01.fm Page 1 Monday, August 23, :52 PM. Part I of Change. The Mechanics. of Change

CS Problem Solving and Object-Oriented Programming

UV Mapping to avoid texture flaws and enable proper shading

Practice Final Examination #2

Assignment 5: Part 1 (COMPLETE) Sprites on a Plane

ICS 61 Game Systems and Design Introduction to Scratch

CS125 : Introduction to Computer Science. Lecture Notes #11 Procedural Composition and Abstraction. c 2005, 2004 Jason Zych

Animations that make decisions

Simple Glass TNT Molecule Tutorial

Adobe Flash CS3 Reference Flash CS3 Application Window

Laboratory 1: Eclipse and Karel the Robot

Mastering Truspace 7

Polygons and Angles: Student Guide

Creating a Brochure in Publisher

ENGR 40M Project 3c: Coding the raindrop pattern

Learn to make watchosle

: Intro Programming for Scientists and Engineers Assignment 1: Turtle Graphics

2. Click on the Freeform Pen Tool. It looks like the image to the right. If it s not showing, right click on that square and choose it from the list.

Making a maze with Scratch

Com S 227 Spring 2018 Assignment points Due Date: Thursday, September 27, 11:59 pm (midnight) "Late" deadline: Friday, September 28, 11:59 pm

CS125 : Introduction to Computer Science. Lecture Notes #38 and #39 Quicksort. c 2005, 2003, 2002, 2000 Jason Zych

BUYING DECISION CRITERIA WHEN DEVELOPING IOT SENSORS

CMPSCI 119 LAB #2 Greebles / Anime Eyes Professor William T. Verts

SNOWFLAKES PHOTO BORDER - PHOTOSHOP CS6 / CC

Assignment 3 Functions, Graphics, and Decomposition

Burning CDs in Windows XP

Accounts and Passwords

Operating System Principles: Memory Management Swapping, Paging, and Virtual Memory CS 111. Operating Systems Peter Reiher

ENCM 339 Fall 2017: Editing and Running Programs in the Lab

Adapted from slides by Brahm Capoor. Breakout YEAH hours. Michael (Chung Troute)

Name: Date: Multimedia Graphics and Web Publishing Mr. Dietzler. Flash Topics TWEENING AND MOTION GUIDES

Assignment 2: Welcome to Java!

Learn a lot beyond the conventional VLOOKUP

Objects and Graphics

1 LOGGING IN REQUEST A SUB (from the calendar) REQUEST A SUB (from Line Listing) ACCEPTING AN INVITATION TO BE A SUB...

On the Web sun.com/aboutsun/comm_invest STAROFFICE 8 DRAW

Lab 4: On Lists and Light Sabers

the NXT-G programming environment

It s possible to get your inbox to zero and keep it there, even if you get hundreds of s a day.

CS311 - Neural Nets Lab Thursday, April 11

- 1 - Handout #33 March 14, 2014 JAR Files. CS106A Winter

CSCI-1200 Data Structures Spring 2018 Lecture 14 Associative Containers (Maps), Part 1 (and Problem Solving Too)

CS108, Stanford Handout #3. HW1 CodeCamp

SketchUp Quick Start For Surveyors

Creating an Animated Navigation Bar in InDesign*

Notes 3: Actionscript to control symbol locations

CoderDojo Activity Cards: The Cards (Animation2.html): How to use: Student comes to mentor, and together they choose a card to do next.

Post Experiment Interview Questions

Copy Music from CDs for Videos & Slideshows

CMPSCI 119 LAB #2 Anime Eyes Professor William T. Verts

ONLINE BOOKING GUIDE

Installing and Using Trackside Cameras Revised November 2008

In this lesson, you ll learn how to:

Memory Management: Virtual Memory and Paging CS 111. Operating Systems Peter Reiher

Turn in a printout of your code exercises stapled to your answers to the written exercises by 2:10 PM on Tuesday, January 18th.

Artwork Guidelines YOUR KEEP-ME GUIDE TO SUPPLYING ARTWORK FOR UNBEELIEVABLY GOOD PRINTS

Using GitHub to Share with SparkFun a

How to Get Your Inbox to Zero Every Day

Introduction to Programming with JES

Quick Guide. Choose It Maker 2. Overview/Introduction. ChooseIt!Maker2 is a motivating program at first because of the visual and musical

Simple Java YEAH Hours. Brahm Capoor and Vrinda Vasavada

COMP 161 Lecture Notes 16 Analyzing Search and Sort

Mobile Computing Professor Pushpedra Singh Indraprasth Institute of Information Technology Delhi Activity Logging Lecture 16

Chapter 2.6: Testing and running a solution

Drawing a Circle. 78 Chapter 5. geometry.pyde. def setup(): size(600,600) def draw(): ellipse(200,100,20,20) Listing 5-1: Drawing a circle

Notebook Assignments

Introduction to VPython for E&M This tutorial will guide you through the basics of programming in VPython

Jump to: Using AAUP Photos AAUP Logos Embedding the AAUP Twitter Feed Embedding the AAUP News Feed CREATING A WEBSITE

Section 1. System Technologies and Implications. Modules

Pong in Unity a basic Intro

Instructions for the 3 Spinner & More Programs

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 14

REVISITING THE SOLUTION TO RUBIK S CUBE

Lesson 9 Transcript: Backup and Recovery

Touring the Mac S e s s i o n 4 : S A V E, P R I N T, C L O S E & Q U I T

Assignment II: Calculator Brain

Unit 21 - Creating a Navigation Bar in Macromedia Fireworks

Intro to Event-Driven Programming

Create your first workbook

How to Read AWStats. Why it s important to know your stats

introduction to Programming in C Department of Computer Science and Engineering Lecture No. #40 Recursion Linear Recursion

ADDING CONDITIONAL STATEMENTS PART 2

Part 1: Understanding Windows XP Basics

Instructor (Mehran Sahami): All righty. Welcome back to yet another fun-filled, exciting day of CS106A.

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi.

We will start our journey into Processing with creating static images using commands available in Processing:

Day 1: Introduction to MATLAB and Colorizing Images CURIE Academy 2015: Computational Photography Sign-Off Sheet

Google SketchUp Design Exercise 1

Robotics and Electronics Unit 5

Transcription:

SSEA Newbies Handout 09 Summer 2012 August 17 th, 2012 Assignment 4: Bouncing Ball and Bizz Bazz Buzz For the next week (from today until next Thursday), you ll be implementing a pair of programs that make use of your recently acquired programming skills. The first program works to implement a bouncing ball animation, and the second helps use get better at a game called Bizz Bazz Buzz. The bouncing ball application is complex, but still short enough that you shouldn t feel any pressure to decompose and define your own helper methods. The second, however, in substantial enough that you should definitely decompose and define your own methods. We ll work in class today and on Tuesday to ensure that you re outfitted to succeed in building programs that benefit from these new decomposition techniques. Due: Thursday, August 23 rd at 4:00 p.m. Problem 1: Bouncing Ball Implement a GraphicsProgram that bounces a ball within the boundaries of the graphics window. Your program should begin by placing a red circle (50 pixels in diameter) at the center of the graphics window. Every 10 milliseconds, your program should shift the position of the ball by dx and dy pixels, where both dx and dy initially have the value of one. Whenever the leading edge of the ball touches one of the window boundaries, your program should make the ball bounce by negating the value of dx and dy, as appropriate. (If you re interested, you might have the ball change colors every time it bounces maybe have it rotate through red, orange, magenta, black, green, blue, gray, and cyan.) The bouncing ball s itinerary would take it from the center of the screen in a southeasterly direction. It would eventually bounce and head northeast until it bounced off the eastern wall. The first few seconds of the application would see the bouncing ball trace through the path outlined in the following snapshot. The ball would travel from the center (shown as the checkered ball) through the dashed line to the be-bricked ball and continue on from there.

2 Don t worry about figuring out how to get the program to stop. For this exercise, you should use a while (true) loop so that the program just keeps on bouncing the ball until you close the window. There is one GOval method you should use to shift the location of the oval to a new spot: setlocation. setlocation takes a new x and y value that defines the new upper left coordinate of the rectangle circumscribing the oval. Consider this code snippet: public void run() { GOval circle = new GOval(0, 0, 10, 10); add(circle); pause(1000); circle.setlocation(50, 50); } The above would create a small circle that when added would hug the upper left corner of the canvas. The circle would sit there for a full second (or 1000 milliseconds) before being relocated 50 pixels to the right and 50 pixels down. In particular, don t create a new GOval with each iteration just move the original one around.

3 Problem 2: Bizz Bazz Buzz Bizz Bazz Buzz is a multiple player game where everyone sits in a circle ala duck-duckgoose and counts off consecutive numbers in a round robin manner. One person says 1, the person next to him says 2, the person next to her says 3, and so on in one big, merry loop. Play continues until someone either takes too long or makes a mistake, and the person who messes up leaves the circle and play resumes with those who remain. Now, counting off numbers is fairly easy easy enough that even a circle of drunken imbeciles could play for a very long time. The twist: whenever you get to a number that s a multiple of 3, 5, or 7 and/or includes any one of those three digits, you don t say the number itself, but you say something else. The rules outlined below dictate what you should say instead: If the number is a multiple of 3 and/or the digit 3 appears one or more times, then you don t say the number. Instead, you say the word "bizz" if it s a multiple of three, and you say "bizz" for every 3 that appears. For example: o You wouldn t say 13. You d say "bizz", because 13 contains a single 3. o You wouldn t say 233. You d instead say "bizz bizz", because 3 appears twice. o You wouldn t say 333. You d actually say "bizz bizz bizz bizz, because it s a multiple of 3, and because the digit 3 appears three times. 1 + 3 equals 4. Fun! If the number is a multiple of 5 and/or the digit 5 appears one or more times, then you don t say the number; rather, you say something involving the word "bazz". 5 is to "bazz" as 3 is to "bizz". For example: o You wouldn t say 52. No, you d say "bazz, because a single 5 appears as the first digit. o You wouldn t say 25. You d say "bazz bazz" instead. 25 is a multiple of 5, and the digit 5 appears exactly one time. o You wouldn t say 55. It s actually "bazz bazz bazz". If the number is a multiple of 3 and 5, and/or both digits appear, you say something involving a combination of "bizz" and "bazz". o You wouldn t say 35. It s a multiple of 5, and it contains a 3 and also a 5. So you d say "bizz bazz bazz". The same goes for the digit 7, except it s paired with the word "buzz". o 77 isn t 77. It s actually "buzz buzz buzz". It s a multiple of 7. It has two 7s. Hence, you say buzz" three times. Woo.

o 105 isn t 105. It s really "bizz bazz bazz buzz". 105 equals 3 times 5 times 7, and there s a 5 in there! Four words! Those numbers having nothing to do with 3s, 5s, and 7s are printed as is: 2, 8, 29, and 44 are examples. The Program The program is conceptually straightforward: You need to write a program that generates what should be said for the numbers 1 through 100 during a game of Bizz Bazz Buzz. The program output should look something like this: Here's a program that'll help you master the game of Bizz Bazz Buzz!! ---------------------------- 1.) 1 2.) 2 3.) bizz bizz 4.) 4 5.) bazz bazz 6.) bizz 7.) buzz buzz 8.) 8 9.) bizz 10.) bazz 11.) 11 12.) bizz 13.) bizz 14.) buzz 15.) bizz bazz bazz output for 16 through 94 has been excluded from handout, just to save paper 95.) bazz bazz 96.) bizz 97.) buzz 98.) buzz 99.) bizz 100.) bazz The Approach I ve provided you with starter code, which includes the implementation of a method called countoccurrences. At the moment, the run method includes some calls to the countoccurrences method to demonstrate that it works as intended. Once you get a chance to run the sample program a few times (look at the Newbies web site for a demo) and look over the code I give you, you ll want to start hacking. Here s how I want you to proceed: 1. Introduce a new method called countnumtimestosay, which has the following prototype: 4

private int countnumtimestosay(int number, int digit) { 5 Implement countnumtimestosay to return the number of times a word should appear in what gets printed on behalf of the specified number, either because the digit appears in number one or more times, number is a multiple of digit, or both. Your implementation should call of the countoccurrences method, because the number that countnumtimestosay needs to return is always equal to or just one more than whatever countoccurrences returns. Note that you don t actually pass the word (i.e. "bizz" or "bazz"), because the word itself doesn t influence what gets returned. Once you ve implemented countnumtimestosay, change the last half of the run method. Get rid of the lines that test countoccurrences, and replace it with similar code that tests countnumtimestosay. It s completely up to you what you write here, but you might include these if it ll help you get started. println("number of bizzes in 133: " + countnumtimestosay(133, 3)); println("number of buzzes in 7217:" + countnumtimestosay(7217, 7)); The truly ambitious programmer will write a good number of these to ensure the countnumtimestosay method works the way we need it to. 2. Making use of the countnumtimestosay method you just wrote, introduce a method called printnumber, which has the following prototype: private void printnumber(int number) { The method decides whether the supplied number should be printed as is, or if it should be printed as a combination of bizzes, bazzes, and/or buzzes. It also prints whatever should be printed. Once you have an implementation you suspect it pretty good, go ahead and erase the code that tested countnumtimestosay and replace it with code that tests printnumber. 3. Finally, remove all test code from the run method, and add a simple for loop that prints out the numbers 1 through 100, using the printnumber method. There s a lot on your plate, but with your smarts and your drive to succeed, I am super duper confident you ll finish both of these programs and live to brag about it.