package com.imooc.abstractTest;
public abstract class Shape {
public abstract void girth();
public abstract void area();
}
package com.imooc.abstractTest;
import java.util.Scanner;
public class Rectangle extends Shape {
Scanner input =new Scanner(System.in);
int width =input.nextInt();
int height= input.nextInt();
@Override
public void girth() {
int girth = (width+height)*2;
System.out.println("矩形周长为:"+girth);
}
@Override
public void area() {
double area= width*height;
System.out.println("矩形面积为:" +area);
}
}
package com.imooc.abstractTest;
import java.util.Scanner;
public class Circle extends Shape {
Scanner input =new Scanner(System.in);
int r =input.nextInt();
@Override
public void girth() {
double girth = 2*Math.PI*r;
System.out.println("圆形周长为:"+girth);
}
@Override
public void area() {
double area= Math.PI*r*r;
System.out.println("圆形面积为:" +area);
}
}
package com.imooc.abstractTest;
public class Test {
public static void main(String[] args) {
System.out.println("请输入长和宽");
Shape rec=new Rectangle();
rec.girth();
rec.area();
System.out.println();
System.out.println("请输入半径");
Shape cir =new Circle();
cir.girth();
cir.area();
}
}
点击查看更多内容
3人点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