``` interface Shape{ double area(double len); } class Square implements Shape{ public double area(double len){ if(len < 0){ return 0; } return len*len; } } class Circle implements Shape{ public double area(double r){ if(r < 0){ return 0; } return r*r*Math.PI; } } ///测试 public class MainTest { @org.junit.Test public void testSquare() throws Exception { Shape square = new Square(); assertEquals(4,square.area(2),0.001); } @org.junit.Test public void testCircle() throws Exception { Shape circle = new Circle(); assertEquals(3*3*Math.PI,circle.area(3),0.001); } }
点赞 评论

相关推荐

27双非本,最近面试被挂麻了面试官说简历内容太简单了,技术栈要单独一行,各位佬有啥建议吗
LZStarV:项目太简单了,你像用什么开发的技术栈没必要写一句话,按点写就好了;有特色的比如说WebSocket、视频流这种狠狠吹,那就好看多了
点赞 评论 收藏
分享
点赞 评论 收藏
分享
做个有文化的流氓:不想当将军的士兵不是好士兵
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务