Classwork(CW): Class Diagrams
Mapping the House
Objective: Translate Java source code into a visual UML Class Diagram using Mermaid syntax.
Source Code
Analyze the following Java classes. Look closely at how the classes relate to one another. Pay attention to inheritance (subclassing) and composition (one class containing another).
// The Base Class
public class Room {
public int squareFeet;
private String wallpaperColor;
}
// The Subclass
public class Kitchen extends Room {
public boolean hasDishwasher;
}
// The Container Class
public class House {
public String address;
public Room masterBedroom;
}
Instructions
- Navigate to Mermaid.live.
- In the left-hand code editor, use the
classDiagramsyntax to recreate these three classes. -
Requirements for your diagram:
- Show public variables using the
+symbol. - Show the private variable using the
-symbol. - Represent the Inheritance relationship (Kitchen is a Room) using
<|--. - Represent the Composition relationship (House has a Room) using
*--.
- Show public variables using the
Syntax Reminders
| Relationship | Mermaid Syntax | Description |
|---|---|---|
| Inheritance | Parent < | -- Child | |
| Composition | Container *-- Contained | “Has a” (ownership) relationship |
| Public | + | Visible to all |
| Private | - | Hidden/Internal |
Check-off Criteria
To get credit for this activity, please raise your green popsicle once your diagram on Mermaid.live matches the following:
-
All 3 classes (
House,Room,Kitchen) are present. -
Kitchenpoints toRoomwith an inheritance arrow. -
Houseconnects toRoomwith a composition diamond. -
wallpaperColoris correctly marked as private.