Java创建圆形类Circle.属性:半径r;方法:计算周长、显示周长、计算面积、显示面积,并创建测试类CircleTest 5
3个回答
展开全部
package test;
class Circle {
private double r;
private double c = 0.0;
private double s = 0.0;
public Circle(double r) {
this.r = r;
}
/**
* 计算周长
*/
public void calcPerimeter() {
c = Math.PI * r * 2;
}
/**
* 展示周长
*/
public void showPerimeter() {
System.out.printf("周长为:%.2f", c);
System.out.println();
}
/**
* 计算面积
*/
public void calcArea() {
s = Math.PI * Math.pow(r, 2);
}
/**
* 展示面积
*/
public void showArea() {
System.out.printf("面积为:%.2f", s);
System.out.println();
}
}
public class Test {
public static void main(String[] args) {
Circle circle = new Circle(1.0);
circle.calcArea();
circle.showArea();
circle.calcPerimeter();
circle.showPerimeter();
}
}
class Circle {
private double r;
private double c = 0.0;
private double s = 0.0;
public Circle(double r) {
this.r = r;
}
/**
* 计算周长
*/
public void calcPerimeter() {
c = Math.PI * r * 2;
}
/**
* 展示周长
*/
public void showPerimeter() {
System.out.printf("周长为:%.2f", c);
System.out.println();
}
/**
* 计算面积
*/
public void calcArea() {
s = Math.PI * Math.pow(r, 2);
}
/**
* 展示面积
*/
public void showArea() {
System.out.printf("面积为:%.2f", s);
System.out.println();
}
}
public class Test {
public static void main(String[] args) {
Circle circle = new Circle(1.0);
circle.calcArea();
circle.showArea();
circle.calcPerimeter();
circle.showPerimeter();
}
}
展开全部
public class Circle {
private Double r;
public Double getR() {
return r;
}
public void setR(Double r) {
this.r = r;
}
public Circle(Double r) {
this.r = r;
}
@Override
public String toString() {
return "Circle{" +
"r=" + r +
'}';
}
}
public class CircleMethod {
public static Double circlePerimeter(Circle circle) {
Double perimeter;
perimeter = 2 * circle.getR() * Math.PI;
return perimeter;
}
public static Double circleArea(Circle circle) {
Double area;
area = circle.getR() * circle.getR() * Math.PI;
return area;
}
}
public class CircleaTest {
public static void main(String[] args) {
Circle circle = new Circle(3.0);
System.out.println("圆的面积是:" + CircleMethod.circleArea(circle));
System.out.println("圆的周长是:" + CircleMethod.circlePerimeter(circle));
}
}
private Double r;
public Double getR() {
return r;
}
public void setR(Double r) {
this.r = r;
}
public Circle(Double r) {
this.r = r;
}
@Override
public String toString() {
return "Circle{" +
"r=" + r +
'}';
}
}
public class CircleMethod {
public static Double circlePerimeter(Circle circle) {
Double perimeter;
perimeter = 2 * circle.getR() * Math.PI;
return perimeter;
}
public static Double circleArea(Circle circle) {
Double area;
area = circle.getR() * circle.getR() * Math.PI;
return area;
}
}
public class CircleaTest {
public static void main(String[] args) {
Circle circle = new Circle(3.0);
System.out.println("圆的面积是:" + CircleMethod.circleArea(circle));
System.out.println("圆的周长是:" + CircleMethod.circlePerimeter(circle));
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
class Cricle{
private Double r;
public Cricle(Double r) {
this.r = r;
}
public Double perimeter(){
Double perimeter= 2*Math.PI*this.r;
System.out.println(perimeter);
return perimeter;
}
public Double area(){
Double area=Math.PI*this.r*this.r;
System.out.println(area);
return area;
}
}
class CricleTest{
public static void main(String[] args) {
Cricle cricle = new Cricle(5.00);
cricle.perimeter();
cricle.area();
}
}
private Double r;
public Cricle(Double r) {
this.r = r;
}
public Double perimeter(){
Double perimeter= 2*Math.PI*this.r;
System.out.println(perimeter);
return perimeter;
}
public Double area(){
Double area=Math.PI*this.r*this.r;
System.out.println(area);
return area;
}
}
class CricleTest{
public static void main(String[] args) {
Cricle cricle = new Cricle(5.00);
cricle.perimeter();
cricle.area();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询