Self-study Java test Code-Simply student class

Source: Internet
Author: User

2017-08-23 23:45:38

Writer:pprp

I'm happy to write this.

 Packagetest; Public classStudent {//Create a member variableString name = ""; String Code= ""; String Sex= ""; Doubleachievement; //constructor Function     PublicStudent (String name) { This. Name =name; }    //initialization function    voidSet (string name, string code, string sex) { This. Name =name;  This. Code =Code;  This. Sex =sex; }    //Get the variable     PublicString getname () {returnname; }     PublicString GetCode () {returnCode; }     PublicString Getsex () {returnsex; }    //Setting Initialization     Public voidSetachi (Doubleachievement) {         This. Achievement =achievement; }     Public DoubleGetachi () {returnachievement; }     Public voidprint () {System.out.println ("Student:" + name + "code" + code + "Sex" +sex); }     PublicString ToString () {string infor= "Student Name:" + name + "code" + code + "Sex" +sex; returninfor; }     Public Static voidMain (string[] args) {//TODO auto-generated Method Stub//new An ObjectStudent St1 =NewStudent ("Name1"); Student St2=NewStudent ("Name2"); Student ST3=NewStudent ("Name3"); Student St4=NewStudent ("Name4"); Student ST5=NewStudent ("Name5"); Student St6=NewStudent ("Name6"); Student St7=NewStudent ("Name7"); Student St8=NewStudent ("Name8"); Student St9=NewStudent ("Name9"); Student st10=NewStudent ("Name10"); //sets an array of objects for the student class, putting all the objects inside the arraystudent[] St =Newstudent[] {st1,st2,st3,st4,st5, st6,st7,st8,st9,st10}; //The setting deviceSt1.set ("Name1", "1", "Man"); St2.set ("Name2", "2", "female"); St3.set ("Name3", "3", "Man"); St4.set ("Name4", "4", "Man"); St5.set ("Name5", "5", "female"); St6.set ("Name6", "6", "Male"); St7.set ("Name7", "7", "female"); St8.set ("Name7", "7", "Male"); St9.set ("Name8", "8", "female"); St10.set ("Name10", "ten", "female");        System.out.println (St1.tostring ());        System.out.println (St2.tostring ());        System.out.println (St3.tostring ());        System.out.println (St4.tostring ());        System.out.println (St5.tostring ());        System.out.println (St6.tostring ());        System.out.println (St7.tostring ());        System.out.println (St8.tostring ());        System.out.println (St9.tostring ());                System.out.println (St10.tostring ()); St1.setachi (Math.random ()* 100); St2.setachi (Math.random ()* 100); St3.setachi (Math.random ()* 100); St4.setachi (Math.random ()* 100); St5.setachi (Math.random ()* 100); St6.setachi (Math.random ()* 100); St7.setachi (Math.random ()* 100); St8.setachi (Math.random ()* 100); St9.setachi (Math.random ()* 100); St10.setachi (Math.random ()* 100);        St1.print (); St2.print (); St3.print ();        St4.print (); St5.print (); St6.print ();        St7.print (); St8.print (); St9.print ();                St10.print ();  for(inti = 0; i < st.length; i++)             for(intj = 0; J < St.length; J + +)            {                if(St[i].achievement <st[j].achievement)                    {Student tmp; TMP=St[i]; St[i]=St[j]; ST[J]=tmp; }} System.out.println ("Best Grader" + St[9].name + "Grade:" +st[9].achievement + "Sex is" + st[9].sex); System.out.println ("Lowest grader is" + St[9].name + "Grade:" +st[9].achievement + "Sex is" + st[9].sex); }}

Self-study Java test Code-Simply student class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.