跪求大神帮忙指正我的代码还有哪些地方需要改进
图形类
package com.chy3.practice;
public abstract class Shape {
public abstract String square(double a,double b);
public abstract String circumFerence(double a,double b);
}
矩形类
package com.chy3.practice;
import java.util.Scanner;
public class Rectangle extends Shape {
Scanner input = new Scanner(System.in);
public void cal(){
System.out.println("计算矩形周长和面积");
System.out.println("请输入两条边长");
double stre1 = input.nextDouble();
double stre2 = input.nextDouble();
System.out.println("周长为: "+circumFerence(stre1, stre2));
System.out.println("面积为: "+square(stre1, stre2));
}
@Override
public String square(double a,double b) {
// TODO Auto-generated method stub
double squ = a*b;
return "矩形面积为:"+squ;
}
@Override
public String circumFerence(double a,double b) {
// TODO Auto-generated method stub
double cif = (a+b)*2;
return "矩形周长为"+cif;
}
}
圆形类
package com.chy3.practice;
import java.lang.Math;
import java.util.Scanner;
public class Circle extends Shape {
Scanner input = new Scanner(System.in);
Double p = Math.PI;
public void cal(){
System.out.println("计算圆形的周长和面积");
System.out.println("请输入半径和直径");
double r = input.nextDouble();
double d = input.nextDouble();
System.out.println("周长为: "+circumFerence(r, d));
System.out.println("面积为: "+square(r, d));
}
@Override
public String square(double a,double b) {
// TODO Auto-generated method stub
double squ = p*a*a;
return "圆的面积为"+squ;
}
@Override
public String circumFerence(double a,double b) {
// TODO Auto-generated method stub
double cif = 2*p*b;
return "圆的周长为"+cif;
}
}
实现类
package com.chy3.practice;
public class Initial {
public static void main(String[] args){
System.out.println("计算开始:");
Rectangle rec = new Rectangle();
rec.cal();
Circle cir = new Circle();
cir.cal();
}
}