THINK FIRST·CODE LATER

← All labs

Little's law calculator

Problem

Little's law: WIP = throughput × cycle time. Given any two of the three values, compute the third.

Read lines until the end of input. Each line has a question type and two numbers:

  • CT wip throughput → print Cycle time: X days
  • TP wip cycletime → print Throughput: X cards/day
  • WIP throughput cycletime → print WIP: X cards

Print X with two decimals. If a division by zero would be needed, print Error: division by zero. For an unknown type print Error: unknown query TYPE.

Input:

CT 12 3
TP 10 5
WIP 2 4.5
CT 5 0
XYZ 1 2

Output:

Cycle time: 4.00 days
Throughput: 2.00 cards/day
WIP: 9.00 cards
Error: division by zero
Error: unknown query XYZ

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.

s2-1-data-1.txt

CT 12 3
TP 10 5
WIP 2 4.5
CT 5 0
XYZ 1 2
What your program must print for s2-1-data-1.txt
Cycle time: 4.00 days
Throughput: 2.00 cards/day
WIP: 9.00 cards
Error: division by zero
Error: unknown query XYZ

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 < s2-1-data-1.txt

Windows PowerShell does not understand <:

Get-Content s2-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.