Add student scores (transfer of object array)

Source: Internet
Author: User

1  PackageTexts.News.copy;2 /*3 * Test class, Run here4  */5  Public classMain {6 7      Public Static voidMain (string[] args) {8 9IS is =NewIs ();//Create a Student Action objectTenstudent[] n = is.input ();//array of returned objects One          ASystem.out.println ("\ n Student Information")); -System.out.println ("\ n number \ t grade \ n"); -          the          for(inti=0; i<n.length; i++) {//number, score, or pass in the Loop output object -System.out.println (n[i].number+ "\ t" +n[i].score+ "\ T" +n[i].pass); -         } -          +     } -  +}

1  PackageTexts.News.copy;2 /*3 * Student Class4  */5  Public classStudent {6 7     intnumber;//School Number8     intScore;//Achievements9String Pass;//whether passTen}

1  PackageTexts.News.copy;2 3 ImportJava.util.Scanner;4 /*5 * The Student action class returns an array of objects. 6  */7  Public classis {8 9      PublicStudent [] input () {Ten          One         intn = 0;//Array Length A          -          for(;;) {//this loop is error handling -              theScanner input =NewScanner (system.in);//creating keyboard Input Objects -System.out.print ("Input a few information:"); -              -             if(Input.hasnextint ()) {//error handling if the input is a number if passed, otherwise else +n =input.nextint (); -                  Break; +             } A             Else { atSystem.out.println ("Please enter correctly! "); -                 Continue; -             } -  -         } -  inStudent [] s =NewStudent [n];//creates an array of objects for each new object that is used for the For loop.  -          to          for(inti=0; i<s.length; i++) { +              -Scanner input =NewScanner (system.in);//creating keyboard Input Objects theStudent stu =NewStudent ();//Create a Student object, and each time a new object is created, the added information is placed in a different object.  *  $System.out.print ("\ n" + (i+1) + "Student Number:");Panax NotoginsengStu.number =input.nextint (); -System.out.print ("+ (i+1) +" Student Score: "); theStu.score =input.nextint (); +              A             if(stu.score>=80) {//judge whether the grade is passed, greater than or equal to 80 points of two hooks greater than or equal to 60 points a tick theStu.pass = "√√"; +             } -             Else if(stu.score>=60){ $Stu.pass = "√"; $             } -             Else { -Stu.pass = "X"; the             } -             WuyiS[i] = stu;//The new object is added to the corresponding position of the array, and the first new one is the first position of the foot Mark I=0,i as the loop increases. The For loop ends the array and fills the object.  the              -         } Wu         returnS//returns an array of filled objects back.  -          About     } $}

Add student scores (transfer of object array)

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.