Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Overview In this assignment, you'll write a simple simulator for bus movement along a network of roads. We've provided you with starter code that models

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Overview In this assignment, you'll write a simple simulator for bus movement along a network of roads. We've provided you with starter code that models the roads, and a skeleton of a class representing a bus, but it will be up to you to translate a written description of how buses move into code. Goals Model state in an object. Translate a written description of behavior into code. Test code using both unit tests and an interactive visualizer. First, look at the Roadmap class. This class models a two-dimensional map; coordinates on the map are identified by an x and y coordinate. As you move north, the y coordinate decreases; as you move west, the x coordinate decreases. Each location on the map is either a road or not a road: the setRoad method lets you set a particular location to be a road (or not), the isRoad method checks whether a valid location is a road, and so on. Next, look at the Bus class. A bus has a number and location associated with it (x and y) as well as a particular Roadmap. Bus also has a (currently empty) move() method. The comment above the move() method explains how it should work. Next, take look at (and perhaps run) the BusVisualizer class. Here, you can set up a map interactively, using the left mouse button to add or remove roads, the right mouse button to add buses, the delete key to remove them, and the spacebar to tell them to move(). Try it out, but you'll find they don't move (because, of course, the Bus.move() method is empty). Next, note we've provided you with a few unit tests. Some are mainly sanity checks; they test code that we wrote and that should work - unless you break something we provided! Others (in particular the ones starting with testMove...) are examining the behavior of the Bus.move() method, and will fail until you correctly implement it. You will also need to add (probably to Roadmap) one or more methods that, given a location, check whether the adjacent locations have roads. You'll likely use these methods in your move() method. Something to watch out for Doing anything listed above is fine. But what you cannot do is change the parameters of existing public methods (or remove existing methods), including constructors. (Roadmap class) package simulator; A map of road(s), where each cell is numbered with an x and y coordinate. The north-western-most corner is at location(0,0). Moving south means increasing the y value; moving east means increasing the x value. Each cell either is or is not a road. @author liberato */ public class Roadmap { public final int xSize; public final int ySize; private final boolean[][] isRoad; public RoadMap(int x, int y) { isRoad = new boolean[x][y]; xSize = x; ySize = y; *** V. Lan AR ySize y; } * Use this method to create a Roadmap from a string. Use 'X' for non-road and *'.' for road. * For example, the string X.. X.X" * (including whitespace!) creates a 3x3 map, where there is a short road * that travels north from the center of the bottom of the map, and then * turns east to the center of the right-hand side of the map. @param s a string representing a map of roads @return a new Roadmap instance */ public static Roadmap fromString(String s) { String[] lines = 5.trim().split("\\s+"); final int xSize = lines[@].length(); final int ySize lines.length; Roadmap roadMap = new RoadMap(xSize, ySize); for (int y = 0; y 0) { busCount--; buses[busCount] = null; } } } public void mousePressed() { int x = mousex / 20; int y = mousey / 20; if (mouseButton LEFT) { boolean isclear = true; for (int i = 0; i 0) { busCount--; buses[busCount] = null; } } } public void mousePressed() { int x = mousex / 20; int y = mousey / 20; if (mouseButton LEFT) { boolean isclear = true; for (int i = 0; i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Database Technology Edbt 88 International Conference On Extending Database Technology Venice Italy March 14 18 1988 Proceedings Lncs 303

Authors: Joachim W. Schmidt ,Stefano Ceri ,Michele Missikoff

1988th Edition

3540190740, 978-3540190745

More Books

Students also viewed these Databases questions

Question

How does talent and expertise contribute to career advancement?

Answered: 1 week ago

Question

1. Describe the power of nonverbal communication

Answered: 1 week ago