THINK FIRST·CODE LATER

← All labs

Coupling metrics and layer violations

Problem

Analyse StudyBuddy's module dependencies.

Input:

LAYERS presentation service domain data
<lines: module layer>
DEPS
<lines: from to>   (module "from" depends on module "to")

The LAYERS line lists the layers from top to bottom. A module may depend only on modules in the same or a lower layer.

Output, for each module in the order it was declared:

module: fan-in=Ca fan-out=Ce instability=I

with I = Ce / (Ca + Ce) printed with two decimals (0.00 if Ca + Ce = 0). Duplicate dependency lines count once. Then the violations in input order, VIOLATION: from (layerA) -> to (layerB), or No layer violations.

Input:

LAYERS presentation service domain data
web presentation
board service
post domain
repo data
DEPS
web board
board post
board repo
post repo
repo web

Output:

web: fan-in=1 fan-out=1 instability=0.50
board: fan-in=1 fan-out=2 instability=0.67
post: fan-in=1 fan-out=1 instability=0.50
repo: fan-in=2 fan-out=1 instability=0.33
VIOLATION: repo (data) -> web (presentation)

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

s6-1-data-1.txt

LAYERS presentation service domain data
web presentation
board service
post domain
repo data
DEPS
web board
board post
board repo
post repo
repo web
What your program must print for s6-1-data-1.txt
web: fan-in=1 fan-out=1 instability=0.50
board: fan-in=1 fan-out=2 instability=0.67
post: fan-in=1 fan-out=1 instability=0.50
repo: fan-in=2 fan-out=1 instability=0.33
VIOLATION: repo (data) -> web (presentation)

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < s6-1-data-1.txt

Windows PowerShell does not understand <:

Get-Content s6-1-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.