package java第二季;public abstract class ZJ311shape {public abstract double circle();public abstract double area(); }//父类import java.util.Scanner;public class ZJ311Circle extends ZJ311shape { Scanner input=new Scanner(System.in); @Override public double circle() { // TODO 自动生成的方法存根 System.out.println("请输入园的半径:"); double r=input.nextDouble(); double c=2*r*3.14; return c; } @Override public double area() { // TODO 自动生成的方法存根 System.out.println("请输入园的半径:"); double r=input.nextDouble(); double a=r*r*3.14; return a; }}//子类圆import java.util.Scanner;public class ZJ311Rectangle extends ZJ311shape { Scanner input=new Scanner(System.in); @Override public double circle() { // TODO 自动生成的方法存根 System.out.println("请输入矩形的长:"); double l=input.nextDouble(); System.out.println("请输入矩形的宽:"); double w=input.nextDouble(); double c=2*(l+w); return c; } @Override public double area() { // TODO 自动生成的方法存根 System.out.println("请输入矩形的长:"); double l=input.nextDouble(); System.out.println("请输入矩形的宽:"); double w=input.nextDouble(); double a=l*w; return a; }}//子类矩形public class ZJ311intial {public static void main(String[] args){ ZJ311shape A=new ZJ311Circle(); ZJ311shape B=new ZJ311Rectangle(); double 圆周=A.circle(); double 圆的面积=A.area();}}//测试主函数
添加回答
举报
0/150
提交
取消