THINK FIRST·CODE LATER

← All labs

A cylindrical water tank

Problem

A village wants to buy a cylindrical water tank and paint its wall. From the radius and the height in metres, WaterTank prints the base area, the volume, the capacity in litres (1 m³ = 1000 litres) and the area of the curved wall.

baseArea ← radius × radius × π        volume ← baseArea × height
litres   ← volume × 1000              wall   ← 2 × π × radius × height

Use 3.14159 for π. For the input

1.5 2

the program prints

Base area: 7.07 m2
Volume: 14.14 m3
Capacity: 14137 litres
Wall to paint: 18.85 m2

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.

l2-8-data-1.txt

1.5 2
What your program must print for l2-8-data-1.txt
Base area: 7.07 m2
Volume: 14.14 m3
Capacity: 14137 litres
Wall to paint: 18.85 m2

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

Windows PowerShell does not understand <:

Get-Content l2-8-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.