1. 程式人生 > >20165234 《Java程序設計》第十周課下作業

20165234 《Java程序設計》第十周課下作業

static 類型 HA set node 學生 tostring 自己 進行

教材p448  Example15_4
1. list中增加自己學號後三名同學,學號是最後三名的從1號開始加入
2. 提交運行結果截圖
3. 刻下推送代碼到碼雲



在數據結構和算法中,排序是很重要的操作,要讓一個類可以進行排序,有兩種方法: - 有類的源代碼,針對某一成員變量排序,讓類實現Comparable接口,調用Collection.sort(List) - 沒有類的源代碼,或者多種排序,新建一個類,實現Comparator接口 調用Collection.sort(List, Compatator) 針對下面的Student類,使用Comparator編程完成以下功能: 1. 在測試類StudentTest中新建學生列表,包括自己和學號前後各兩名學生,共5名學生,給出運行結果(排序前,排序後) 2. 對這5名同學分別用學號和總成績進行增序排序,提交兩個Comparator的代碼 3. 課下提交代碼到碼雲 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; } }







參見附件,補充MyList.java的內容,提交運行結果截圖(全屏)
課下推送代碼到碼雲


public class MyList {
	public static void main(String [] args) {
		//選用合適的構造方法,用你學號前後各兩名同學的學號創建四個結點
		
		
		//把上面四個節點連成一個沒有頭結點的單鏈表
		
		//遍歷單鏈表,打印每個結點的

		//把你自己插入到合適的位置(學號升序)

		//遍歷單鏈表,打印每個結點的

		//從鏈表中刪除自己

		//遍歷單鏈表,打印每個結點的
	}
}


public class Node<T>                             //單鏈表結點類,T指定結點的元素類型
{
    public T data;                               //數據域,存儲數據元素
    public Node<T> next;                         //地址域,引用後繼結點

    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();
    }
}

20165234 《Java程序設計》第十周課下作業