20165234 Homework for the tenth week of "Java Programming"

Textbook p448 Example15_4
1. Add the last three students of your student number to the list. The student number is the last three students to join from the 1st
2. Submit a screenshot of the running result
3. Engrave the push code to the code cloud

 



In data structures and algorithms, sorting is a very important operation. To make a class can be sorted, there are two ways: - With the source code of the 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 sorts, 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: 1. 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) 2. Sort the 5 students in increasing order by student number and total score, and submit the codes of two Comparators 3. Submit code to Code Cloud after class class Student { private String id;//Indicates the student number private String name;//Indicates name private int age;//Indicates age private double computer_score;//Indicates the score of computer courses private double english_score;//Indicates the score of the English class private double maths_score;//Indicates the score of the math class private double total_score;// Indicates the total score private double ave_score; //represents the average 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; }//Get the student number 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 math course grade of the current object, public double getEnglish_score(){ return english_score; }//Get the English course grade of the current object, 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 of the three subjects 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; } }







See the attachment, supplement the content of MyList.java, and submit a screenshot of the running result (full screen)
Push code to Code Cloud after class


public class MyList {
	public static void main(String [] args) {
		//Select the appropriate construction method and create four nodes with the student numbers of two students before and after your student number
		
		
		//Connect the above four nodes into a singly linked list without a head node
		
		// Traverse the singly linked list and print the value of each node

		//Insert yourself into the appropriate position (in ascending order of student number)

		// Traverse the singly linked list and print the value of each node

		//remove self from the linked list

		// Traverse the singly linked list and print the value of each node
	}
}


public class Node<T> //Single linked list node class, T specifies the element type of the node
{
    public T data; //Data field, storing data elements
    public Node<T> next; //Address field, refer to the successor node

    public Node(T data, Node<T> next) //Construct the node, data specifies the data element, next specifies the successor node
    {
        this.data = data; //T object reference assignment
        this.next = next; //Node<T> object reference assignment
    }
    public Node()
    {
        this(null, null);
    }
    public String toString() //Return the description string of the node data field
    {
        return this.data.toString();
    }
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325473949&siteId=291194637