您的位置:首页 > 编程语言 > Java开发

【JAVA 课后习题 11.5】

2016-11-20 19:26 375 查看
水题~? 还是我实现的姿势不对~~总之很简单~手写一个max方法~

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