Virtual Moped Assignment
Your assignment is to create a program that allows a user to drive a virtual Moped around the virtual streets of Manhattan.
The program accepts the following commands from the user:
- "go left"
- "go right"
- "straight on"
- "back up"
- "how we doin'?"
- "fill 'er up"
- "go to Bluestone Lane"
See below for details.
The user simply instructs the Moped to "go left", "go right", "straight on", or "back up", and Moped moves one block in the chosen direction.
- The Moped always starts out its life at 10th St. and 5th Ave., facing South.
- The program must announce the Moped's current location and orientation (which cardinal direction it is facing), when it starts, and with every move.
- If the user commands the Moped to "park", then the program outputs a message indicating the Moped has been parked on the sidewalk, and quits.
- Turning left while going forwards is a different thing from turning left while in reverse, hence your moped must keep track of its orientation.
- The moped's gas tank stores up to 1 gallon. It comes pre-filled.
- Driving the moped burns 1/20th of gallon per city block.
- If the user enters the command, "how we doin'?", the program outputs the current level of gasoline in the tank, as a percentage.
- If the Moped runs out of gas, the user is notified that the Moped has run out of gas and no longer drives, and the program should quit.
- To refill the gas tank, the user simply instructs the program to "fill 'er up".
The Moped has a special "go to Bluestone Lane" command that automatically drives the Moped from wherever it happens to be to Bluestone Lane restaurant at 8th St. and 4th Ave.
- the Moped should auto-drive itself one block at a time to the address of Bluestone Lane, outputting its location with each block.
- the Moped must use the same methods to move block-by-block and same amount of gas when homing as when being manually driven. If it needs to fill up gas while homing, it should do so automatically and then continue. The only difference between homing and manual driving is that the user is not being asked what the Moped should do, the Moped is deciding for itself.
Our Moped is paid for by advertising, and should output ads when it reaches the locations of our current clients:
- at 79th St. and 8th Ave., the Moped should output an ad for the American Museum of Natural History.
- at 74th St. and 1st Ave., the Moped should output an ad for Memorial Sloan Kettering.
- at 12th St. and 4th Ave., the Moped should output an ad for The Strand book shop.
- at 3rd St. and 6th Ave., the Moped should output an ad for Fayda Coffee Tea Cookies Cake shop.
If the user enters the command, "help", the program should display a list of commands that the program understands.
Our program should follow a few key assumptions:
- Assume that Manhattan is just a simple 200x10 grid of numbered city streets, thus ignoring real-world irregularities in geography and street names.
- Users must not be allowed to drive their Moped off the grid... sorry :( . If a user tries to do so, you must not allow it and ask them for a valid move until one is given.
- Assume that Streets are named 1st St, 2nd St, 3rd St, and so on up to 200th St.
- Assume that Avenues are named 1st Ave, 2nd Ave, 3rd Ave, 4th Ave and so on up to 10th Ave.
- Assume that Street numbers increase as you go North.
- Assume that Avenue numbers increase as you go West.
Your assignment must adhere to the following requirements:
- include a class named Moped that encapsulates all of the attributes and methods that our moped model needs in order to perform its functions.
- include a class named TestDrive which includes a main() method that starts up the program and facilitates the interaction between the user and the Moped.
- adhere to the object-oriented design principles of encapsulation and abstraction; make all data fields private; provide 'getter' and 'setter' methods as needed to control the behavior of your objects.
This is an example session. User input is bold.
Thanks for jumping on the moped. We're currently parked outside Dr. Rossinsky DDS's office at 10th St. and 5th Ave, facing South. May I say your teeth look very clean. What would you like to do? At any time, say "help" for assistance. back up Now at 11th St. and 5th Ave, facing South. back up Now at 12th St. and 5th Ave, facing South. go left Now at 12th St. and 4th Ave, facing West. Did you know The Strand has 18 Miles of new, used and rare books, and has been in business since 1927? how we doin'? The gas tank is currently 85% full. go to Bluestone Lane Now at 12th St. and 5th Ave, facing West. Now at 11th St. and 5th Ave, facing South. Now at 11th St. and 4th Ave, facing East. Now at 10th St. and 4th Ave, facing South. Now at 9th St. and 4th Ave, facing South. Now at 8th St. and 4th Ave, facing South. We have reached the Bluestone Lane. Enjoy your cappuccino. go left ...etc...
Create two more "drunk driver" Mopeds that drive themselves around erratically one block at a time.
- Drunk driver Mopeds must be instantiated from the same class as user-driven Mopeds. Your job is to modify the code in this class to allow for both kinds of Mopeds.
- These robotic self-driving Mopeds should automatically follow a random path, or any path you design for them, as they move one block at a time around Manhattan.
- Drunk driver Mopeds perform all the same behaviors as user-driven Mopeds, except they do so without human intervention.
- Drunk driver Mopeds use gas like the user's Moped, but they never run out of gas - they automatically fill up their gas when they are nearly out of gas.
- Drunk driver Mopeds never crash into each other. They only crash into the user's Moped.
- If the user's Moped and either of the robotic Mopeds are at the same location at the same time, they should crash into each other and the user should be notified that their Moped has crashed, is totally unusable, and the program should quit.
- Like the human-driven moped, each drunk driver moped must announce its location and orientation after every move. All output in this version must clearly identify which Moped is at which position.