CSC B07 Software Design Assignment | Individual

CSC B07 Software Design
Assignment | Individual
For this Assignment, you will implement a set of Java classes according to the UML diagrams provided in
this assignment description.
Learning Outcomes
By the end of this assignment, you should have:

  1. gained an understanding of how one speci es the design for an object oriented (OO) program using
    basic UML class diagrams,
  2. implemented a given OO design, speci ed by a UML class diagram, in Java,
  3. become more familiar with Java generics, interfaces, abstract classes, and inheritance,
  4. practised writing high quality Java documentation.
    What to do for this assignment
  5. Your svn repository now contains the starter directories and les for this assignment. Follow the usual
    process to get the starter code from the svn repo.
  6. You should see a directory called a1. It contains a directory A1soln with a sub-directory src, which
    in turn contains the sub-directories game, sprites, and ui.
  7. Follow the usual process to create a workspace a1 and a Java Project A1soln in Eclipse, so that you
    can see the starter packages and work on them in Eclipse.
  8. Complete the Java program according to the UML diagram in Figures 2 through 4. Commit often!
  9. To submit your work, add any newly created Java les and commit all your changes under the existing
    directory A1soln.
    Commit only the given directories and the .java les. Do not commit .class les or the les
    and directories generated by Eclipse, such as bin, doc, .project, etc. Marks will be deducted for
    submitting these les.
    The Great Vacuum Race
    We are implementing a simple game. The game board is a 2-dimensional grid. Each cell in this grid represents
    either a section of hallway, a piece of wall, or a dumpster. We denote a wall with the symbol X, a hallway
    with a blank space, and dumpster with U. There are two players in this game | two vacuums. We denote
    them with symbols 1 and 2. Some of the cells are dirty: they contain dust (the symbol .) or dust balls (the
    symbol o). The vacuums’ objective is to clean up as many dirty cells as possible. The dust is stationary, but
    the dust balls move about the grid and each cell that a dust ball visits becomes (or stays) dusty when the
    dust ball leaves. Figure 1 (left) shows an example initial state of the vacuum game. Notice the two vacuums
    (1 and 2), 16 dusty cells (.), four dust balls (o), and three dumpsters (U).
    In our simple UI implementation, vacuum 1 moves left when the user presses the ‘a’ key, moves right on
    the ‘d’ key, moves up on the ‘w’ key and moves down on the ‘s’ key. Similarly, vacuum 2 moves left on
    the ‘j’ key, moves right on the ‘l’ key, moves up on the ‘i’ key and moves down on the ‘k’ key.
    Only one vacuum can move at a time, but they do not need to alternate turns (e.g., vacuum 1 could move
    three times in a row). A vacuum cannot move onto the other vacuum (or a wall, of course), but can move
    X U …. X o X X
    X X X X oX XXX X
    X.. X X X XXXXXX X
    X1 X UXXX X 2 X X
    X X ..o XXXX X X
    X ….. X o XU X X
    X U …. X . X X
    X X 1 X X .X .XXX X
    X X UXXX X 2 X X
    X X …. XXXX X X
    X ….. X …oXU X X
    Figure 1: Example Initial and Intermediate States of the Game
    onto dust, a dust ball, a dumpster (or clean hallway, of course). After any vacuum moves, all dust balls on
    the grid move randomly (including a chance of not moving, too). One exception is a dust ball that happens
    to be under a vacuum at the time | these dust balls do not move.
    When a vacuum enters a cell, it cleans the cell | i.e., any dust or dust ball is removed; the cell becomes a
    clean hallway | but only if the vacuum is not yet full (see below). Figure 1 (right) shows an example state
    of a vacuum game after vacuums 1 and 2 made some moves. Notice that the dust balls moved (dirtying
    more hallways) and that vacuum 1 cleaned some dust.
    Each time a vacuum cleans dirt, the vacuum’s score is incremented. In our implementation, dust balls are
    worth more than dust. The score accrued for cleaning dust or a dust ball is de ned in the starter code.
    Each vacuum has a capacity. Cleaning up dust or a dust ball adds a constant amount to the fullness of
    the vacuum. When a vacuum becomes full, it cannot clean any more dirt; it can still go to dirty hallways,
    but it has no e ect on the dirt that is there. A vacuum that enters a cell with a dumpster is emptied (i.e.,
    its fullness becomes a constant that corresponds to \empty vacuum”); thus, if a vacuum is full, in order to
    resume cleaning dirt, it must visit a dumpster. Dumpsters have no limit on their capacity.
    The game ends when all dirt (dust and dust balls) is gone. The vacuum with the higher score wins, or, if
    the two scores are equal, we declare a tie.
    The Implementation
    We have largely designed The Great Vacuum Race game for you. Your task is to study the UML class
    diagrams provided and to produce a corresponding Java implementation. In addition to what is speci ed,
    you may add private helper methods (and it is a very good idea to do so!).
    Grid is a generic abstract class that de nes a two dimensional grid of objects of type T, where T is its type
    parameter. It declares four abstract methods (getCell, setCell, getNumRows, and getNumColumns), and
    overrides hashCode, equals, and toString. The method toString must produce a String representation
    of the Grid in exactly the same way as speci ed in Figure 1. Two Grids are considered equal if they have
    the same dimensions, and contain equal elements in all corresponding cells.
    You will need to implement two children of Grid: a List-based implementation ListGrid and a Map-based
    implementation MapGrid. Study the UML class diagram in Figure 2 for details. This code belongs in package
    For our vacuum game, you will store and manipulate a Grid of Sprites. Carefully study the UML diagram
    that de nes the various Sprites that will go on the grid, and the relationships between them. See Figure 3.
    This code belongs in package sprites. Here are a few things to note about the Sprites:
     Each Dirt object stores in its value attribute the score accrued for cleaning it.
     Every Vacuum sits on top of another Sprite, even if it is just a CleanHallway. The Vacuum itself, not
    the Grid, stores what’s under it. No other Sprite can have anything under it. Initially, a Vacuum sits
    on top of a CleanHallway.
  • grid: Map>
    … private instance(s): your design …
  • MapGrid(numRows: int, numColumns: int)
  • getCell(row: int, column: int): T <>
  • setCell(row: int, column: int, item: T): void <>
  • getNumRows(): int <>
  • getNumColumns(): int <>
  • hashCode(): int <>
  • equals(other: Object): boolean
  • toString(): String
  • grid: Grid
  • vacuum1: Vacuum
  • vacuum2: Vacuum
  • dusts: List
  • dustBalls: List
  • random: Random
  • VacuumGame(layoutFilename: String,
    gridType: GridType)
  • getNumRows(): int
  • getNumColumns(): int
  • getSprite(row: int, col: int): Sprite
  • getGrid(): Grid
  • getVacuumOne(): Vacuum
  • getVacuumTwo(): Vacuum
  • move(nextMove: char): void
  • gameOver(): boolean
  • getWinner(): char
    … private methods — your design …
  • grid: List>
    … private instance(s): your design …
  • ListGrid(numRows: int, numColumns: int)
    Figure 2: Grid and VacuumGame (in package game)
    The class VacuumGame is where all the action will happen! Class VacuumGame belongs in package game. It
    keeps track of the Grid of Sprites, the two Vacuum players, and all the Dirts. Several things to note about
    this class:
     The constructor for VacuumGame takes a path to a text le and reads and initializes the Grid. The
    starter code has examples that demonstrate the correct content and format for an input le.
     The method move takes a character. If it is a valid move character, and the move it describes is an
    allowed move (see the description above and the starter code), this method changes the position of the
    corresponding vacuum accordingly. Afterwards, the Dustballs move randomly.
     The method getWinner() returns the character that corresponds to the winning player or a tie. See
    Constants for details.
    Finally, the interface Ui de nes a user interface for the Vacuum Game. We have provided a very simple Gui
    implementation. Your task is to provide a text UI that implements the same interface. The text UI should
    read from and print to System.out. See Figure 4 for the UML class diagrams. This code belongs
    in package ui.
    The Starter Code and Evaluation
    Your repository contains the starter code for this assignment. Make sure to study it carefully before you
    begin coding! Pay careful attention to the class Constants: you should make extensive use of it in your
    In addition to correctness, your submission will also be marked for style | be sure to run the checkstyle
    Eclipse plug-in often as you develop your solution.
    Have you. . .
     run the checkstyle plug-in?
     followed the style guidelines?
     documented your code well? Generated the HTML documentation to see it in the form that the TAs
    will grade?
     tested your code on the lab computers?
     committed all of your les (and no extra les) in the correct directory?
  • Dust(row: int, column: int, value: int)
  • score: int
  • capacity: int
  • fullness: int
  • under: Sprite
  • Vacuum(symbol: char, row: int, column: int, capacity: int)
  • moveTo(row: int, column: int): void
  • clean(score: int): boolean
  • empty(): void
  • getScore(): int
  • getUnder(): Sprite
  • setUnder(under: Sprite): void
  • Dumpster(row: int, column: int)
  • Wall(row: int, column: int)
  • CleanHallway(row: int, column: int)
  • DustBall(row: int, column: int, value: int)
  • moveTo(row: int, column: int): void
  • value: int
  • Dirt(symbol: char, row: int, column: int, value: int)
  • getValue(): int
  • hashCode(): int
  • equals(Object obj): boolean
  • symbol: char
  • row: int
  • column: int
  • Sprite(symbol: char, row: int, column: int)
  • getSymbol(): char
  • getRow(): int
  • getColumn(): int
  • updateCoordinates(row: int, column:int): void
  • toString(): String
  • hashCode(): int
  • equals(Object obj): boolean
    Figure 3: The Various Sprites (in package sprites)
  • game: VacuumGame
  • tiles: JLabel[][]
  • Gui(game: VacuumGame)
  • getGame(): VacuumGame
  • updateLabels(): void
  • launchGame(): void
  • displayWinner(): void
  • game: VacuumGame
  • TextUi(game: VacuumGame)
    Figure 4: The User Interface (in package ui)