import java.util.ArrayList;
import java.util.Collections;
public class StringSorting {
public static void main(String[] args) {
ArrayList persons = new ArrayList();
persons.add(new Person("Sam"));
persons.add(new Person("Jerry"));
persons.add(new Person("Abel"));
persons.add(new Person("Sara"));
persons.add(new Person("Tom"));
persons.add(new Person("Matt"));
persons.add(new Person("Chris"));
persons.add(new Person("Nancy"));
persons.add(new Person("Sandra"));
Collections.shuffle(persons);
reorderEveryone(persons);
String result = persons.toString();
String expected = "[Jerry, Sam, Nancu, Sandra, Abel, Matt, Chris, Tom, Sara]";
println("It is now : "+result);
println("It should be: " + expected);
if(result.equals(expected)){
println("It works!");
} else {
println("Keep trying!");
}
}
private static void println(Object s) {
System.out.println(s);
}
private static class Person {
String name;
public Person(String name) {
this.name = name;
}
@Override
public String toString() {
return name;
}
}
/// DO NOT CHANGE CODE BEFORE THIS LINE
private static void reorderEveryone(ArrayList<Person> persons) {
補充這裡 讓 這個打印出working
}
}
for (Person p : persons)
{
System.out.println(p.toString());
}