Question

Write a method that calculates an area of a circle given a radius as an input....

Write a method that calculates an area of a circle given a radius as an input. Call the method you define in the main and test your problem. The input is being given by the user in the main and sent to the method as an input.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;

public class CircleArea {

    public static double areaOfCircle(double radius) {
        return Math.PI * radius * radius;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter radius of the circle: ");
        double radius = in.nextDouble();
        System.out.println("Area of the circle is " + areaOfCircle(radius));
    }
}

Add a comment
Know the answer?
Add Answer to:
Write a method that calculates an area of a circle given a radius as an input....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a shell script that given a radius, calculates the area of a circle. (Hint –...

    Write a shell script that given a radius, calculates the area of a circle. (Hint – don’t write this from scratch. Find another script that reads user input and performs a calculation, then modify it to meet your needs.) Save the script in your home directory with the name circle.sh The formula for calculating the area is: Area=Π*Radius2 You can use 3.14 for Π, and either do Radius*Radius or Radius^2 to get the square of the radius. Use the scale...

  • Write a Java console application that prompts the user to enter the radius of a circle,...

    Write a Java console application that prompts the user to enter the radius of a circle, then prints its radius, diameter, circumference, and area. Write a JavaFX GUI application to do the same calculation, and draw the circle. The Console Output Enter the radius of the circle: 1.2 The radius is 1.2 The diameter is 2.4 The circumference is 7.5398223686155035 The area is 4.523893421169302 Write and document your program per class coding conventions. Add an instance variable double radius. Generate...

  • Define an interface named Shape with a single method named area that calculates the area of...

    Define an interface named Shape with a single method named area that calculates the area of the geometric shape:        public double area(); Next, define a class named Circle that implements Shape. The Circle class should have an instance variable for the radius, a constructor that sets the radius, an accessor and a mutator method for the radius, and an implementation of the area method. Define another class named Rectangle that implements Shape. The Rectangle class should have instance variables...

  • Program62 Write a class that has a main method and two more methods for performing calculations...

    Program62 Write a class that has a main method and two more methods for performing calculations on a circle. One void method calculates and prints the circumference of the circle and the other method returns the area of the circle. The main method should prompt the user to enter the diameter of the circle (as a double) and call the other methods with this input as an argument. Both the circumference and area should be displayed accurate to three decimal...

  • Problem: Given information about a circle, rectangle and a triangle, calculate the area of the shape...

    Problem: Given information about a circle, rectangle and a triangle, calculate the area of the shape from the information supplied. Write pseudocode to solve this problem and write a Python program that asks the user to input the required information for a shape and then calculates the area of the shape. Geometry Calculator 1. Calculate the Area of a Circle 2. Calculate the Area of a Rectangle 3. Calculate the Area of a Triangle 4. Quit Enter your choice (1...

  • Write a program that calculates the area and circumference of a circle. It should ask the...

    Write a program that calculates the area and circumference of a circle. It should ask the user first to enter the number of circles n, then reads the radius of each circle and stores it in an array. The program then finds the area and the circumference, as in the following equations, and prints them in a tabular format as shown in the sample output. Area = πr2 , Circumference = 2πr, π = 3.14159 Sample Output: Enter the number...

  • Develop a VB.Net application that gets input from the user about the radius of a circle,...

    Develop a VB.Net application that gets input from the user about the radius of a circle, calculates the diameter, circumference, and area of the circle, and displays the results in three textboxes. The three textboxes should be disabled for user input. A logic flow and the form that implements the flow are required for this problem.

  • Create a class Circle with one instance variable of type double called radius. Then define an...

    Create a class Circle with one instance variable of type double called radius. Then define an appropriate constructor that takes an initial value for the radius, get and set methods for the radius, and methods getArea and getPerimeter. Create a class RightTriangle with three instance variables of type double called base, height, and hypotenuse. Then define an appropriate constructor that takes initial values for the base and height and calculates the hypotenuse, a single set method which takes new values...

  • #1 Write a java program which calculates the area of either a Triangle or a Rectangle....

    #1 Write a java program which calculates the area of either a Triangle or a Rectangle. Use Scanner to take an input field to tell you if the area to be calculated is for a Triangle or is for a Rectangle. Depending on that input - the program must call either the Triangle method or the Rectangle method. Each of those methods must receive 2 input fields from the user - one for base and one for height in order...

  • Using the c++ language 1) Create a function that calculates the area of a circle "circeArea...

    Using the c++ language 1) Create a function that calculates the area of a circle "circeArea ()". The function should take a single float parameter radius and return a float area. 2) Create a function to calculate the area of a rectangle. 3) Creat a function to calculate the area of a triangle when given base and height as parameters provided by the user.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT