Homework 5 for Computer Science 125

Introduction to Computer Science

Boise State University, Spring 1999


This homework is due by 9 p.m., Friday, 12 March 1999. See the directions in Homework 1 to electronically submit homework.

Warm-up and Practice Problems

These are not be turned in. They are to help you understand the material, and some will appear on exams.

Graded Problems

You must include comments for all functions, following the javadoc format. See CCJ, p 183-185 for more details.

P13. (bar chart): Exercise P6.8, p 283. Submit this as program 13 using the electronic submission. Please call the file (and the class) Program13. Include an HTML file in the directory called Program13.html that displays your applet.

Note: You may assume that all input is in integer form, and there will be no more than 20 bars.
Your program should prompt the user for all input using the GraphicsApplet interface (not the console). That is, you should use readInt(), not Console.in.readInt().

Hint: You might want to change the coordinate system to match the range of the data (that is, from 0 to 100). See CCJ, p 113 for more details.

P14. (random walk): Write a program to simulate the walk of a drunkard in a square street grid. Draw a grid of 21 streets horizontally and 21 streets vertically (see CCJ, p 271). Place a simulated person at the center of the grid (i.e. at (0,0)), denoted by a point. For 100 times, have the simulated person randomly pick a direction (east, west, north, south), move one block in that direction, and redraw the dot. Circle the starting and stopping positions of the walk with a circle of radius one quarter.

Prompt the user if they would like to try again. If their answer starts with 'y' or 'Y', clear the window and simulate another random walk. If the user enters anything else, thank them for playing.

For example,

Submit this as program 14 using the electronic submission. Please call the file (and the class) Program14. Include an HTML file in the directory called Program14.html that displays your applet.

Extra credit if you also highlight the path that the simulated person walks. Since we're working in black and white, one way to do this would be to draw a line slightly below and above the path, making the path appear as a wider line.

P15. (drawing roses): Exercise P6.21, p 288. Submit this as program 15 using the electronic submission. Please call the file (and the class) Program15. Include an HTML file in the directory called Program15.html that displays your applet.

For the extra credit: Your program should prompt the user for the number of leaves using the GraphicsApplet interface (not the console). That is, you should use readInt(), not Console.in.readInt().