Your task is to fix the device limit tool so that every command updates the data correctly and prints the correct success message or error reason. It reads the state from data/plan.json and data/sessions.json, processes the login, logout and switch commands, and writes the updated state back.
├── data/
│ ├── plan.json # Read-only plan (plan, device_limit)
│ └── sessions.json # Persistent sessions state (active)
├── src/
│ ├── main/java/com/devices/
│ │ ├── Commands.java # Command handlers
│ │ ├── FileIo.java # State file load and save
│ │ ├── Main.java # CLI entry point
│ │ ├── Models.java # Data models
│ │ └── Parser.java # JSON parsing
│ └── test/java/com/devices/
│ └── CommandsTest.java
├── devices # CLI launcher script
├── run.sh # Setup and run script
├── reset.sh # Restore data/sessions.json to its initial state
├── test.sh # Test script (writes junit.xml)
├── pom.xml # Maven build configuration
└── README.md
mvn -B -ntp -DskipTests packagebash run.shbash test.shRestore data/sessions.json to its initial state.
bash reset.shEach example below runs independently against the initial data files: the Family plan with a limit of 5, and five devices signed in: phone, tv, laptop, kids tablet and game console.
Command:
./devices login projectorOutput:
Error: DEVICE_LIMIT
The five devices on the list already take every slot on the plan, so there is no room for projector. data/sessions.json is not modified.
Command:
./devices login phoneOutput:
Error: ALREADY_LOGGED_IN
phone is on the list already, so it is not signed in a second time. data/sessions.json is not modified.
Command:
./devices switch laptop projectorOutput:
Switched laptop to projector (5/5)
Final data/sessions.json:
{"active":["phone","tv","projector","kids tablet","game console"]}laptop is signed out and projector signed in by the one command. projector takes the position laptop had, and the other devices are untouched.
Commands:
./devices logout tv
./devices login projectorOutput:
tv signed out (4/5)
projector signed in (5/5)
Final data/sessions.json:
{"active":["phone","laptop","kids tablet","game console","projector"]}With tv signed out there is room on the plan for projector, which joins the end of the list.
Commands:
./devices switch watch tv
./devices switch phone tvOutput:
Error: NOT_LOGGED_IN
Error: ALREADY_LOGGED_IN
watch is not signed in, so it cannot be the device that leaves. tv is signed in already, so it cannot be the device that arrives. Neither command changes the file.