practice one
Textbook p448 Example15_4
- Add three students after your student number to the list. The student number is the last three students to join from the 1st
- Submit a screenshot of the running result
Engrave the push code to the code cloud
practice two
In data structures and algorithms, sorting is a very important operation. To make a class can be sorted, there are two ways:
- There is a source code of a class, sort a member variable, let the class implement the Comparable interface, and call Collection.sort(List)
- If there is no source code of the class, or multiple sorting, create a new class, implement the Comparator interface and call Collection.sort(List, Compatator)
For the following Student class, use Comparator programming to complete the following functions:
- Create a new student list in the test class StudentTest, including two students before and after oneself and student number, a total of 5 students, and give the running results (before sorting, after sorting)
- Sort these 5 students in increasing order by student number and total score, and submit the codes of two Comparators
Submit the code to the code cloud after class
```
class Student {
private String id;//indicates the student number
private String name;//indicates the name
private int age;//indicates the age
private double computer_score;//indicates the score of the computer course
private double english_score;//Indicates the score of English class
private double maths_score;//Indicates the score of mathematics class
private double total_score;// Indicates the total score
private double ave_score; //Indicates the average scorepublic Student(String id, String name){
this.id = id;
this.name = name;
}
public Student(String id, String name, char sex, int age){
this(id, name);
this.sex = sex;
this.age = age;
}
public String getId(){
return id;
}//Get the student ID of the current object,
public double getComputer_score(){
return computer_score;
}//Get the computer course grade of the current object,
public double getMaths_score(){
return maths_score;
}//Get the current object's math course score,
public double getEnglish_score(){
return english_score;
}//Get the current object's English course score,public void setId(String id){
this.id=id;
}// Set the id value of the current object,
public void setComputer_score(double computer_score){
this.computer_score=computer_score;
}//Set the Computer_score value of the current object,
public void setEnglish_score(double english_score){
this.english_score=english_score;
}//Set the English_score value of the current object,
public void setMaths_score(double maths_score){
this.maths_score=maths_score;
}//Set the Maths_score value of the current object,public double getTotalScore(){
return computer_score+maths_score+english_score;
}// Calculate the total score of Computer_score, Maths_score and English_score.
public double getAveScore(){
return getTotalScore()/3;
}// Calculate the average score of Computer_score, Maths_score and English_score.
}
class Undergraduate extends Student{
private String classID;
public Undergraduate(String id, String name, char sex, int age,String classID){
super(id,name,sex,age);
this.classID=classID;
}
public String getClassID(){
return classID;
}
public void setClassID(String classID){
this.classID=classID;
}
}
##实践三
参见附件,补充MyList.java的内容,提交运行结果截图(全屏)
课下推送代码到码云
public class MyList {
public static void main(String [] args) {
//Select the appropriate construction method and create four nodes with the student IDs of two students before and after your student ID
//把上面四个节点连成一个没有头结点的单链表
//遍历单链表,打印每个结点的
//把你自己插入到合适的位置(学号升序)
//遍历单链表,打印每个结点的
//从链表中删除自己
//遍历单链表,打印每个结点的
}
}
public class Node
public Node(T data, Node<T> next) //构造结点,data指定数据元素,next指定后继结点
{
this.data = data; //T对象引用赋值
this.next = next; //Node<T>对象引用赋值
}
public Node()
{
this(null, null);
}
public String toString() //返回结点数据域的描述字符串
{
return this.data.toString();
}
}
```