classStudent {//Define student Number PrivateString Stu; //Student Name PrivateString name; //Student Letter Scores Private floatMath; //students ' Chinese achievements Private floatChinese; //Student English scores Private float中文版; //Property Initialization PublicStudent (String stu,string name,floatMathfloatChinese,float中文版) { //Set Number This. Setstu (Stu); //Set name This. SetName (name); //Set Math scores This. Setmath (math); //Set Language scores This. Setchinese (Chinese); //set English scores This. Setenglish (中文版); } Private voidSetenglish (floate) {//TODO auto-generated Method StubEnglish=e; } Private voidSetchinese (floatc) {//TODO auto-generated Method StubChinese=C; } Private voidSetmath (floatm) {//TODO auto-generated Method StubMath=m; } Private voidSetName (String N) {//TODO auto-generated Method StubName=N; } Private voidSetstu (String s) {//TODO auto-generated Method Stubstu=s; } PublicString GetName () {returnname; } Public floatGetmath () {returnMath; } Public floatGetchinese () {returnChinese; } Public floatGetenglish () {return中文版; } PublicString Getstu () {returnStu; } //Score Score Public floatsum () {returnMath+chinese+中文版; } //Average score Public floatavg () {return This. SUM ()/3; } //Highest score Public floatMax () {floatmax=Math; Max= max > Chinese?Max:chinese; Max= max > 中文版?Max:english; returnMax; } //Minimum Value Public floatmin () {floatmin=Math; Min= Min < Chinese?Min:chinese; Min= Min < 中文版?Min:english; returnmin; } //Test Class Public Static classtest{ Public Static voidMain (String args[]) {student Stu=NULL; //instantiates a student object, and constructs a methodstu=NewStudent ("23", "Xiaoming", 90.0f,85.0f,97.0f); System.out.println ("Student Number:" +Stu.getstu ()); System.out.println ("Student Name:" +stu.getname ()); System.out.println ("Student Math Score:" +Stu.getmath ()); System.out.println ("Student language score:" +Stu.getchinese ()); System.out.println ("Student English score:" +stu.getenglish ()); System.out.println ("Total Score:" +stu.sum ()); System.out.println ("Average score:" +stu.avg ()); System.out.println ("Highest score:" +Stu.max ()); System.out.println ("Lowest Score:" +stu.min ()); } } }
Run
Student Number: Students ' name: Xiao Ming's students ' math score: 90.0 students ' Chinese score: 85.0 students ' English score: 97.0 score :272.0 average : 90.666664 Highest score:97.0 minimum score:85.0
Java's classic Student class