⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 card.java

📁 第一次写的java下程序
💻 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 + -