Arrays sort () sorts the array output
The Get method in the encapsulation is access and the Set method is the output
Breakpoints in Eclipse debugging------> Double-click the number of rows with the mouse
F5 on behalf------------one step (if a method is called, he jumps to the method)
F6 stands for ——— > Single-Step Debugging (he will not jump into the method)
F7 represents ——— > jumps out of the method currently being debugged
F8 represents ——— > is not a single-step debug but jumps directly to the next breakpoint
Breakpoints hit everywhere can be mainly seen in their own proficiency can be hit in the right place
Instanceof Determine if an instance is a type
/***
*
* @author Administrator
* Create a Student aid class for calculating average and maximum score
*/
public class Studentutil {
Public double Sum (studnet[]students) {//Calculate total scores first pass in parameters
Double sum = 0;//defines a variable to receive the student's total
for (int i = 0; i < students.length; i++) {//Use loops to add the scores in the array
Sum+=students[i].getscore ();
}
return sum;
}
Public double Avg (studnet[]students) {//Calculate average input parameter make method run
Double sum=sum (students);//Call the Sum method in Studentutil to calculate the total
Return sum/students.length;//divided by the number of students even if the average
}
Public double Max (studnet[]students) {
Double max = 0;
for (int i = 0; i < students.length; i++) {
if (Max<students[i].getscore ()) {
Max=students[i].getscore ();
}
}
return Max;
}
}
/***
*
* @author Administrator
* Create a Student class
*/
public class Studnet {
Properties of the class (Student's properties)
The private String name;//uses the idea of encapsulation
private double score;
Provides access to the appropriate Get Set method
Public String GetName () {
return name;
}
public void SetName (String name) {
THIS.name = name;
}
Public double Getscore () {
return score;
}
public void SetScore (double score) {
This.score = score;
}
}
Import Java.util.Scanner;
/***
*
* @author Administrator Input Group's students ' grades/names, overall score, average grade, highest score
*/
public class Test {
/**
* @param args
*/
public static void Main (string[] args) {
TODO auto-generated Method Stub
A student's score requires an array, but does not know the length of the array so that the user enters
Scanner s = new Scanner (system.in);
System.out.println ("Please enter the number of students");
int sum = S.nextint ();
studnet[] studnets = new studnet[2];
Studnet stu = null;//declares a Studnet object and is the same as the NULL syntax structure and int i
Use loops to let users enter
for (int i = 0; i < studnets.length; i++) {
Stu = new Studnet ();//The Stu instantiation syntax is equivalent to i = new int
System.out.println ("Please enter the student's name");
String name1 = S.next ();
Stu.setname (name1);//Use the Set method to access the private String Name property in student
System.out.println ("Please enter student's score");
Double score1 = s.nextdouble ();
Stu.setscore (Score1);
Studnets[i] = stu; Transfer the properties of the Stu to the array
Next calculate the student's overall results then create an auxiliary tool class Student Utill
Then call the method of calculating the total in student Utill
Studentutil studentutil = new Studentutil ();
Studentutil.sum (studnets);//The incoming parameter is the student array
System.out.println ("total:" + studentutil.sum (studnets));
Then calculate the mean and add a method to calculate the mean in the student Utill class
Then call the method of calculating the mean in Student Utill
Studentutil.avg (studnets);
System.out.println ("Average score:" + studentutil.avg (studnets));
Then compare the maximum value in student Utill and then establish a method to compare the maximum value.
Studentutil.max (studnets);
System.out.println ("Highest score:" + Studentutil.max (studnets));
}
}
}
2016/04/11