彦祖们救救孩子吧 这到底是什么错误

笔记 专栏收录该内容
1 篇文章 0 订阅

救救孩子吧 这到底是什么错误

彦祖们救救孩子吧 这到底是什么错误

这个method getArea in class circle cannot be applied to given types
还又 getPerimeter 什么的一直找不到什么原因,我承认我菜,请大佬们救救我 拜托了彦祖们。

import java.util.*;


interface Shape{
	public double getArea();
	public double getPerimeter();
}

class Figure{
	String type;
	
	public Figure(){
		
	}
	
	public Figure(String type){
		this.type = type;
	}
	
	double getArea(){
		
	}
	
}

class Circle extends Figure implements Shape{
	public double radius; //半径
	public static final double pi = 3.14;
	Circle(){
		
	}
	
	public Circle(String type,double r){
		super(type);
		radius = r;
	}
	
	public double getArea(){
		//static final double pi = 3.1415 this will define in main function
		double area = this.radius * this.radius * pi;
		return area;
	}
	
	public double getPerimeter(){
		double perimeter = 2 * pi * this.radius;
		return perimeter;
	}
	
	public String toString(){
		double a = getArea(radius);
		double p = getPerimeter(radius);
		return "radius="+radius+",perimeter="+p+",area="+a;
	}
}

class Square extends Figure implements Shape{
	public double len;
	public double width;
	public Square(){
		
	}
	
	public Square(String type,double len,double width){
		super(type);
		this.len = len;
		this.width = width;
	}
	
	public double getArea(){
		return len * width;
	}
	
	public double getPerimeter(){
		return len + width;
	}
	
	public String toString(){
		double a = getArea(len,width);
		double p = getPerimeter(len,width);
		return "len="+len+",width="+width+",area="+a+",perimeter="+p;
	}

}

class Coin{
	public static final int zheng_coin = 1;
	public static final int fan_coin = 0;
	
	public static int throwOut(){
		int coin = (int)(Math.random() * 100);
		if(coin % 2 == 1){
			return zheng_coin;
		}else{
			return fan_coin;
		}
	}
}

class Judge{
	public static Figure judgeCreate(){
		Figure figure=null;
		if(Coin.throwOut()==zheng_coin){
			figure = new Circle("circle",4);
		}else{
			figure = new Square("square",5,6);
		}	
	}
}

public class FigureCalculate{
	public static void main(String args[]){
		//public static final double pi = 3.14159; 
		Figure figure = Judge.judgeCreate();
		System.out.println(figure);	
		System.out.println("this figure was a "+figure.type);
		System.out.println("the area is"+figure.getArea());
		System.out.println("the perimeter is"+figure.getPerimeter());
		
	}
}

不知道那两个函数是怎么了
  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 打赏
    打赏
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 1024 设计师:白松林 返回首页

打赏作者

weixin_47240281

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值