DrunkWalk - System.out.println (); System.out.print...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
// *********************************************************** // TestWalk.java // // Program to test methods in the RandomWalk class. // *********************************************************** import java.util.Scanner; public class DrunkWalk { public static void main (String[] args) { int maxSteps; // maximum number of steps in a walk int maxCoord; // the maximum x and y coordinate int x, y; // starting x and y coordinates for a walk int numDrunks; Scanner scan = new Scanner(System.in); RandomWalk walk1; System.out.println ("\nDrunken Walk");
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: System.out.println (); System.out.print ("Enter the maximum number of steps: "); maxSteps = scan.nextInt(); System.out.print ("Enter the boundary for the square: "); maxCoord = scan.nextInt(); System.out.print ("Enter the number of drunks: "); numDrunks = scan.nextInt(); int fellOff = 0; for (int i=0; i<numDrunks; i++) { RandomWalk drunk = new RandomWalk(maxSteps, maxCoord); drunk.walk(); if (!drunk.inBounds()) fellOff++; } System.out.println(fellOff + " out of " + numDrunks + " fell off."); } }...
View Full Document

This note was uploaded on 03/22/2010 for the course CS 202 taught by Professor Fong during the Spring '10 term at SIU Carbondale.

Ask a homework question - tutors are online