?? card.java
字號:
package Cd;
import java.lang.*;
public class Card implements Comparable{ //Card Father
String type="";
int num=0;
public Card(String s){
type=s;
}
public void disPlay(){
System.out.println(this.type+" "+this.num);
}
public int equal(Card a){
if(a.type==this.type&&this.num==a.num)return 1;
else return 0;
}
public int compareTo(Object c) {//實現接口函數的定義,順序為red,blue,green,yellow
if(c instanceof Card){
int a=0,b=0;
if(this.type.length()==3)a=1;
else if(this.type.length()==5)a=3;
else if(this.type.length()==6)a=4;
else if(this.type.length()==4)a=2;
// System.out.println(this.type.length());
if(((Card)c).type.length()==3)b=1;
else if(((Card)c).type.length()==5)b=3;
else if(((Card)c).type.length()==6)b=4;
else if(((Card)c).type.length()==4)b=2;
// System.out.println(a+b);
if(a>b)return 1;
else if (a<b)return -1;
else{
if(this.num>((Card)c).num)return 1;
else if(this.num<((Card)c).num)return -1;
else return 0;
}
}
else return 0;
}
public static void main(String []args){}
}
// four sons of Card Red Green Yellow Blue
class Red extends Card{
public Red(int i){
super("Red");
num=i;
}
}
class Green extends Card{
public Green(int i){
super("Green");
num=i;
}
}
class Yellow extends Card{
public Yellow(int i){
super("Yellow");
num=i;
}
}
class Blue extends Card{
public Blue(int i){
super("Blue");
num=i;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -