Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

my feedback for this lab was to elminate variables used only once. can someone explain that to me and how it should look? import java.util.Scanner;

my feedback for this lab was to elminate variables used only once. can someone explain that to me and how it should look?
import java.util.Scanner;
public class Circles03{
public static void main(String[] args){
// Method for radius calculation.
double radius = getRadius();
// Method for circumference calculation.
calculateCircumference(radius);
// Method for area calculation.
calculateArea(radius);
// Method for rounded area calculation.
calculateRoundedArea(radius);
}
/* This method gets the radius from the user and returns the
* user-input radius.
*/
public static double getRadius(){
// Instantiates the scanner.
Scanner in = new Scanner(System.in);
// Prompts the user for a radius and stores as a return double.
System.out.println("Radius:");
return in.nextDouble();
}
/* This method calculates and displays the circumference of the
* circle. The parameter is the radius of the circle.
*/
public static void calculateCircumference(double radius){
// Calculates and outputs the circumference of the circle.
double circumference =(2* Math.PI * radius);
System.out.println("CIRCUMFERENCE ="+ circumference);
}
/* This method calculates and displays the area of the circle.
* The parameter is the radius of the circle.
*/
public static void calculateArea(double radius){
// Calculates and outputs the area of the circle.
double area = Math.PI * Math.pow(radius,2);
System.out.println("AREA ="+ area);
}
/* This method calculates and displays the rounded area of the
* circle. The parameter is the radius of the circle.
*/
public static void calculateRoundedArea(double radius){
// Calculates the rounded area of a circle.
double area = Math.PI * Math.pow(radius,2);
// Creates a variable for the rounded area and casts it
// to an integer.
int roundedArea =(int) Math.round(area);
// Outputs the rounded area.
System.out.println("ROUNDED AREA ="+ roundedArea);
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro Oracle Fusion Applications Installation And Administration

Authors: Tushar Thakker

1st Edition

1484209834, 9781484209837

More Books

Students also viewed these Databases questions