package com.imooc;
import java.util.Scanner;
import java.lang.Math;
public abstract class Shape {//父类shape
double a;
double b;
double r;
public abstract void c();
public abstract void s();
public void Shape(){
Scanner input1=new Scanner(System.in);
Scanner input2=new Scanner(System.in);
System.out.print("请输入长a");
double a1=input1.nextDouble();
System.out.println();
System.out.print("请输入宽b");
double b1=input2.nextDouble();
System.out.println();
Scanner input3=new Scanner(System.in);
System.out.print("请输入圆的半径");
double r=input3.nextDouble();
}
}
2.子类Circle
package com.imooc;
import java.util.Scanner;
public class Circle extends Shape {
@Override
public void c() {
// TODO Auto-generated method stub
double r=super.r;
double c=2*Math.PI*r;
System.out.println("圆的周长为"+c);
}
@Override
public void s() {
double r=super.r;
double s=Math.PI*r*r;
System.out.println("圆的面积为"+s);
}
}
3.子类Retangle
package com.imooc;
import java.util.Scanner;
public class Retangle extends Shape {
@Override
public void c() {
// TODO Auto-generated method stub
double a=super.a;
double b=super.b;
double c=2*(a+b);
System.out.println("长方形的周长为"+c);
}
@Override
public void s() {
// TODO Auto-generated method stub
// TODO Auto-generated method stub
double a=super.a;
double b=super.b;
double s=a*b;
System.out.println("长方形的面积为"+s);
}
}
4.测试类Inital
package com.imooc;
public class Iniatal {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Shape h1=new Retangle();
h1.c();
h1.s();
Shape h2=new Circle();
h2.c();
h2.s();
}
}
结果得到的怎么是全零,我不是做了外界输入参数的值吗,请问问题出在哪里?
qq_山水禾田_0
无敌的大鹏鸟
相关分类