【JAVA 课后习题 13.12】
2016-11-20 19:32
393 查看
自己老是给自己找麻烦~~很快写好代码后~却发了很长时间找自己的Bug~
好想找个人能和自己一起敲JAVA~一起交流~
GeOb类代码~(加了两个构造方法)
JuXi子类代码~
Yuan子类代码~
Text实现代码~~
好想找个人能和自己一起敲JAVA~一起交流~
GeOb类代码~(加了两个构造方法)
public abstract class GeOb{ private String color = "white"; private boolean filled; protected java.util.Date da; int a,b,r; public void setBian(int a,int b){ this.a = a; this.b = b; } public void setBan(int r){ this.r = r; } protected GeOb(){ da = new java.util.Date(); } protected GeOb(String color,boolean filled){ da = new java.util.Date(); this.color = color; this.filled = filled; } public void setGe(String color,boolean filled){ da = new java.util.Date(); this.color = color; this.filled = filled; } public String getcolor(){ return color; } public void setcolor(String color){ this.color = color; } public boolean getfillrd(){ return this.filled; } public void setfilled(boolean filled){ this.filled = filled; } public java.util.Date getda(){ return da; } public String toString(){ return "created on " + da + "\ncolor : " + color + " and filled : " + filled; } public void howToColor() { System.out.println("Color all four sides "); } interface Colorable{ public void howToColor(); } protected abstract double getArea(); protected abstract double getPerimeter(); }
JuXi子类代码~
public class JuXi extends GeOb{ protected double getArea() { return this.a * this.b; } protected double getPerimeter() { return 2 * a * b; } }
Yuan子类代码~
public class Yuan extends GeOb{ protected double getArea(){ return Math.PI * this.r * this.r; } protected double getPerimeter() { return 2 * Math.PI * this.r * 1.0; } }
Text实现代码~~
public class Text2 { public static void main(String[] args) { GeOb[] a = new GeOb[4]; a[0] = new JuXi(); // 数组里的元素要逐个实例化 a[0].setBian(1, 2); a[1] = new JuXi(); a[1].setBian(3, 5); a[2] = new Yuan(); a[2].setBan(2); a[3] = new Yuan(); a[3].setBan(7); System.out.println(sumArea(a)); } public static double sumArea(GeOb[] a){ // 题目要求的构造方法 double sum = 0.0; for(int i = 0 ; i < a.length ; i++) sum += a[i].getArea(); return sum; } }
相关文章推荐
- java语言程序设计第十版(Introduce to java 10th) 课后习题 chapter7-24
- 算法第4版(Java语言描述)课后习题答案
- 【JAVA 课后习题 12.5】+ 自定义异常类
- java语言程序设计第十版(Introduce to java) 课后习题 chapter6-18
- java语言程序设计第十版(Introduce to java 10th) 课后习题 chapter7-33
- java程序设计 课后习题-chapter6-3
- java语言程序设计第十版(Introduce to java 10th) 课后习题 chapter7-23
- 陈国君java第五版第四章课后习题第五题
- 【JAVA 课后习题 13.1】
- Welcome to JAVA!(第4章课后习题)
- 2017.08.1java开发实战经典课后习题(1-3章)
- java语言程序设计第十版(Introduce to java) 课后习题 chapter6-22
- java语言程序设计第十版(Introduce to java 10th) 课后习题 chapter6-27
- java语言程序设计第十版(Introduce to java 10th) 课后习题 chapter7-31
- java基础学习(6)疯狂java讲义第5章课后习题解答源码
- 【JAVA 课后习题 11.5】
- JAVA语言程序设计基础课后习题第三章
- java学习初体验之课后习题
- java语言程序设计第十版(Introduce to java 10th) 课后习题 chapter12-11
- 【JAVA 课后习题 11.8】+ 练习