20165237 2017-2018-2 "Java Programming" Week 10 Exam Supplement and Programming Questions
Knowledge point
1. A linked list is a data structure composed of several objects called nodes, each node contains a data and a reference to the next node.
2. The class methods for sorting and searching provided by the Collections class are as follows: public static sort(List
Data Structure - Sort:
Topic:
In data structures and algorithms, sorting is a very important operation. There are two ways to allow a class to be sorted:
- 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 code to Code Cloud after class
class Student {
private String id;//表示学号
private String name;//表示姓名
private int age;//表示年龄
private double computer_score;//表示计算机课程的成绩
private double english_score;//表示英语课的成绩
private double maths_score;//表示数学课的成绩
private double total_score;// 表示总成绩
private double ave_score; //表示平均成绩
public 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;
}//获得当前对象的学号,
public double getComputer_score(){
return computer_score;
}//获得当前对象的计算机课程成绩,
public double getMaths_score(){
return maths_score;
}//获得当前对象的数学课程成绩,
public double getEnglish_score(){
return english_score;
}//获得当前对象的英语课程成绩,
public void setId(String id){
this.id=id;
}// 设置当前对象的id值,
public void setComputer_score(double computer_score){
this.computer_score=computer_score;
}//设置当前对象的Computer_score值,
public void setEnglish_score(double english_score){
this.english_score=english_score;
}//设置当前对象的English_score值,
public void setMaths_score(double maths_score){
this.maths_score=maths_score;
}//设置当前对象的Maths_score值,
public double getTotalScore(){
return computer_score+maths_score+english_score;
}// 计算Computer_score, Maths_score 和English_score 三门课的总成绩。
public double getAveScore(){
return getTotalScore()/3;
}// 计算Computer_score, Maths_score 和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;
}
}
Make up screenshots:
git log :
Programming question code hosting
(Screenshot of the running result of the program)
(1) Use the stack structure to output several items of an, where an=2an-1+2an-2, a1=3, a2=8
(2) Write a program to store the students' English transcripts in the linked list into a tree set, so that the program is automatically sorted and the sorting results are output
(3) There are 10 U disks with two important attributes: price and capacity. Write an application that uses TreeMap