Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this question you are going to write code relating to a drawbridge. Our drawbridges are road bridges over rivers. While small boats can pass

image text in transcribed

In this question you are going to write code relating to a drawbridge. Our drawbridges are road bridges over rivers. While small boats can pass under a bridge while the bridge is in use (by cars, tall boats cannot go post a bridge unless is open. When a bridge is open, all vehicular (cars, etc) and pedestrians traffic must stop. Our drawings are all very wide, so both cars and boats may proceed in both directions at once (two-way traffic). We will assume that all our drawbridges have the same CLEARANCE. Boats with height less than CLEARANCE may proceed at any time. Boats with height greater than or equal to CLEARANCE may proceed only when the drawbridge is open. All our drawbridges will start in the closed state. In case you are unfamiliar with a drawbridge, you will find pictures and explanations in the appendix. Our real-time system that models a drawbridge has the following threads Controller: The controller thread is in charge of opening and closing the bridge. There is thread for each drawbridge. The code in the Controller's run() method will invoke Drawbridge methods open () and close () to open and bridge, respectively. Car: There is one thread for each car. Cars can cross the bridge from cast to west, or from west to east. The code in the Car class run () method will invoke Drawbridge methods goWest () and goEast () so that the car can to cross the bridge from east to west, or from west to east. Boat: There is one thread for each boat, Boats can pass the bridge from north to south, or from Boat south to north. The code in the Boat class run () method will invoke Drawbridge methods goSouth () and goNorth () so the boat can go past the bridge from north to south and from south to north, respectively. You do not need to write the code Controller, Car or Boat classes or the main program that creates the threads and ensures that they are all sharing the same Drawbridge object. You are going to write some of the code for the Drawbridge class. Here is an outline of the class public class Drawbridge { //all our drawbridges have a clearance of 10m. (Boats 10n or //over can proceed only when the drawbridge is open.) public final static int CLEARANCE = 10: //member variables go here //** open: Opens the drawbridge, (If already open does nothing.] This method has no arguments and returns void. To simulate the time it takes to (a) wait until all cars currently crossing the bridge have done so, and (b) then to open the bridge, this method sleeps for 1 minute before it returns. No cars or tall boats may proceed while the bridge is in the process of opening. //Close: Closes the drawbridge. (Similar to open ()) goWest: A car goes over the bridge from east to west. This method has no arguments and returns void. This method should not return until the car has safely gone over the bridge (while the bridge is closed). To simulate the time it takes to cross the bridge, this method sleeps for 10 seconds before it returns. In other words, on car does not have to wait until another has finished crossing the bridge before it can start.) goSouth: A boat goes under the bridge from north to south. This method has one arguments, the height of the boat (in meters) and returns void. This method should not return until the boat has safely gone past the bridge. Small boats may go under the bridge at any time. Tall boats may only proceed when the bridge is open. To simulate the time it takes to pass the bridge (for any size boat), this method sleeps for 30 seconds before it returns. they may proceed in parallel. In other words one boat does not have to finish going under the bridge before another can start (And as mentioned is goWest above, small boats and cars can also proceed in parallel) //goNorth: A boat goes under the bridge form south to north. //(similar to goSouth (). } In this question you are going to write code relating to a drawbridge. Our drawbridges are road bridges over rivers. While small boats can pass under a bridge while the bridge is in use (by cars, tall boats cannot go post a bridge unless is open. When a bridge is open, all vehicular (cars, etc) and pedestrians traffic must stop. Our drawings are all very wide, so both cars and boats may proceed in both directions at once (two-way traffic). We will assume that all our drawbridges have the same CLEARANCE. Boats with height less than CLEARANCE may proceed at any time. Boats with height greater than or equal to CLEARANCE may proceed only when the drawbridge is open. All our drawbridges will start in the closed state. In case you are unfamiliar with a drawbridge, you will find pictures and explanations in the appendix. Our real-time system that models a drawbridge has the following threads Controller: The controller thread is in charge of opening and closing the bridge. There is thread for each drawbridge. The code in the Controller's run() method will invoke Drawbridge methods open () and close () to open and bridge, respectively. Car: There is one thread for each car. Cars can cross the bridge from cast to west, or from west to east. The code in the Car class run () method will invoke Drawbridge methods goWest () and goEast () so that the car can to cross the bridge from east to west, or from west to east. Boat: There is one thread for each boat, Boats can pass the bridge from north to south, or from Boat south to north. The code in the Boat class run () method will invoke Drawbridge methods goSouth () and goNorth () so the boat can go past the bridge from north to south and from south to north, respectively. You do not need to write the code Controller, Car or Boat classes or the main program that creates the threads and ensures that they are all sharing the same Drawbridge object. You are going to write some of the code for the Drawbridge class. Here is an outline of the class public class Drawbridge { //all our drawbridges have a clearance of 10m. (Boats 10n or //over can proceed only when the drawbridge is open.) public final static int CLEARANCE = 10: //member variables go here //** open: Opens the drawbridge, (If already open does nothing.] This method has no arguments and returns void. To simulate the time it takes to (a) wait until all cars currently crossing the bridge have done so, and (b) then to open the bridge, this method sleeps for 1 minute before it returns. No cars or tall boats may proceed while the bridge is in the process of opening. //Close: Closes the drawbridge. (Similar to open ()) goWest: A car goes over the bridge from east to west. This method has no arguments and returns void. This method should not return until the car has safely gone over the bridge (while the bridge is closed). To simulate the time it takes to cross the bridge, this method sleeps for 10 seconds before it returns. In other words, on car does not have to wait until another has finished crossing the bridge before it can start.) goSouth: A boat goes under the bridge from north to south. This method has one arguments, the height of the boat (in meters) and returns void. This method should not return until the boat has safely gone past the bridge. Small boats may go under the bridge at any time. Tall boats may only proceed when the bridge is open. To simulate the time it takes to pass the bridge (for any size boat), this method sleeps for 30 seconds before it returns. they may proceed in parallel. In other words one boat does not have to finish going under the bridge before another can start (And as mentioned is goWest above, small boats and cars can also proceed in parallel) //goNorth: A boat goes under the bridge form south to north. //(similar to goSouth (). }

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

Step: 3

blur-text-image

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

Students also viewed these Databases questions

Question

b. Why were these values considered important?

Answered: 1 week ago