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)