當前位置:編程學習大全網 - 編程語言 - java.student類

java.student類

class Student {

private String id;//表示學號

private String name;//表示姓名

private char sex;//表示性別

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;

}

}

class Graduate extends Student{

private String tutor;

public Graduate(String id, String name, char sex, int age,String tutor){

super(id,name,sex,age);

this.tutor=tutor;

}

public double getTotalScore() {

return getComputer_score()+getEnglish_score();

}

public double getAveScore(){

return getTotalScore()/2;

}

}

public class Test {

public static void main(String[] args) {

Undergraduate ug=new Undergraduate("0001", "張三", '男',19, "2083");

ug.setComputer_score(65);

ug.setEnglish_score(75);

ug.setMaths_score(85);

Graduate g=new Graduate("1001","李四",'女',24,"王五");

g.setComputer_score(65);

g.setEnglish_score(75);

g.setMaths_score(85);

Student s[]={ug,g};

for(int i=0;i<s.length;i++){

System.out.println("學號:"+s[i].getId()+" 計算機成績:"+s[i].getComputer_score()+

" 英語成績:"+s[i].getEnglish_score()+" 數學成績:"+s[i].getMaths_score()

+" 總成績:"+s[i].getTotalScore()+" 平均成績:"+s[i].getAveScore());

}

}

}

  • 上一篇:S7-200編程軟件講座
  • 下一篇:長沙周南梅溪湖中學高中錄取線
  • copyright 2024編程學習大全網