Question

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 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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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

Add a comment
Know the answer?
Add Answer to:
Program62 Write a class that has a main method and two more methods for performing calculations...
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 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...

  • Project Objectives: To develop ability to write void and value returning methods and to call them...

    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...

  • A) One of the problems that have been discussed in the class is to write a...

    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...

  • A) One of the problems that have been discussed in the class is to write a simple C++ program to ...

    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...

  • Design and implement class Circle to represent a circle object. The class defines the following attributes...

    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...

    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....

    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...

    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...

  • Create a class named Circle with fields named radius, diameter, and area. Include a constructor that...

    Create a class named Circle with fields named radius, diameter, and area. Include a constructor that sets the radius to 1 and calculates the other two values. Also include methods named setRadius() and getRadius(). The setRadius() method not only sets the radius, but it also calculates the other two values. (The diameter of a circle is twice the radius, and the area of a circle is pi multiplied by the square of the radius. Use the Math class PI constant...

  • 14.8 Prog 8 Overload methods (find avg) Write a program to find the average of a...

    14.8 Prog 8 Overload methods (find avg) Write a program to find the average of a set numbers (assume that the numbers in the set is less than 20) using overload methods. The program first prompts the user to enter a character; if the character is 'I' or 'i', then invokes the appropriate methods to process integer data set; if the character is 'R' or 'r', then invokes the appropriate methods to process real number data set; if the inputted...

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