PackageTest.studet_manager; Public classStudent {Static intnum = 100; //numbered--Unique Private intNumber =-1; //name PrivateString name = ""; //Sex PrivateString sex = ""; //Age Private intAge =-1; //class PrivateString grade = ""; //Achievements Private intScore =-1; /** methods for set and get*/ Public voidsetsex (String sex) { This. Sex =sex; } PublicString Getsex () {returnsex; } Public voidsetName (String name) { This. Name =name; } PublicString GetName () {returnname; } Public voidSetage (intAge ) { //age must be greater than 0 if(age>=0) { This. Age =Age ; } } Public intGetage () {returnAge ; } Public voidSetgrade (String grade) { This. grade =grade; } PublicString Getgrade () {returngrade; } Public voidSetScore (intscore) { if(Score >= 0) { This. score =score; } } Public intGetscore () {returnscore; } Public voidSetnumber (intNumber ) { This. Number = This. number+0; } Public intGetNumber () {returnNumber ; } PublicStudent () {//TODO auto-generated Constructor stub++num; This. Number =num; } PublicStudent (intnumber,string name,string Sex,intAge,string grade,intscore) {GetNumber (); GetName (); Getsex (); Getage (); Getgrade (); Getscore (); } @Override PublicString toString () {//TODO auto-generated Method Stub return""+ This. number+ "" + This. name+ "" + This. sex+ "" + This. age+ "" + This. grade+ "" + This. score+ "\ n"; } @Override Public Booleanequals (Object obj) {//TODO auto-generated Method Stub//determines whether the object to compare is not NULL if(obj = =NULL) { return false; } //judging the object to compare is not itself if(obj = = This) { return true; } //determine if the object to compare is not the same type if(objinstanceofStudent) {Student Student=(Student) obj; returnstudent.number== This. number&&student.name== This. name&&student.sex== This. sex&&student.age== This. age&&student.grade== This. grade&&student.score== This. Score; } return false; } @Override//Note: The Hashcode method must be consistent with the attributes in the Equals method Public inthashcode () {//TODO auto-generated Method Stub return This. number- This. Name.hashcode ()- This. Sex.hashcode ()- This. age- This. Grade.hashcode (); } //write some of your own ways Public voidLearn () {System.out.println ( This. name+ "Learning computer language"); }}
java-Basic Package