Question

Write a method that returns the area of a circle given the radius. Use the Math.PI...

Write a method that returns the area of a circle given the radius.

Use the Math.PI method.

Homework Answers

Answer #1
import java.util.Scanner;

public class AreaOfCircle {

    public static double getCircleArea(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 circle: ");
        double radius = in.nextDouble();
        System.out.println("Area of circle is " + getCircleArea(radius));
    }
}

Know the answer?
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
Similar Questions
java Consider the following class definition: public class Circle { private double radius; public Circle (double...
java Consider the following class definition: public class Circle { private double radius; public Circle (double r) { radius = r ; } public double getArea(){ return Math.PI * radius * radius; } public double getRadius(){ return radius; } } a) Write a toString method for this class. The method should return a string containing the radius and area of the circle; For example “The area of a circle with radius 2.0 is 12.1.” b) Writeaequalsmethodforthisclass.ThemethodshouldacceptaCircleobjectasan argument. It should return...
Write a JAVA method called printComputeArea that receives the radius of a circle as an argument...
Write a JAVA method called printComputeArea that receives the radius of a circle as an argument and prints its area
# given a radius, find the area of a circle def get_area_circle(r):        """        ...
# given a radius, find the area of a circle def get_area_circle(r):        """         what it takes             radius of a circle (any positive real number)         what it does:             computes the area of a circle             given a radius, find the area of a circle             area = pi*r2 (pi times r squared)         what it returns             area of a circle. Any positive real number (float)     """         # your code goes in...
Please write a program to calculate the area of a circle. Area =3.14*Radius*Radius. Input Radius. Please...
Please write a program to calculate the area of a circle. Area =3.14*Radius*Radius. Input Radius. Please write a program to calculate the area of a rectangle. Area =Width*Length. Input Width and Length. Please write a program to covert Fahrenheit degree to Celsius degree. The formula is C=(F-32)*5/9. Input Fahrenheit degree. Please write a program to covert Celsius degree to Fahrenheit degree. The formula is F=C*9/5+32. Input Celsius degree.
write a method named area with one double parameter named radius. The method needs to return...
write a method named area with one double parameter named radius. The method needs to return a double value that represents the area of a circle. If the parameter radius is negative, Then return -1.0 to represent an invalid value write another overloaded method with 2 parameters side1 and side2 (both doubles) where side1 and side2 represent the sides of a rectangle. The method needs to return an area of a rectangle. If either or both parameters is /are a...
Complete the program to calculate and print the circumference and area of a circle, rounded to...
Complete the program to calculate and print the circumference and area of a circle, rounded to the nearest tenth (1 decimal place). The starter code already prompts the user and takes in the radius as a double-value input. You need to do the calculations and print the results. I recommend using the printf() command (described in chapter 3 of the book) to print the results with the correct rounding. import java.util.Scanner; class Circle { static Scanner sc = new Scanner(System.in);...
Write a Python program to calculate the area of a circle. The user needs to input...
Write a Python program to calculate the area of a circle. The user needs to input the value of the radius of the circle. area = 3.14 x radius x radius You should use a function named circlearea to perform the calculation 3. Write a Python program to calculate the area of a square. The user needs to input the value of the length of the square. area = len*len You should use a function named squarearea to perform the...
Write a paragraph - complemented by a drawing - that describes a method of estimating the...
Write a paragraph - complemented by a drawing - that describes a method of estimating the area of the interior of a circle - a method that does not employ the familiar formula A = πr2 where A is the area of the interior the circle given that r is the radius of the circle.
In C programming, Thank you Write a program to compute the area of a circle. You...
In C programming, Thank you Write a program to compute the area of a circle. You have to write a complete “C” program that compiles and runs in Codeblocks. Program requirements: 1. Declare the variables needed: radius (r) and area (yourLastName). 2. Calculate and print the area of each circle. 3. The program MUST prompt the user for a new radius (r) over and over until the user types -1. 5. Use the type double for all decimal numbers. 6....
in java Implement a class Balloon. A balloon starts out with radius 0. Supply a method...
in java Implement a class Balloon. A balloon starts out with radius 0. Supply a method public void inflate(double amount) that increases the radius by the given amount. Supply a method public double getVolume() that returns the current volume of the balloon; volume of a balloon is represented as: V = (4/3) * PI * r^3 Use Math.PI for the value of π. To compute the cube of a value r, you can use Math.pow (https://www.tutorialspoint.com/java/lang/math_pow.htm) or r*r*r Write a...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT