Sorting values from ArrayList inside HashMap - java

I'm having a hard time trying to solve my problem. I have to sort students in descending order by highest average mark and also to show the average mark of all students. I will include my Main class and declarations from my other classes.
public Main()
{
ArrayList<Student> students = new ArrayList<Student>();
Student A = new Student("John", "Doe", 1000);
students.add(A);
Student B = new Student("Michael", "Hawk", 2000);
students.add(B);
Student C = new Student("Nicholas", "Johnson", 3000);
students.add(C);
HashMap<Integer, ArrayList<PassedExams>> map = new HashMap<Integer, ArrayList<PassedExams>>();
for (Student student : students)
{
map.put(student.getIndeks(), new ArrayList<PassedExams>());
}
for (Entry<Integer,ArrayList<PassedExams>> exam : map.entrySet())
{
if (exam.getKey() == 1000)
{
ArrayList<PassedExams> passedExam = exam.getValue();
passedExam.add(new PassedExams("CS102", 6));
passedExam.add(new PassedExams("CS220", 8));
exam.setValue(passedExam);
}
if (exam.getKey() == 2000)
{
ArrayList<PassedExams> passedExam = exam.getValue();
passedExam.add(new PassedExams("MA101", 10));
passedExam.add(new PassedExams("CS101", 7));
exam.setValue(passedExam);
}
if (exam.getKey() == 3000)
{
ArrayList<PassedExams> passedExam = exam.getValue();
passedExam.add(new PassedExams("CS115", 9));
passedExam.add(new PassedExams("MA102", 7));
exam.setValue(passedExam);
}
}
for (Student student : students)
{
System.out.println(student.toString() + " " + map.get(student.getIndex()));
}
}
`
public class PassedExams
{
private String code;
private Integer mark;
// get and set methods
// aswell as toString();
}
`
public class Student
{
private String name, surname;
private Integer index;
// get and set methods
// aswell as toString();
}
EDIT: Adding input and output
What is seen by default:
Student Name: John Surname: Doe Index: 1000 [Predmet: Code: CS102 Mark: 6, Predmet: Code: CS220 Mark: 8]
Student Name: Michael Surname: Hawk Index: 2000 [Predmet: Code: MA101 Mark: 10, Predmet: Code: CS101 Mark: 7]
Student Name: Nicholas Surname: Johnson Index: 3000 [Predmet: Code: CS115 Mark: 9, Predmet: Code: MA102 Mark: 7]
What should be seen after sort:
Student Name: Michael Surname: Hawk Index: 2000 [Predmet: Code: MA101 Mark: 10, Predmet: Code: CS101 Mark: 7]
Student Name: Nicholas Surname: Johnson Index: 3000 [Predmet: Code: CS115 Mark: 9, Predmet: Code: MA102 Mark: 7]
Student Name: John Surname: Doe Index: 1000 [Predmet: Code: CS102 Mark: 6, Predmet: Code: CS220 Mark: 8]
And total average mark:
Total average mark from students is: 7.83
Also I guess I should change from Integer to Double because of the line above.

Draken is right, it's more elegant to model the passed exams list as property of a student. However, you can sort your students with the way things are.
When you want to define an order on a list in Java you can write a special Comparator:
//sorting starts here
Collections.sort(students, new Comparator<Student>() {
#Override
public int compare(Student o1, Student o2) {
double sum1 = 0, sum2 = 0;
for (PassedExams pe : map.get(o1.getIndex())) sum1+=pe.mark;
for (PassedExams pe : map.get(o2.getIndex())) sum2+=pe.mark;
sum1 /= map.get(o1.getIndex()).size();
sum2 /= map.get(o2.getIndex()).size();
return Double.compare(sum2, sum1);
}
});

Here's the elegant way to do it (I'm using Java 1.7, so please ignore the lack of predicates!)
Main
public class App {
public static void main(String[] args) {
new App();
}
public App()
{
ArrayList<Student> students = new ArrayList<Student>();
Student A = new Student("John", "Doe", 1000);
students.add(A);
Student B = new Student("Michael", "Hawk", 2000);
students.add(B);
Student C = new Student("Nicholas", "Johnson", 3000);
students.add(C);
for (Student student : students)
{
if (student.getIndex() == 1000)
{
student.getPassedExamList().add(new PassedExam("CS102", 6));
student.getPassedExamList().add(new PassedExam("CS220", 8));
}
if (student.getIndex() == 2000)
{
student.getPassedExamList().add(new PassedExam("MA101", 10));
student.getPassedExamList().add(new PassedExam("CS101", 7));
}
if (student.getIndex() == 3000)
{
student.getPassedExamList().add(new PassedExam("CS115", 9));
student.getPassedExamList().add(new PassedExam("MA102", 7));
}
}
for (Student student : students)
{
System.out.println(student.toString() + " " + student.getPassedExamList());
}
Collections.sort(students);
System.out.println("\nSorted\n");
for (Student student : students)
{
System.out.println(student.toString() + " " + student.getPassedExamList());
}
System.out.println("\nCalculating average\n");
double total = 0;
double count = 0;
for (Student student : students)
{
count += student.getPassedExamList().size();
total += student.getTotalMarks();
}
DecimalFormat df = new DecimalFormat("0.##");
System.out.println("Average is " + df.format(total / count));
}
}
Passed exam
public class PassedExam {
private String code;
private Integer mark;
public PassedExam(String code, int mark){
this.code = code;
this.mark = mark;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public Integer getMark() {
return mark;
}
public void setMark(Integer mark) {
this.mark = mark;
}
#Override
public String toString() {
return "PassedExams{" +
"code='" + code + '\'' +
", mark=" + mark +
'}';
}
}
Student
public class Student implements Comparator<Student>, Comparable<Student> {
private String name, surname;
private Integer index;
private List<PassedExam> passedExamList = new ArrayList<PassedExam>();
public Student(String name, String surname, int index){
this.name = name;
this.surname = surname;
this.index = index;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
public Integer getIndex() {
return index;
}
public void setIndex(Integer index) {
this.index = index;
}
public List<PassedExam> getPassedExamList() {
return passedExamList;
}
public int getTotalMarks(){
int total = 0;
for(PassedExam exam : passedExamList)
total += exam.getMark();
return total;
}
#Override
public String toString() {
return "Student{" +
"name='" + name + '\'' +
", surname='" + surname + '\'' +
'}';
}
#Override
public int compare(Student o1, Student o2) {
return Integer.compare(o2.getTotalMarks(), o1.getTotalMarks());
}
#Override
public int compareTo(Student o) {
return Integer.compare(o.getTotalMarks(), this.getTotalMarks());
}
}
The thing that allows me to call Collections.sort() is the fact that I implement Comparable<Student> on the Student class. I then add the method compareTo() and state how I want it sorting. Since you wanted descending order, I've reverse the normal order of comparison. You can read more on Comparable here

I don't think you need a hashMap
First add all students in the list.
Implement a Comparator, the comparator would probably have a method: getExamsForStudent()
Then sort the list using Collections.sort(list, comparator).

Related

How to break out of a loop and print the contents of an array

How can I break out of a loop when the user enters "done" and print the contents of what the user entered? Also, I would like to be able to find the smallest element of the array and the largest element of the array during the printing.
import java.util.Arrays;
public class array2 {
public static void main(String[] args) {
java.util.Scanner input = new java.util.Scanner(System.in);
input.useDelimiter(System.getProperty("line.separator"));
int numofpeople = 10;
Person[] persons = new Person[numofpeople];
for (int i = 0; i < numofpeople; i++) {
System.out.print("Enter the person's name: ");
String person = input.next();
if(person.equals("done")){break;}
System.out.print("Enter the persons's age: ");
int age = (Integer) input.nextInt();
persons[i] = new Person(person, age);
}
}
}
class Person implements Comparable<Person> {
public String person;
public Integer age;
public Person(String s, Integer g) {
this.person = s;
this.age = g;
}
#Override
public int compareTo(Person o) {
return (this.age>o.age?1:-1);
}
}
The break statement will make the program leave the for loop. You have no code to print the array outside of the for loop. In fact, there is no code outside of the loop. This will make your program exit since it is in the main method. So you need code to print the array.
Complete Solution Given all comments below:
import java.util.ArrayList;
public class Array2 {
public static void main(String[] args) {
java.util.Scanner input = new java.util.Scanner(System.in);
ArrayList<Person> persons = new ArrayList();
int numOfPeople = 10;
for (int i = 0; i < numOfPeople; i++) {
System.out.print("Enter the person's name: ");
String person = input.nextLine();
if (person.trim().equalsIgnoreCase("done")) {
break;
}
System.out.print("Enter the persons's age: ");
int age = Integer.parseInt(input.nextLine());
persons.add(new Person(person, age));
}
//Collections.sort(persons); //not sorting anymore
for (Person person : persons) {
System.out.println(person.name + ": " + person.age);
}
Person youngestPerson = getYoungest(persons);
Person oldestPerson = getOldest(persons);
System.out.println("Youngest: " + youngestPerson.name + ": " + youngestPerson.age);
System.out.println("Oldest: " +oldestPerson.name + ": " + oldestPerson.age);
}
public static Person getYoungest(ArrayList<Person> people) {
Person youngestPerson = null;
for (Person person : people) {
if (youngestPerson == null || person.age < youngestPerson.age) {
youngestPerson = person;
}
}
return youngestPerson;
}
public static Person getOldest(ArrayList<Person> people) {
Person oldestPerson = null;
for (Person person : people) {
if (oldestPerson == null || person.age > oldestPerson.age) {
oldestPerson = person;
}
}
return oldestPerson;
}
protected static class Person implements Comparable<Person> {
protected String name;
protected int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
#Override
public int compareTo(Person o) {
return (this.age > o.age ? 1 : -1);
}
}
}

How to fix "reached end of file while parsing"

I am writing a program to find and display the student with the highest GPA, as well as the student with the lowest GPA out of a class with 4 attributes (first name, last name, age, GPA).
The output for my code results in "build successful," but the parsing error still shows up and there isn't the proper output information.
public class app
{
public static void main(String args[ ])
{
student st1 = new student("Rebecca", "Collins", 22, 3.3);
student st2 = new student("Alex", "White", 19, 2.8);
student st3 = new student("Jordan", "Anderson", 22, 3.1);
student[ ] studentArray = new student[3];
studentArray[0] = st1;
studentArray[1] = st2;
studentArray[2] = st3;
var maxStudent = studentArray[0];
// Start at 1 because we assumed the first student in the array
// has the current max.
//
for (int i = 1; i < studentArray.length; i++)
{
// If the current student has a GPA higher than the student
// with the current max, make the current student the student
// with the current max.
//
if(studentArray[i].gpa > maxStudent.getGpa())
{
boolean max = false;
boolean min;
min = false;
for (student studentArray1 : studentArray) {
boolean gpa = false;
}
System.out.print("The highest GPA is: "+max);
System.out.println();
System.out.print("The lowest GPA is: "+min);
System.out.println();
System.out.println("Name: "+ studentArray[i].firstName + " "+ studentArray[i].lastName);
System.out.println("Age: "+ studentArray[i].age);
System.out.println("GPA: "+ studentArray[i].gpa);
}
}
public class student
{
//class variables
public String firstName;
public String lastName;
public int age;
public double gpa;
public int max = 0;
public int min = 0;
//constructor method
student(String a, String b, int c, double d)
{
firstName = a;
lastName = b;
age = c;
gpa = d;
}
student(String a, String b, int c, double d, int e, int f)
{
firstName = a;
lastName = b;
age = c;
gpa = d;
min = e;
max = f;
}
//a method that returns the student's complete name
String getInfo()
{
return getFirstName() +" " + getLastName() +" " + getMax();
}
public String getFirstName()
{
return firstName;
}
public void setFirstName(String fn)
{
firstName = fn;
}
public String getLastName()
{
return lastName;
}
public void setLastName(String ln)
{
lastName = ln;
}
public int getAge()
{
return age;
}
public void setAge(int x)
{
age = x;
}
public double getGpa()
{
return gpa;
}
public void getGpa(double g)
{
gpa = g;
}
public int getMax()
{
return max;
}
public void getMax(int e)
{
max = e;
}
public int getMin()
{
return min;
}
public void getMin(int f)
{
min = f;
}
}
I would appreciate any insight that addresses the error and solutions for what I can do to make this code work properly.
There are a number of (possible) issues with your posted code; you appear to be using an inner student class; your braces don't match up and your indentation doesn't seem to be consistent, and the var keyword doesn't exist in versions of Java prior to 10 (and we have no knowledge of your installed JDK or configured project compiler level). Your student(s) shouldn't have individual min and max fields.
There is some debate about the merits of a class with all public fields; but any possible advantage to that is negated when you also implement getters and setters for all of them.
You need two loops; one to find the min and max, one to display the student(s). Java naming conventions should be respected (class names start with a capital letter). And you have a getGpa(double) that should be a setter.
Fixing all of that, it might look something like
public class App {
public static class Student {
private String firstName;
private String lastName;
private int age;
private double gpa;
public Student(String a, String b, int c, double d) {
firstName = a;
lastName = b;
age = c;
gpa = d;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String fn) {
firstName = fn;
}
public String getLastName() {
return lastName;
}
public void setLastName(String ln) {
lastName = ln;
}
public int getAge() {
return age;
}
public void setAge(int x) {
age = x;
}
public double getGpa() {
return gpa;
}
public void setGpa(double g) {
gpa = g;
}
}
public static void main(String[] args) throws Exception {
Student st1 = new Student("Rebecca", "Collins", 22, 3.3);
Student st2 = new Student("Alex", "White", 19, 2.8);
Student st3 = new Student("Jordan", "Anderson", 22, 3.1);
Student[] studentArray = { st1, st2, st3 };
Student maxStudent = studentArray[0];
Student minStudent = studentArray[0];
for (int i = 1; i < studentArray.length; i++) {
if (studentArray[i].getGpa() > maxStudent.getGpa()) {
maxStudent = studentArray[i];
}
if (studentArray[i].getGpa() < minStudent.getGpa()) {
minStudent = studentArray[i];
}
}
System.out.printf("The highest GPA is: %.1f%n", maxStudent.getGpa());
System.out.printf("The lowest GPA is: %.1f%n", minStudent.getGpa());
for (Student s : studentArray) {
System.out.printf("Name: %s %s%n", s.getFirstName(), s.getLastName());
System.out.printf("Age: %d%n", s.getAge());
System.out.printf("GPA: %.1f%n", s.getGpa());
}
}
}
which I ran; producing
The highest GPA is: 3.3
The lowest GPA is: 2.8
Name: Rebecca Collins
Age: 22
GPA: 3.3
Name: Alex White
Age: 19
GPA: 2.8
Name: Jordan Anderson
Age: 22
GPA: 3.1
And, if you're using Java 8+, you could simplify the main code with DoubleSummaryStatistics by streaming the Student(s), mapping to the gpa value and then collecting the statistics. Like,
public static void main(String[] args) throws Exception {
Student st1 = new Student("Rebecca", "Collins", 22, 3.3);
Student st2 = new Student("Alex", "White", 19, 2.8);
Student st3 = new Student("Jordan", "Anderson", 22, 3.1);
Student[] studentArray = { st1, st2, st3 };
DoubleSummaryStatistics dss = Arrays.stream(studentArray).mapToDouble(Student::getGpa).summaryStatistics();
System.out.printf("The highest GPA is: %.1f%n", dss.getMax());
System.out.printf("The lowest GPA is: %.1f%n", dss.getMin());
Arrays.stream(studentArray).map(s -> String.format("Name: %s %s%nAge: %d%nGPA: %.1f", //
s.getFirstName(), s.getLastName(), s.getAge(), s.getGpa())).forEach(System.out::println);
}

Java Arrays and Referencing

As part of the curriculum at my school, we are working on some CodeHS Java.
There is one problem that I'm stuck on:
Taking our Student and Classroom example from earlier, you should fill in the method getMostImprovedStudent, as well as the method getExamRange. The most improved student is the one with the largest exam score range.
To compute the exam score range, you must subtract the minimum exam score from the maximum exam score.
For example, if the exam scores were 90, 75, and 84, the range would be 90 - 75 = 15.
This is the Student class which I added my method getExamRange().
import java.util.*;
public class Student
{
private static final int NUM_EXAMS = 4;
private String firstName;
private String lastName;
private int gradeLevel;
private double gpa;
private int[] exams;
private int numExamsTaken;
public static int[] examRange = new int[Classroom.numStudentsAdded];
private int i = 0;
/**
* This is a constructor. A constructor is a method
* that creates an object -- it creates an instance
* of the class. What that means is it takes the input
* parameters and sets the instance variables (or fields)
* to the proper values.
*
* Check out StudentTester.java for an example of how to use
* this constructor.
*/
public Student(String fName, String lName, int grade)
{
firstName = fName;
lastName = lName;
gradeLevel = grade;
exams = new int[NUM_EXAMS];
numExamsTaken = 0;
}
public int getExamRange()
{
Arrays.sort(exams);
examRange[i] = exams[exams.length-1] - exams[0];
i++;
return exams[exams.length-1] - exams[0];
}
public String getName()
{
return firstName + " " + lastName;
}
public void addExamScore(int score)
{
exams[numExamsTaken] = score;
numExamsTaken++;
}
// This is a setter method to set the GPA for the Student.
public void setGPA(double theGPA)
{
gpa = theGPA;
}
/**
* This is a toString for the Student class. It returns a String
* representation of the object, which includes the fields
* in that object.
*/
public String toString()
{
return firstName + " " + lastName + " is in grade: " + gradeLevel;
}
}
And this is the Classroom class in which I added the method getMostImprovedStudent().
import java.util.*;
public class Classroom
{
Student[] students;
static int numStudentsAdded;
public Classroom(int numStudents)
{
students = new Student[numStudents];
numStudentsAdded = 0;
}
public Student getMostImprovedStudent()
{
Arrays.sort(Student.examRange);
//return Student.examRange[0];
}
public void addStudent(Student s)
{
students[numStudentsAdded] = s;
numStudentsAdded++;
}
public void printStudents()
{
for(int i = 0; i < numStudentsAdded; i++)
{
System.out.println(students[i]);
}
}
}
I can get the exam Range by sorting the exams array then subtracting the smallest from the biggest, but once I do this, how do I find the student with the biggest exam range, and return it?
The way you would do this is looping through students, and have a variable to hold the biggest difference in score, and the most improved student:
public Student getMostImprovedStudent()
{
Student mostImproved = students[0];
int biggest = student[i].getExamRange();
for(int i = 1; i < students.length; i++) {
if(students[i].getExamRange() > biggest) {
mostImproved = students[i];
biggest = students[i].getExamRange();
}
}
return mostImproved;
}
However Java 8+ we can do:
public Student getMostImprovedStudent()
{
return Arrays.stream(students)
.max(Comparator.comparing(Student::getExamRange))
.get();
}
Which is assuming that students is not empty
As I explained in the comment above you can do it this way:
public Student getMostImprovedStudent() {
Student maxRangeStudent = null;
int maxRange = 0;
for (Student student: students) {
int curExamRange = student.getExamRange();
if (curExamRange > maxRange){
maxRangeStudent = student;
maxRange = curExamRange;
}
}
return maxRangeStudent;
}

Trying to pass array values using a constructor

I've created all of my objects in my class "student" by hand and really just need to use an array to put the names, grades and ID numbers into. When I try, it gives me an error about incompatible types. I understand it's probably due to a restriction on some sort of syntax type of error. Could anyone help with the physical grammar of this portion please? It would be much appreciated!
package bilak_sackin_assignment_7;
public class Bilak_Sackin_Assignment_7 {
public static void main(String[] args) {
student Frank = new student("Frank", 95.2, 11231);
student Billy = new student("Billy", 65.6, 656454);
student Alex = new student("Alex", 65.2, 123456);
student Miranda = new student("Miranda", 80.0, 963852);
student Joel = new student("Joel", 89.9, 486248);
Frank.display();
Billy.display();
Alex.display();
Miranda.display();
Joel.display();
}
}
class student {
String[] name = new String[5];
double[] grade = new double[5];
int[] ID = new int[5];
public student(String[] n, double[] g, int[] d) {
name = n;
grade = g;
ID = d;
}
public void display() {
for (int i = 0; i < 4; i++) {
System.out.println("Names: " + name[i]);
System.out.println("Grades: " + grade[i]);
System.out.println("Student ID: " + ID[i]);
}
}
}
I'm quite new to this too, but surely you're not needing arrays, you're creating objects. Remove all your [ and ], like this -
public static void main(String[] args) {
student Frank = new student("Frank",95.2,11231);
student Billy = new student("Billy", 65.6, 656454);
student Alex = new student("Alex", 65.2, 123456);
student Miranda = new student("Miranda", 80.0, 963852);
student Joel = new student("Joel", 89.9, 486248);
Frank.display();
Billy.display();
Alex.display();
Miranda.display();
Joel.display();
}
}
class student
{
String name;
double grade;
int ID;
public student(String n, double g, int d)
{
name = n;
grade = g;
ID = d;
}
public void display()
{
System.out.println("Names: " + name);
System.out.println("Grades: " + grade);
System.out.println("Student ID: " + ID);
}
}
That works for me.
If I'm right, PLEASE mark me as right, I need the rep! :-)
public student(String[] n, double[] g, int[] d)
{
name = n;
grade = g;
ID = d;
}
Your constructor expects an array of Strings, an array of doubles, and an array of ints.
This, however, is what you pass:
new student("Joel", 89.9, 486248);
One single String, one single double, and a single int.
My guess, you don't need arrays in your Student class, except for the grades.
So, step one is to remove the arrays for name and id.
step two: pass an array of doubles as grades.
In your constructor for student, all of the inputs are primitive arrays however, you are not using them as such in the creation of the objects above.
If you want to use a constructor as follows:
Student billy = new Student("Billy", 23, 35);
then you must define the constructor with non-array inputs i.e.
class Student {
String name;
double grade;
int id;
public Student(String name, double grade, int id) {
this.name = name;
this.grade = grade;
this.id = id;
}
}
Alrighty, I decided to use #NickL's idea by using the array to construct the objects and then access it as an array afterwards.
package bilak_sackin_assignment_7;
public class Bilak_Sackin_Assignment_7 {
public static void main(String[] args) {
String name[] = {"Frank", "Billy","Alex", "Miranda", "Joel" };
double grades[] = {95.2, 65.6, 65.2, 80.0, 89.9};
int iD[] = {112312, 656454, 123456, 963852, 486248};
for (int i = 0; i < 5; i++)
{
String names = name[i];
double grade =(grades[i]);
int ID = (iD[i]);
System.out.println("Name: " + names + " | Grade: " + grade + " | ID number: " + ID);
}
}
}

Removing smallest key from treeMap

I'm creating a scoring system using a treeMap and I want to only display the top 3 results. When the player inputs the 4th result (if it's bigger than the current smallest value) how do I make it delete the smallest value and replace it with the new value. My code so far so sorting the scores:
Map<Integer, String> treeMap = new TreeMap<Integer, String>(new MyCopr());
treeMap.put(name1val, name1);
treeMap.put(name2val, name2);
treeMap.put(name3val, name3);
treeMap.put(tempval, tempname);
for (Map.Entry<Integer, String> entry : treeMap.entrySet()) {
playername1.append("Key : " + entry.getKey() + " Value : "
+ entry.getValue() + "\n");
}
}
class MyCopr implements Comparator<Integer> {
#Override
public int compare(Integer lhs, Integer rhs) {
return rhs.compareTo(lhs);
}
}
From here what can I do to replace the smallest value? Thanks.
I would use a set of scores (like this) -
private static int MAX_SCORES = 3;
private SortedSet<Score> scores = new TreeSet<Score>();
public Set<Score> getScores() {
return scores;
}
public void addScore(String name, int score) {
scores.add(new Score(name, score));
while (scores.size() > MAX_SCORES) {
scores.remove(scores.first());
}
}
private class Score implements Comparable<Score> {
private String name;
private int score;
private Score(String name, int score) {
this.name = name;
this.score = score;
}
public int compareTo(Score obj) {
if (this == obj) {
return 0;
}
if (this.score < obj.score) {
return -1;
} else if (this.score > obj.score) {
return 1;
}
return name.compareTo(obj.name);
}
public String toString() {
return name + " - score = " + score;
}
}
And then use it like so ...
System.out.println(obj.getScores());
obj.addScore("Player 1", 1);
obj.addScore("Player 2", 2);
obj.addScore("Player 3", 3);
System.out.println(obj.getScores());
obj.addScore("Player 4", 4);
System.out.println(obj.getScores());
Which yields this (when I run it) -
[]
[Player 1 - score = 1, Player 2 - score = 2, Player 3 - score = 3]
[Player 2 - score = 2, Player 3 - score = 3, Player 4 - score = 4]

Categories

Resources