top of page

Programming Sample Assignment

Problem Description:

This assignment is designed to extend your understanding of

  1. Graphics programming

  2. GUI programming

  3. Concurrency and multi-threading

  4. Abstraction, encapsulation, inheritance, interfaces and abstract classes, and polymorphism.

You are going to develop a software application (starting with the given codebase) that simulates the movements of people and various types of vehicles within a section of the city center that is illustrated below as a colorful map composed of streets, bicycle paths, green areas, and traffic lights.

On the above city map, the black frame indicates the border cells of the area of interest. The green areas are indicated by light green color, bicycle paths are indicated by dark green color, grey areas marked with yellow dashed lanes are the streets, and the (green-red-yellow) colored circles represent the traffic lights, respectively.


The provided starter (or skeleton) code for the project includes a complete (and correct) implementation of the application’s graphical user interface (GUI):

  • The GUI reads in the terrain information of the city map and starting locations of the humans and vehicles from the provided file city_map.txt and renders the city map that includes various types of terrain, humans, and vehicles. Note that the city map view stretches up to the borders of the center panel of the application window.

  • There are buttons to START and STOP the city animation and run it a single time STEP at a time (i.e., advance and redraw all;) and to RESET the vehicles to their initial layout.

  • The speed of city animation is controllable via a slider at the bottom of the interface.

  • Each time the GUI redraws, it moves each of the vehicles. If any two vehicles end up on the same square, the GUI tells the vehicles that they have collided, which may ‘kill’ or suspend them temporarily. Those vehicles appear upside down on the screen

  • Also, debug information can be shown using a checkbox.

    • If debug information is enabled, all (x, y) grid positions on the map are labeled, and every vehicle’s toString output is shown next to the vehicle

    • You can put any information you like into your vehicles’ toString methods to help you debug their behavior.

Your main task in this assignment is to implement the classes to model the people and various types of vehicles wandering around the city center. Since those classes have many similarities, you should spot them and exploit the object-oriented inheritance and polymorphism in your class design, resulting in an effective implementation without writing unnecessary repetitive code.

  • You must write Vehicle sub-classes (and a common parent class called AbstractVehicle) for this assignment.

  • Each Vehicle class must implement the provided Vehicle interface described in this document.

  • Vehicle behavior includes some randomness. Therefore, your project code should only create a single object of type Random that all Vehicle objects can share.


Vehicle Descriptions:

Note that a Human is considered a type of Vehicle for the purposes of this assignment.


Human

  • Constructor: public Human (int theX, int theY, Direction theDir)

  • Images: human.gif (alive), human_dead.gif (dead)

  • Movement behavior:

    • moves in a random direction (straight, left, or right), always on grass or crosswalks.

    • never reverses its direction unless there is no other option.

    • will not turn to avoid the crosswalk.

    • If a human is next to a crosswalk, it will always choose to turn to face in the crosswalk direction. (You can assume that the map of terrain will never contain crosswalks that are so close together that a human might be adjacent to more than one at the same time.)

    • does not travel through crosswalks when the crosswalk light is green. If a human is facing a green crosswalk, it will wait until the light changes to yellow and then cross through the crosswalk.

    • Humans travel through crosswalks when the crosswalk light is yellow or red.

  • Collision behavior: gets hurt if s/he is hit by any vehicle (other than a human,) and stays in hospital for 45 time steps.




Komentari


bottom of page