Practice w23am2q2
Model-View (UML)
Interpret the Java code below. It represents an automated parking lot system. It provides an API to monitor the status of a parking lot. Currently, the ParkingLot class can display available parking spots and draw the parking lot map. We want to add a pie chart showing the current ratio of available and occupied parking spots. Unfortunately, we seem to be making this class too big.
Refactor/restructure this code AS A UML CLASS DIAGRAM OF RESTRUCTURED CODE to implement the Model-View pattern (variation of the MVC pattern, but without a dedicated Controller). Separate out models and views, and add new views as necessary to address the new features that were asked for. Explicitly improve cohesion with your restructuring of the code. You can make new classes and interfaces, you can move methods, rename methods, and make new methods.
- Add a pie chart
- Restructure into MVC using just models and views.
On the diagram, CLEARLY LABEL which class(es) represents the Model and the View components. You do NOT need to have a Controller.
Draw a well-designed UML class diagram to represent this information. Provide the basic abstractions, attributes, methods, relationships, multiplicities, and navigabilities as appropriate. "...” means much code is omitted.
Do NOT submit Java, submit UML!
import java.util.*;
class ParkingLot {
private int capacity;
private int numCars;
private HashMap<Integer, Boolean> spots;
/* ... */
/* called by the parking detection system */
protected void carIn(int spot) {
spots.put(spot, true);
numCars++;
render();
}
/* called by the parking detection system */
protected void carOut(int spot) {
spots.put(spot, false);
numCars--;
render();
}
// lists available parking spots
public void listSpots() {
/* ... */
}
// draws a map of the parking spots and their status
public void drawMap() {
/* ... */
}
public void render() {
listSpots();
drawMap();
}
}