In Java
The Circle. In one program, write 3 separate functions, and use
them.
Calculate area of circle, parameter radius.
Use math lib ‘pow’ function to help with calc: calcArea
Calculate diameter of circle, parameter radius: calcDiameter
Calculate circumference of circle, parameter
radius:calcCircumference
Test radius sizes: 5, 42, 12.30
package a1; import java.util.Scanner; public class Circle { // calcArea method public static double calcArea(double radius){ // Returning area of circle return Math.PI*Math.pow(radius,2); } // calcDiameter method public static double calcDiameter(double radius){ // Returning diameter of circle return 2*radius; } // circumference method public static double calcCircumference(double radius){ // Returning circumference of circle return 2*Math.PI*radius; } // main method public static void main(String[] args) { Scanner scan = new Scanner(System.in); // Reading radius from user System.out.print("Enter radius: "); double radius = scan.nextDouble(); // Printing area System.out.println("Area of circle = "+calcArea(radius)); // Printing diameter System.out.println("Diameter of circle = "+calcDiameter(radius)); // Printing circumference System.out.println("Circumference of circle = "+calcCircumference(radius)); } }
Get Answers For Free
Most questions answered within 1 hours.