CS计算机代考程序代写 Java import java.io.File;

import java.io.File;
import java.util.List;

/**
*
* @author nanwang
*
The goal of this task is to write a program that loads/stores a list of students in XML format. `StudentCollection.java` class contains
a list of `Student` instances. Each student has his/her `age` and `name`, which need to be saved as attributes of XML node. Additionally,
each student can have three possible properties: `height`, `weight` and `courses`. `courses` property contains a list of `course` elements.
Each course has a course `name` attribute and a `grade` value. Note that not every student has all three properties. Some properties of students may be missing
(for example, see the test cases in StudentsTest.java). You job is to implement the below two methods in `StudentCollection.java`:

* `saveToFile`
* `loadFromFile`

Note that these methods should take into account the available properties of a given student. You are allowed to add additional asserts
and test cases to test your solutions. You can use `getAttribute(String name)` and `setAttribute(String name, String value)` of `Element`
class to get and set the attributes of XML node. **Please upload `StudentCollection.java` to wattle!**
*/
public class StudentCollection {

private final List students;

public StudentCollection(List students) {
this.students = students;
}

public List getStudents() {
return students;
}

/**
* Implement this method to save the list of students to XML file
* HINT: `setAttribute(String name, String value)` in `Element` can be used to set `name` and `age` properties
* @param file
*/
public void saveToFile(File file) {
//START YOUR CODE

//END YOUR CODE
}

/**
* Implement this method to load from the XML file to create a `StudentCollection`
* HINT: `getAttribute(String name)`in `Element` can be used to get `name` and `age` properties
* @param file
* @return
*/
public static StudentCollection loadFromFile(File file) {
//START YOUR CODE

//END YOUR CODE
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}

if (o instanceof StudentCollection) {
StudentCollection studentCollection = (StudentCollection) o;
return this.students.equals(studentCollection.students);
}

return false;
}
}