簡単なJavaクラス・ジョブの使用について

53596 ワード

簡単なJavaのクラスに関する小さな作業テーマ:1.抽象クラスPersonを定義し、クラスには属性がある:名前、性別、生年月日、インスタンス方法:年齢の計算、抽象方法:play
2.学生類Studioを定義し、Personを継承し、属性を追加する:学号;
|-小中学生クラスを定義し、Studentを継承し、属性を追加:学年、クラス;方法:円の面積を計算できる
|-プレイを実現
|-大学生クラスを定義し、Studentを継承し、属性を追加する:専門、学年、クラス、方法:椎体の体積を計算できる
|-大学生クラスの学号:正規表現を使用して学号がルールに合致しているかどうかを検証する必要がある->20先頭、8桁の数字文字
|-プレイを実現
3.従業員クラスEmployerを定義し、Personを継承し、新しい属性:勤務番号、月給、部門、職位、方法:...
4.小中学生オブジェクト、大学生オブジェクト、従業員を新規作成し、各オブジェクトの文字列表示(属性値)を出力し、各メソッドをテストします.
package class_test;
import java.math.*;
public class CollegeStudent extends Student {
     
@Override
	public String toString() {
     
		return "bigStudent [zhuanye=" + zhuanye + ", nainji=" + nainji + ", banji=" + banji + ", getZhuanye()="
				+ getZhuanye() + ", getNainji()=" + getNainji() + ", getBanji()=" + getBanji() + ", getNumber()="
				+ getNumber() + ", getName()=" + getName() + ", getSex()=" + getSex() + ", getBirthday()="
				+ getBirthday() + ", getClass()=" + getClass() + ", hashCode()=" + hashCode() + ", toString()="
				+ super.toString() + "]";
	}
public String getZhuanye() {
     
		return zhuanye;
	}
	public void setZhuanye(String zhuanye) {
     
		this.zhuanye = zhuanye;
	}
	public String getNainji() {
     
		return nainji;
	}
	public void setNainji(String nainji) {
     
		this.nainji = nainji;
	}
	public int getBanji() {
     
		return banji;
	}
	public void setBanji(int banji) {
     
		this.banji = banji;
	}
private String zhuanye;
private String nainji;
private int banji;
public CollegeStudent(String zhuanye, String nainji, int i) {
     
	super();
	this.zhuanye = zhuanye;
	this.nainji = nainji;
	this.banji = i;
}
public CollegeStudent() {
     }
int getyuanzhui(int r,int h) {
     
	long area;
	area = (long) ((r*r*(Math.PI))*h*(0.3));
	return (int) area;
}
}

package class_test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Employer extends Person {
     
	@Override
	public String toString() {
     
		return "Employer [gonghao=" + gonghao + ", yuexin=" + yuexin + ", bumen=" + bumen + ", zhiwei=" + zhiwei
				+ ", days=" + days + ", getGonghao()=" + getGonghao() + ", getYuexin()=" + getYuexin() + ", getBumen()="
				+ getBumen() + ", getZhiwei()=" + getZhiwei() + ", getName()=" + getName() + ", getSex()=" + getSex()
				+ ", getBirthday()=" + getBirthday() + ", getClass()=" + getClass() + ", hashCode()=" + hashCode()
				+ ", toString()=" + super.toString() + "]";
	}
	public int getGonghao() {
     
		return gonghao;
	}
	public void setGonghao(int gonghao) {
     
		this.gonghao = gonghao;
	}
	public int getYuexin() {
     
		return yuexin;
	}
	public void setYuexin(int yuexin) {
     
		this.yuexin = yuexin;
	}
	public String getBumen() {
     
		return bumen;
	}
	public void setBumen(String bumen) {
     
		this.bumen = bumen;
	}
	public String getZhiwei() {
     
		return zhiwei;
	}
	public void setZhiwei(String zhiwei) {
     
		this.zhiwei = zhiwei;
	}
	private int gonghao;
	private int yuexin;
	private String bumen;
	private String zhiwei;
	private int days;
	public Employer(String name, String sex, String birthday, int gonghao, int yuexin, String bumen, String zhiwei) {
     
		this.gonghao = gonghao;
		this.yuexin = yuexin;
		this.bumen = bumen;
		this.zhiwei = zhiwei;
	}
	public Employer() {
     }
	
	public void getAge(String birthday1) throws ParseException {
     
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd,HH:mm:ss");
		Date date = sdf.parse(birthday1);
		long time = date.getTime();
		System.out.println("          "+time+"  ");
		Date date1 = new Date();
		System.out.println("     "+date1);
		long time1 = date1.getTime();
		long time2 = ((time1-time)/86400000)/365;
		System.out.println("   "+time2);
}
}

