I need to design and code a Java program that calculates and prints the (D) diameter, the (C) circumference, or the (A) area of a circle, given the radius. The program inputs two data items: the calculation needed, and the radius of the circle. The program should continue to ask the user for values until the user enters 'Q' as the calculation type. The program should echo print the input data and prompt appropriately. Label the output and format to two decimal places. Is there anyone that can help me??
Example:
Enter the calculation type (A, C, D, N, Q):
N
New circle, Enter radius:
6.75
Enter the calculation type (A, C, D, N, Q):
A
The area of a circle with a radius of 6.75 is 143.14
D
The diameter of a circle with a radius of 6.75 is 13.50
Enter the calculation type (A, C, D, N, Q):
Q
Thank You.
I am new to Java and have no idea how to write the code for this to work right. Is there anyone that will take pity on a newbie?
This is what I have , but I can't get it to work.
import java.util.Scann er; // uses class Scanner
public class circleCalculato r
{
public static void main(String args[])
// create Scanner to obtain input
// prompt for input
{
Scanner input = new Scanner( System.in );
char option = '?'; // input character
String instring; // string
int radius = 0; // radius entered by user
int area = 0;
int circumference = 0;
int diameter = 0;
do
{
System.out.prin tln( "Enter calculation type (n = new, a = area, c = circumference, d = diameter, q = quit): " );
instring = input.next();
option = instring.charAt (0);
if ( option == 'N' || option == 'n' )
{
System.out.prin tln( "Enter the radius of the circle: " );
instring = input.next();
radius = instring.Int();
} // end if statement
while ( radius > 0 )
{
if ( option == 'A' || option == 'a' )
area = (double) (radius * radius) * 3.14159;
System.out.prin tf( "The area of the circle is: %f.2\n", area );
if ( option = 'C' || option = 'c' )
circumference = (2 * 3.14159) * (double) radius;
System.out.prin tf( "The area of the circle is: %f.2\n", circumference );
if ( option == 'D' || option == 'd' )
diameter = 2 * (double) radius;
System.out.prin tf( "The diameter of the circle is: %f.2\n", diameter );
} // end while statement
} while ( option == 'Q' && option == 'q' );
System.out.prin tln( "Thank You!" );
} // end main
} // end class
Example:
Enter the calculation type (A, C, D, N, Q):
N
New circle, Enter radius:
6.75
Enter the calculation type (A, C, D, N, Q):
A
The area of a circle with a radius of 6.75 is 143.14
D
The diameter of a circle with a radius of 6.75 is 13.50
Enter the calculation type (A, C, D, N, Q):
Q
Thank You.
I am new to Java and have no idea how to write the code for this to work right. Is there anyone that will take pity on a newbie?
This is what I have , but I can't get it to work.
import java.util.Scann er; // uses class Scanner
public class circleCalculato r
{
public static void main(String args[])
// create Scanner to obtain input
// prompt for input
{
Scanner input = new Scanner( System.in );
char option = '?'; // input character
String instring; // string
int radius = 0; // radius entered by user
int area = 0;
int circumference = 0;
int diameter = 0;
do
{
System.out.prin tln( "Enter calculation type (n = new, a = area, c = circumference, d = diameter, q = quit): " );
instring = input.next();
option = instring.charAt (0);
if ( option == 'N' || option == 'n' )
{
System.out.prin tln( "Enter the radius of the circle: " );
instring = input.next();
radius = instring.Int();
} // end if statement
while ( radius > 0 )
{
if ( option == 'A' || option == 'a' )
area = (double) (radius * radius) * 3.14159;
System.out.prin tf( "The area of the circle is: %f.2\n", area );
if ( option = 'C' || option = 'c' )
circumference = (2 * 3.14159) * (double) radius;
System.out.prin tf( "The area of the circle is: %f.2\n", circumference );
if ( option == 'D' || option == 'd' )
diameter = 2 * (double) radius;
System.out.prin tf( "The diameter of the circle is: %f.2\n", diameter );
} // end while statement
} while ( option == 'Q' && option == 'q' );
System.out.prin tln( "Thank You!" );
} // end main
} // end class
Comment