exercisesMarch1708

exercisesMarch1708 - • Ask the user for a starting point...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
COMP202 Instructor: Ladan Mahabadi March 17, 2008 (Hypothetical) Saturday night walk: Imagine walking on a line. Write a program that depicts a random walk on a line that has n (n being a user-input value) random integers less than 50 on it. Each point on the line has an x coordinate and a counter variable that keeps track of how many times a point is visited. The moves on the lines are limited to left or right and your walks should not exceed the boundaries of the line. Your program should: Ask the user for n Create n random points (located between 0 and 50 on the real line) Display the created points to the user Display the maximum and the minimum point to the user
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: • Ask the user for a starting point • Start the walk such that Moving left or right is equally likely Your movements can’t exceed the boundaries • (i.e. if at any point, you were exceeding the boundary just stay at your current position) public class Point { private int x; private int visitedCount; public Point(int newX) { x = newX; visitedCount = 0; } public int getX() { return x; } public void incrementCount() { visitedCount++; } public String toString() { String result = "Location: " + x + " has been visited " + visitedCount + " times."; return result; } }...
View Full Document

{[ snackBarMessage ]}

Page1 / 2

exercisesMarch1708 - • Ask the user for a starting point...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online