Discover the answers to your questions at Westonci.ca, where experts share their knowledge and insights with you. Get detailed and precise answers to your questions from a dedicated community of experts on our Q&A platform. Get detailed and accurate answers to your questions from a dedicated community of experts on our Q&A platform.

Unit 2: Lesson 6 - Coding Activity 1
Write code that takes input from the user for the radius (double) of a circle, and create a circle with that radius. The program should then print a sentence with the circumference and area of the circle. You should use the appropriate Circle methods to obtain the circumference and area of the circle rather than calculating these values yourself.

Sample run:

Enter the radius of the circle:
> 3
A circle with a radius 3.0 has a circumference of 18.84955592153876 and an area of 28.274333882308138
Hint: You can approach this problem by saving the double (radius) as a variable and then creating the Circle, or you can create the Circle and use methods from the Circle class to set the radius.

what i have already in java:
/* Lesson 6 Coding Activity Question 1 */

import java.util.Scanner;
import shapes.*;

public class U2_L6_Activity_One
{
public static void main(String[] args)
{

Scanner scan = new Scanner(System.in);

System.out.println("Enter radius: ");

double r = scan.nextDouble();

Circle c = new Circle(r);

double area = c.getArea();

r = c.getRadius();

c.setRadius(r*2);

area = c.getArea();

C = c.getCircumfrence();

System.out.println("A circle with a radius " + r + " has a circumference of " + C + " and an area of "+ area);

}
}
Keeps giving me an error for circumference.
Any help?


Sagot :

We appreciate your visit. Our platform is always here to offer accurate and reliable answers. Return anytime. We appreciate your time. Please revisit us for more reliable answers to any questions you may have. Thank you for visiting Westonci.ca, your go-to source for reliable answers. Come back soon for more expert insights.