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

📄 teststr.java

📁 目标: 设计一个小型的学生管理系统。 第一步要求: 1、 对于一个学生类
💻 JAVA
字号:
package day09.src;

interface Person{ //第四步
	public int getNumber();
	//public String getStrAddress();
}

class Str implements Person{  //第四步
	private String strName = "";
	private int strNumber = 20070101;
	private String strSex = "";
	private BirthDate strBirthday;
	private String strSpeciality = "";
	private String strAddress = "";
	public static int nextNumber = 20070101;  //第二步
	
	/*public Str(String strName,int strNumber){  //第一步
		this.strName = strName;
		this.strNumber = strNumber;
	}
	
	public Str(String name){                    //第一步
		this(name,20060101);
	}*/
	
	public int getNumber() {   //第二步   
		return nextNumber++;
	}
	
	public Str(String strName){  //第二步
		this.strName = strName;
		this.strNumber = getNumber();
	}
	
	public void setStrName(String strName){this.strName = strName;}	
	public String getStrName(){return strName;}
	
	public void setStrNumber(int strNumber){this.strNumber = strNumber;}	
	public int getStrNumber(){return strNumber;}
	
	public void setStrSex(String strSex){this.strSex = strSex;}	
	public String getStrSex(){return strSex;}
	
	public void setStrBirthday(BirthDate strBirthday){this.strBirthday = strBirthday;}	
	public BirthDate getStrBirthday(){return strBirthday;}
	
	public void setStrSpeciality(String strSpeciality){this.strSpeciality = strSpeciality;}	
	public String getStrSpeciality(){return strSpeciality;}
	
	public void setStrAddress(String strAddress){this.strAddress = strAddress;}	
	public String getStrAddress(){return strAddress;}
	
	public String toString(){   
		String infor = "姓名:" + strName + ",学号:" + strNumber;
		if(!strSex.equals("")){
			infor += ",性别:" + strSex;
		}
		if(!(strBirthday == null)){
			infor += ",出生日期:" + strBirthday;
		}
		if(!strSpeciality.equals("")){
			infor += ",专业:" + strSpeciality;
		}
		if(!strAddress.equals("")){
			infor += ",籍贯:" + strAddress;
		}
		return infor;
		
	}
}

//第三步
class ClassManager extends Str{
	private String strDuty = "";
	
	public ClassManager(String strName,String strDuty){
		super(strName);
		this.strDuty = strDuty;
	}
	
	public String a(){
		return "老实点";
	}
	
	public String toString(){
		String infor = super.toString();
		if(!(strDuty == null)){
			infor += ",职务:" + strDuty;
		}
		return infor;
	}
	
}

public class TestStr {
    //第三步
	public static void p(Str s){
		if (s instanceof ClassManager){
			ClassManager ss = (ClassManager) s;
			System.out.println("我是班干部," + ss + "," + ss.a());
		}else{
			if(s instanceof Str){
				System.out.println("我是学生," + s + ",我很听话");
			}
		}
	}
	
	public static void main(String[] args) {
	Str s1 = new Str("tom");
	s1.setStrSex("男");
	s1.setStrSpeciality("computer");
	s1.setStrAddress("中国");
	Str s2 = new Str("孙");
	Str s3 = new Str("八");
	Str s4 = new Str("沙");
	p(s1);
	p(s2);
	p(s3);
	p(s4);
	
	Str ss1 = new ClassManager("观音","生活委员");  //第三步
	Str ss2 = new ClassManager("玉帝","体育委员");
	p(ss1);
	p(ss2);
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -