There is such a code, in the conditions of the problem it is said: Display the average and total rating of all student.
That is, you need to bring the average and total ball of all students. The number of students will be arbitrary; additional class fields cannot be created.
Tell me how to assign avgRating variable the average rating of all students? And also count the overall rating.
import java.util.Scanner; /** * Created by golov on 12.10.2017. */ public class ExampleStudents { public static void main(String[] args) { Student student = new Student("Andrew",4.3); System.out.println(student); } } class Student { private String name; private double rating; static double avgRating; public void setName(String name) { this.name = name; } public void setRating(double rating) { this.rating = rating; } public String getName() { return name; } public double getRating() { return rating; } public Student(){ } public Student(String name, double rating) { this.name = name; this.rating = rating; } //definite the better student (between two, return true or false) public boolean betterStudent (Student student1, Student student2){ if (student1.getRating()>student2.getRating()){ return true; } else { return false; } } @Override public String toString() { return "Student [Name = "+getName()+", rating "+getRating()+"]"; } //change the rating of student void changeRating(){ Scanner scanner = new Scanner(System.in); System.out.println("Enter rating of the student: "); setRating(scanner.nextDouble()); } }