Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can i please ask how to write this task in Java ? Volume of Cylinder V=r2h You are tasked with writing a program to calculate

Can i please ask how to write this task in Java ?

image text in transcribed

Volume of Cylinder V=r2h You are tasked with writing a program to calculate the area of the base of the cylinder and the volume of the cylinder using the radius and height specified in the command line by the user. Your program should take two command line arguments. The first argument is the radius of the base of the cylinder. The second one is the height of the cylinder. Since command line arguments are stored as Strings, you will need to use Double.parseDouble() method to convert it to a double value. If the number of command line arguments is smaller than two, your program should output: Not enough arguments. If the number of command line arguments is greater than two, your program should output: Too many arguments. If the radius is negative, your program should output (without checking the value of the height): Radius cannot be negative. If the radius is non-negative but the height is negative, your program should output: Height cannot be negative. For all situations listed above, the program should terminate immediately after the message has been printed. The value for PI will should be set as a constant with the value 3.141592. (You should declare a variable with final static keyword) You can assume that the values for radius and height will always be decimal numbers. The volume of the cylinder can be calculated using the formula: V=r2h Your program should display the volume up to 2 decimal places. (use System.out.printf() method) The volume of the cylinder is 2d.p >

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases

Authors: Ian Robinson, Jim Webber, Emil Eifrem

1st Edition

1449356265, 978-1449356262

More Books

Students also viewed these Databases questions

Question

16. What makes them unique? (special features of the group)

Answered: 1 week ago