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 places.
Sample Output (user input shown in blue)
Enter the diameter of the circle
12.25
The circumference is 38.485
The area is 117.859
If you need any corrections/clarifications kindly comment.
Please give a Thumps Up if you like the answer.
Java Program
import java.util.Scanner;
public class Circle
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
//Prompt the user to enter the diameter of the circle
(as a double)
System.out.print("Enter the diameter of the
circle:");
double diameter =
sc.nextDouble();
//void method print_circumference(radius) that
calculates and prints the circumference of the circle
print_circumference(diameter);
//calculate_area(radius) method returns the area of
the circle
double
area=calculate_area(diameter);
System.out.printf("\nThe
area is %.3f", area);
}
public static void print_circumference(double
diameter)
{
double radius=diameter/2;
//Circumference = 2*PI*radius
double circumference=
Math.PI * 2*radius;
System.out.printf( "The
circumference is %.3f",circumference) ;
}
public static double calculate_area(double
diameter)
{
double radius=diameter/2;
//Area = PI*radius*radius
double area = Math.PI *
(radius * radius);
return(area);
}
}
Output
Enter the diameter of the circle:12.25
The circumference is 38.485
The area is 117.859
Program62 Write a class that has a main method and two more methods for performing calculations...
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...
Project Objectives: To develop ability to write void and value returning methods and to call them -- Introduction: Methods are commonly used to break a problem down into small manageable pieces. A large task can be broken down into smaller tasks (methods) that contain the details of how to complete that small task. The larger problem is then solved by implementing the smaller tasks (calling the methods) in the correct order. This also allows for efficiencies, since the method can...
C++ programming question will upvote
A) One of the problems that have been discussed in the class is to write a simple C++ program to determine the area and circumference of a circle of a given radius. In this lab you will be rewriting the program again but this time you will be writing some functions to take care of the user input and math. Specifically, your main function should look like the following int main //the radius of the...
A) One of the problems that have been discussed in the class is to write a simple C++ program to determine the area and circumference of a circle of a given radius. In this lab you will be rewriting the program again but this time you will be writing some functions to take care of the user input and math. Specifically, your main function should look like the following: int main() { double radius; double area; double circumference; //the radius...
C++ 8. Circle Class Write a Circle class that has the following member variables: • radius: a double • pi: a double initialized with the value 3.14159 The class should have the following member functions: • Default Constructor. A default constructor that sets radius to 0.0. • Constructor. Accepts the radius of the circle as an argument. • setRadius. A mutator function for the radius variable. • getRadius. An accessor function for the radius variable. • getArea. Returns the area...
what are the debuggers in Java? import java.text.NumberFormat; /** * * This class represents a circle that would be used as part * of a larger geometry application */ public class Circle { private double radius; private NumberFormat numberFormat; /** * Constructor for the Circle. * @param radius for the circle */ public Circle(double r) { radius = r; } /** * This method uses the radius of the circle to compute...
Design and implement class Circle to represent a circle object. The class defines the following attributes (variables) and methods: 1. A private variable of type double named radius to represent the radius. Set to 1. 2. Constructor Methods: • Python : An overloaded constructor method to create a default circle. • C# & Java: Default Constructor with no arguments. • C# & Java: Constructor method that creates a circle with user-specified radius. 3. Method getRadius() that returns the radius. 4. ...
Write a java class definition for a circle object. The object should be capable of setting radius, and computing its area and circumference. Use this to create two Circle objects with radius 10 and 40.5, respectively. Print their areas and circumference. Here is the Java class file (Circle.java). Compile it. public class Circle{ //Instance Variables private double PI = 3.1459; private double radius; //Methods public Circle ( ) { } //get method (Accessor Methods ) public double getRadius (...
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.
Write a Java program that has the following methods: findSum - a method that takes in three integers and returns the sum of these three integers; findAverage - a method that takes in three integers and returns the average of these three integers (as a double value) Within the main method read in 3 integers from the user and call above two methods by passing the three integers. Your program should print the user provided three integers and results of...