【JAVA 课后习题 11.5】
2016-11-20 19:26
375 查看
水题~? 还是我实现的姿势不对~~总之很简单~手写一个max方法~
GeOb类代码 :(核心代码也就几行)
Text3类代码:
GeOb类代码 :(核心代码也就几行)
package EiGt; public class GeOb implements Comparable<GeOb>{ private String color = "white"; private boolean filled; protected java.util.Date da; int a = 0,b = 0,r = 0; protected void getBian(int a,int b){ this.a = a; this.b = b; } protected void getBan(int r){ this.r = 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(); } public static int compareTo(GeOb o,GeOb p){ // 核心代码感觉就这几行 if(o.a * o.b < p.a * p.b || o.r < p.r) return -1; if(o.a * o.b > p.a * p.b || o.r > p.r) return 1; return 0; } @Override public int compareTo(GeOb o) { return 0; } }
Text3类代码:
package EiGt; public class Text3 { public static void main(String[] args) { GeOb a = new GeOb(); a.setBian(1, 2); GeOb a1 = new GeOb(); a1.setBian(3, 4); System.out.println(GeOb.compareTo(a1, a)); GeOb b = new GeOb(); b.setBan(2); GeOb b1 = new GeOb(); b1.setBan(3); System.out.println(GeOb.compareTo(b, b1)); } }
相关文章推荐
- java语言程序设计第十版(Introduce to java 10th) 课后习题 chapter6-27
- java语言程序设计第十版(Introduce to java 10th) 课后习题 chapter7-31
- 【JAVA 课后习题 12.5】+ 自定义异常类
- Welcome to JAVA!(第4章课后习题)
- java的课后习题
- java语言程序设计第十版(Introduce to java) 课后习题 chapter6-22
- 疯狂java讲义习题11.5
- java语言程序设计第十版(Introduce to java 10th) 课后习题 chapter12-11
- 【JAVA 课后习题 13.1】
- Java课后习题——校验密码
- 【JAVA 课后习题 11.8】+ 练习
- think in java第18章Java i/o系统课后习题
- 【JAVA 课后习题 12.5】+ 自定义异常类
- java 语言程序设计-李尊朝 第9章 异常处理 课后习题
- 【JAVA 课后习题 13.12】
- JAVA语言程序设计基础课后习题第五章
- java语言程序设计第十版(Introduce to java 10th) 课后习题 chapter7-21
- JAVA数据结构课后习题——2的100次方(mod5)是多少?
- 【JAVA 课后习题 13.7】+ 接口 + 抽象类
- java语言程序设计基础课后习题第二章