Question: The Walking Drunkard (or Random Walk) Problem focus on Encapsulation and putting Java Collections to work (80 pts) : Imagine an infinite grid of streets

The Walking Drunkard (or Random Walk) Problem focus on Encapsulation and putting Java Collections to work (80 pts):

Imagine an infinite grid of streets where locations/intersections are represented as integer pairs (x, y) or more precisely, (avenue, street) pairs. For example, you might be on the intersection of 8th Ave and 52nd Street. Now consider someone that has had 1 drink too many that person starts at a given intersection and then stumbles to the next intersection, but in a completely random, poorly-thought-out direction. So the drunkard might start at 7th Ave and 90th street - then randomly picks one of eight directions as a next step. Notice that diagonal steps represent a 2 linear-block move while the others represent a single linear block move:

Forward / North 7th Ave and 91st Street

Right / East 6th Ave and 90th Street.

Backward / South 7th Ave and 89th Street.

Left / West 8th Ave and 90th Street

Forward-Right / Northeast 6th Ave and 91st Street

Backward-Right / Southeast 6th Ave and 89nt Street

Backward-Left / Southwest 8th Ave and 89nt Street

Forward-Left / Northwest 8th Ave and 91st Street

See NYC grid below as an example, but our grid can be larger in scope and as you may experience, negative values for Streets / Avenues are allowed.

Lab 5 is all about modeling random movement and keeping key statistics on a block-by-block trip covered by drunken (or random) behavior ;-)

Very often as a professional software developer, youll be asked to modify existing or partially completed code, rather than start an application from scratch. Thats exactly what youre being asked to do here.

Youre being provided with four starter entities:

Direction enum defines Direction constants, and methods related to using Direction values.

Intersection Class simply models the street corner or the (avenue, street) coordinates.

DrunkWalker Class models a drunkard navigating intersection to intersection.

DrunkWalkTester Class is a test harness for the DrunkWalker Class.

Your job will be to submit all 4 Classes/enums with updates that make them far more functional than they were when you found them.

Heres what needs to be done:

Direction enum already encompasses 4 of the 8 (plus NONE) Direction-set values required. You need to:

Add the 4 additional Values

Make appropriate changes to the getNextRandom() method to consider the 4 new Direction values.

Intersection:Use Eclipse code generating features (in Editor pane right-click->source ) to generate:

a constructor that accepts avenue and street values (and of course assigns them to the Class data members).

getters/setters for the two private data members (avenue, street).

hashCode() and equals() methods

toString() method.

Populate the main() method to perform the following:

Create 2 instances of Intersection that represent two different grid/street corners.

Display the value of both instances using toString() either explicitly or implicitly.

Test the equality of the two instances you created using the equals() method display the results of the if/equals test proving that equals is working properly.

DrunkWalker models the drunkard navigating intersection to intersection. Your update tasks for this Class are follows:

Implement the hollowed out

DrunkWalker(int avenue, int street) constructor.

Complete the implementation of the following methods. In all cases, let the comments in each method be your guide:

public void step().

public String getLocation()

public void fastForward(int steps)

public int howFar()

private void takeAStep()

public void displayWalkDetails()

add the appropriate Collection data members to support the methods above

Implement a toString() method using the Eclipse->Source feature (do this last when you have the full structure of the Class worked out. You dont need to include all data members state in toString() you decide what you want to see displayed while developing and testing the application.

DrunkWalkTester is a test harness for the DrunkWalker Class.

You will leave the existing code in the runTest() method alone, but youll add to it as dictated by the comments that appear at the end of that method:

/**

* Expand the test above to include the following ...

* Create a 2nd instances of DrunkWalker - Harvey

* Have then race each - which instance (billy or harvey)

* manages to walk a greater distance with 200 steps?

*

* Also invoke the displayWalkDetails() on both instances.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!