package cn.campsg.java.experiment.impl;
import cn.campsg.java.experiment.ShapeCalc;
public class SquareCalImpl implements ShapeCalc {
private float length;
public float getLength() {
return length;
}
public void setLength(float length) {
this.length = length;
}
public SquareCalImpl() {
}
public float calcPerim() {
float peri = length * 4;
return peri;
}
public float calcArea() {
float area= length * length ;
return area;
}
}
package cn.campsg.java.experiment;
public interface ShapeCalc {
public float calcPerim();
public float calcArea();
}
package cn.campsg.java.experiment;
import cn.campsg.java.experiment.impl.SquareCalImpl;
public class MainClass{
public static void main(String[] args) {
SquareCalImpl sc = new SquareCalImpl();
sc.setLength(5.0f);
System.out.println("正方形的周长为:"+sc.calcPerim());
System.out.println("正方形的面积为:"+sc.calcArea());
}
}