20165237 2017-2018-2 《Java程式設計》第十周考試補做及編程題

來源:互聯網
上載者:User

標籤:string   演算法   代碼   功能   mit   lov   turn   tee   tco   

20165237 2017-2018-2 《Java程式設計》第十周考試補做及編程題知識點

1、鏈表是由若干個稱作節點的對象組成的一種資料結構,每個節點含有一個資料和下一個節點的引用 。

2、Collections類提供的用於排序和尋找的類方法如下: public static sort(List

資料結構-排序:

題目:
在資料結構和演算法中,排序是很重要的操作,要讓一個類可以進行排序,有兩種方法:

  • 有類的原始碼,針對某一成員變數排序,讓類實現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;    }}
補做:

StudentPX

git log :

編程題代碼託管

(程式的運行結果)
(1)使用堆棧結構輸出an的若干項,其中an=2an-1+2an-2,a1=3,a2=8

(2)編寫一個程式,將鏈表中的學生英語成績單存放到一個樹集中,使得按程式自動排序,並輸出排序結果

(3)有10個隨身碟,有兩個重要的屬性:價格和容量。編寫一個應用程式,使用TreeMap

20165237 2017-2018-2 《Java程式設計》第十周考試補做及編程題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.