THINK FIRST·CODE LATER

← All labs

The iceberg: lifetime cost of StudyBuddy

Problem

Most of a system's cost comes after the first release. Estimate StudyBuddy's lifetime cost.

Input (one line): D P Y G

  • D — cost of the first version (development), in yuan (a real number);
  • P — maintenance cost in year 1, as a percentage of D (e.g. 20 means 20% of D);
  • Y — number of years in operation (integer, 0 or more);
  • G — yearly growth of maintenance cost, in percent (the system gets bigger and older: year k costs (1 + G/100) times year k−1).

Print, with one decimal (String.format("%.1f", x)):

Year 1: <cost>
...
Year Y: <cost>
Development: <D>
Maintenance: <sum of all years>
Total: <D + maintenance>
Maintenance share: <percent of total>%

then Maintenance exceeds development in year k for the first year in which the cumulative maintenance cost becomes strictly greater than D, or Maintenance never exceeds development if it never does. If Y is 0, print no year lines and a share of 0.0%.

Input 100000 20 5 10 gives:

Year 1: 20000.0
Year 2: 22000.0
Year 3: 24200.0
Year 4: 26620.0
Year 5: 29282.0
Development: 100000.0
Maintenance: 122102.0
Total: 222102.0
Maintenance share: 55.0%
Maintenance exceeds development in year 5

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.

s1-4-data-1.txt

100000 20 5 10
What your program must print for s1-4-data-1.txt
Year 1: 20000.0
Year 2: 22000.0
Year 3: 24200.0
Year 4: 26620.0
Year 5: 29282.0
Development: 100000.0
Maintenance: 122102.0
Total: 222102.0
Maintenance share: 55.0%
Maintenance exceeds development in year 5

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

Windows PowerShell does not understand <:

Get-Content s1-4-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.