package class_test;

public abstract class Person {
     
@Override
	public String toString() {
     
		return "Person [name=" + name + ", sex=" + sex + ", birthday=" + birthday + ", getName()=" + getName()
				+ ", getSex()=" + getSex() + ", getBirthday()=" + getBirthday() + ", getClass()=" + getClass()
				+ ", hashCode()=" + hashCode() + ", toString()=" + super.toString() + "]";
	}
public String getName() {
     
		return name;
	}
	public void setName(String name) {
     
		this.name = name;
	}
	public String getSex() {
     
		return sex;
	}
	public void setSex(String sex) {
     
		this.sex = sex;
	}
	public String getBirthday() {
     
		return birthday;
	}
	public void setBirthday(String birthday) {
     
		this.birthday = birthday;
	}
private String name;
private String sex;
// birthday   yyyy-MM-dd HH:mm:ss      ;
private String birthday;
public Person(String name, String sex, String birthday) {
     
	super();
	this.name = name;
	this.sex = sex;
	this.birthday = birthday;
}
public Person() {
     }
void getAge() {
     

}
}

package class_test;
import java.math.*;
public class Pupils extends Student {
     
	@Override
	public String toString() {
     
		return "littleStudent [nianji=" + nianji + ", banji=" + banji + ", getNianji()=" + getNianji() + ", getBanji()="
				+ getBanji() + ", getNumber()=" + getNumber() + ", getName()=" + getName() + ", getSex()=" + getSex()
				+ ", getBirthday()=" + getBirthday() + ", getClass()=" + getClass() + ", hashCode()=" + hashCode()
				+ ", toString()=" + super.toString() + "]";
	}
	public String getNianji() {
     
		return nianji;
	}
	public void setNianji(String nianji) {
     
		this.nianji = nianji;
	}
	public String getBanji() {
     
		return banji;
	}
	public void setBanji(String banji) {
     
		this.banji = banji;
	}
	private String nianji;
	private String banji;
	public Pupils(String name, String sex, String birthday, String number, String nianji, String banji) {
     
		super(name, sex, birthday, number);
		this.nianji = nianji;
		this.banji = banji;
	}
	public Pupils() {
     }
	int getCircle(int r) {
     
		int area;
		area = (int) (r*r*(Math.PI));
		return area;
	}

}

package class_test;

public class Student extends Person {
     
	@Override
	public String toString() {
     
		return "Student [number=" + number + ", getNumber()=" + getNumber() + ", toString()=" + super.toString()
				+ ", getName()=" + getName() + ", getSex()=" + getSex() + ", getBirthday()=" + getBirthday()
				+ ", getClass()=" + getClass() + ", hashCode()=" + hashCode() + "]";
	}

	public 	String getNumber() {
     
		return number;
	}

	public void setNumber(String number) {
     
		this.number = number;
	}

	private String number;

	public Student(String name, String sex, String birthday, String number) {
     
		super(name, sex, birthday);
		this.number = number;
	}
	public Student() {
     }
}

package class_test;

import java.text.ParseException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class main1 {
     
public static void main(String[] args) throws ParseException {
     
	
	CollegeStudent bg = new CollegeStudent("    ","2018",1);
	Pupils ls = new Pupils("  ", " ","2000-12-12,00:00:00", "20180001", "2018", "1");
	Employer ep = new Employer("  ", " ","1970-12-12,00:00:00" , 20110001, 3000, "   ", "  ");

boolean a;
a = isNumLegal(ls.getNumber());
System.out.println(a);

System.out.println(bg.toString());
System.out.println(ls.toString());
System.out.println(ep.toString());
 int circle = ls.getCircle(2);
 System.out.println(circle);//  
 int circle1 = bg.getyuanzhui(8,4);
 System.out.println(circle1);//   
 //   
 ep.getAge(ls.getBirthday());
}

private static String String(int number) {
     
	// TODO Auto-generated method stub
	return null;
}
private static boolean isNumLegal(String str){
     
    String regExp = "^((20)\\d{6})$";
    Pattern p = Pattern.compile(regExp);
    Matcher m = p.matcher(str);
    return m.matches();
}
}