P: 1

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.Scanner; // uses class Scanner
public class circleCalculator
{
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.println( "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.println( "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.printf( "The area of the circle is: %f.2\n", area );
if ( option = 'C'  option = 'c' )
circumference = (2 * 3.14159) * (double) radius;
System.out.printf( "The area of the circle is: %f.2\n", circumference );
if ( option == 'D'  option == 'd' )
diameter = 2 * (double) radius;
System.out.printf( "The diameter of the circle is: %f.2\n", diameter );
} // end while statement
} while ( option == 'Q' && option == 'q' );
System.out.println( "Thank You!" );
} // end main
} // end class
 
Share this Question
P: 6

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.Scanner; // uses class Scanner
public class circleCalculator
{
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.println( "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.println( "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.printf( "The area of the circle is: %f.2\n", area );
if ( option = 'C'  option = 'c' )
circumference = (2 * 3.14159) * (double) radius;
System.out.printf( "The area of the circle is: %f.2\n", circumference );
if ( option == 'D'  option == 'd' )
diameter = 2 * (double) radius;
System.out.printf( "The diameter of the circle is: %f.2\n", diameter );
} // end while statement
} while ( option == 'Q' && option == 'q' );
System.out.println( "Thank You!" );
} // end main
} // end class
Hi
After looking ur code I found these errors
1. U have defined radious, area, circumference diameter as integer but it should be float type .
2. last if condition u provvide && it should be  .
3 . U are assigning in if statement U have to give "== "sign in steade of "="
    Question stats  viewed: 6647
 replies: 1
 date asked: Oct 16 '05
