How to correct file if I need to use for cicles? circles -- area = ?*radius^2 (f
ID: 3714336 • Letter: H
Question
How to correct file if I need to use for cicles?
circles -- area = ?*radius^2 (format the answer to have two decimal places)?
thank you
import java.util.Scanner;
import java.text.DecimalFormat;
public class Area
{
public static double area(double radius)
{
return (double)?*radius^2 )(radius,2));
}
public static double area(double width,double length)
{
return (width * length);
}
public static double area(double base1,double base2,double height)
{
return (double)((base1 + base2) * height / 2);
}
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
double radius = 3;
double width = 4.0;
double length = 2.0;
double base1 = 3;
double base2 = 4;
double height = 5;
// Create a DecimalFormat object
DecimalFormat fmt = new DecimalFormat("0.0");
//Calculating Area of Circle:
System.out.printf("%.2f ",Area.area(radius));
// Calculating Area of Rectangle:
System.out.println("" + Area.area(width,length));
//Calculating Area of Trapezoid:
System.out.printf("%,.1f " ,Area.area(base1,base2,height));
}
}
Explanation / Answer
Area.java
import java.util.Scanner;
import java.text.DecimalFormat;
public class Area
{
public static double area(double radius)
{
return (double)Math.PI*radius*radius;
}
public static double area(double width,double length)
{
return (width * length);
}
public static double area(double base1,double base2,double height)
{
return (double)((base1 + base2) * height / 2);
}
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
double radius = 3;
double width = 4.0;
double length = 2.0;
double base1 = 3;
double base2 = 4;
double height = 5;
// Create a DecimalFormat object
DecimalFormat fmt = new DecimalFormat("0.0");
//Calculating Area of Circle:
System.out.printf("%.2f ",Area.area(radius));
// Calculating Area of Rectangle:
System.out.println("" + Area.area(width,length));
//Calculating Area of Trapezoid:
System.out.printf("%,.1f " ,Area.area(base1,base2,height));
}
}
Output:
28.27
8.0
17.5
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.