整个项目是一个压缩包,在视频里要求的功能下加入了输入超出范围的纠错功能,有些地方感觉会有更简便的办法实现 代码地址:我的头像->TA的社区->Ta的作品 ,欢迎大家一起来探讨留言
测试类
package exercise4_3;
public class Initial {
public static void main(String[] args){
Shape shape1=new Rectangle();
shape1.zhouchang();
shape1.mianji();
Shape shape2=new Circle();
shape2.zhouchang();
shape2.mianji();
}
}
package exercise4_3;
public class Initial {
public static void main(String[] args){
Shape shape1=new Rectangle();
shape1.zhouchang();
shape1.mianji();
Shape shape2=new Circle();
shape2.zhouchang();
shape2.mianji();
}
}
2016-01-14
圆子类
package exercise4_3;
public class Circle extends Shape {
float r;
@Override
public void zhouchang() {
// TODO Auto-generated method stub
System.out.println("圆的周长为2r*PI");
}
@Override
public void mianji() {
// TODO Auto-generated method stub
System.out.println("圆的面积 为PI*r*r");
}
}
package exercise4_3;
public class Circle extends Shape {
float r;
@Override
public void zhouchang() {
// TODO Auto-generated method stub
System.out.println("圆的周长为2r*PI");
}
@Override
public void mianji() {
// TODO Auto-generated method stub
System.out.println("圆的面积 为PI*r*r");
}
}
2016-01-14
矩形子类
package exercise4_3;
public class Rectangle extends Shape {
float lang;
float wide;
@Override
public void zhouchang() {
System.out.println("周长为2lang*2wide");
}
@Override
public void mianji() {
// TODO Auto-generated method stub
System.out.println("矩形面积为lang*wide");
}
}
package exercise4_3;
public class Rectangle extends Shape {
float lang;
float wide;
@Override
public void zhouchang() {
System.out.println("周长为2lang*2wide");
}
@Override
public void mianji() {
// TODO Auto-generated method stub
System.out.println("矩形面积为lang*wide");
}
}
2016-01-14
抽象父类
package exercise4_3;
public abstract class Shape {
public abstract void zhouchang();
public abstract void mianji();
}
package exercise4_3;
public abstract class Shape {
public abstract void zhouchang();
public abstract void mianji();
}
2016-01-14