CMPS 200 Homework Assignment 7, Fall 2011

American University of Beirut · Introduction to Programming · 2 pages

All CMPS 200 files
CMPS 200 Homework Assignment 7, Fall 2011, page 1

Stuck on a question? A tutor can walk you through it.

CMPS 200 Homework Assignment 7, Fall 2011, page 2

More CMPS 200 files

Show the text of this homework
Faculty of Arts & Sciences Department of Computer Science CMPS 200—Introduction to Programming Assignment 7 – Due Mon Nov 21, 2011 Notes and Announcements  This assignment relies on a few external libraries for input and output packaged in an external library called stdlib.jar available for download from Moodle. You will need to let Eclipse know where this library (also known as archive) resides. To do so, first save it somewhere in your folders. Then, in Eclipse, left click on the project name in the Package Explorer tab, and navigate to Build Path  Add External Archives to add it. The library will appear in the package Explorer tab. Problem 1. CheckerBoard Write a program CheckerBoard.java that takes a command line input N and plots an N-by-N checkerboard. Always color the lower left square red. Draw the squares in red and black. Below is the desired output for N = 5, 10, and 25. Write a variation on the program that reads three command line parameters and draws three corresponding checkerboards. Problem 2. Barcode For faster sorting of letters the U.S. Postal System encourages companies that send large volumes of mail to use a barcode denoting the zip code of the destination. The barcode is defined as follows: Each decimal digit in the 5-digit zip code is encoded using a sequence of three half-height and two full-height bars, as per the table below. The barcode starts and ends with a full-height bar (called the guard rail) and includes a checksum digit (after the five-digit zip code), computed to make the sum of the six digits a multiple of 10. For the 5-digit zip the barcode consists then of 32 bars in total. For example the barcode below encodes the zip 12345. a. Write a program Barcode.java that takes a 5-digit zip code and prints the corresponding barcode on the screen (Use : for half bars, and | for full bars). For example, > java Barcode 95014 ||:|:::|:|:||::::::||:|::|:::||| b. Write another version of this program that draws the bar code in a canvas to produce a compelling visual output as in the example above for the 12345 zip code. Introduction to Programming (CMPS 200) Fall 2011 2 of 2 Problem 3. BouncingBall Modify the program BouncingBall.java so that the ball leaves the domain of the animation if it hits the right half of the top boundary. For example, in the picture below, the ball should leave the domain instead of bouncing back off the top. When the ball leaves the domain the animation should stop. Program 4. ChangingColor Write a program that draws a square and changes its color to a random color every half a second. Program 5. Circles Write a program Circles.java that draws filled black and white circles of random size at random positions in the unit square, producing images like those below. Your program should take four command-line arguments: the number of circles, the probability that each circle is black, the minimum radius, and the maximum radius. Program 6. GuessTheNumber. Write an interactive program that prompts the user to think of an integer between one and a million and then asks the user to truthfully respond with true or false to statements of the form "My number is less than or equal to x?" for various values of x, until the program can deduce the chosen integer. Your program should use a strategy known as binary search for guessing. Binary search chooses the middle of the search interval as the value of x at every iteration. Problem 7. DocumentStats Write a program that takes a file name as argument and counts the number of words and the number of characters (without spaces) in the document. For example, the file AUBMissionStatement.txt (download from Moodle) which contains the text of AUB’s mission statement would generate the following statistics: > java DocumentStats AUBMissionStatement.txt Number of Words: 105 Number of characters: 613