生活随笔
收集整理的這篇文章主要介紹了
学生类
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
定義一個學生類,學生的屬性有學號、姓名、性別,還有高數成績、英語成績、C語言成績、JAVA語言成績,這些都是私有屬性。另外還有公有的構造方法、普通的賦值方法,以及返回各個屬性的方法。實現對于給定的多組數據,每組數據為:學號、姓名、性別、高數成績、英語成績、C語言成績、JAVA語言成績。能夠根據給定的不定組數的學生信息,按照要求在輸出學生一般數據的同時,再輸出平均成績和總成績,數據中間用一個英文空格間隔。參見樣例:
輸入:
1701 zhangsan m 80 80 80 80
1702 zhangmei f 90 90 90 90
輸出:
1701 zhangsan m 80 80 80 80 80 320
1702 zhangmei f 90 90 90 90 90 360。
public class Main {public static void main(String[] args) {Scanner in=new Scanner (System.in);
int a,b,c,d,f;
char e;
String name;
while(in.hasNext()){
a=in.nextInt();
name=in.next();
e=in.next().charAt(0);
b=in.nextInt();
c=in.nextInt();
d=in.nextInt();
f=in.nextInt();
Student stu=new Student(a,name,e,b,c,d,f);
stu.shuchu(a,name,e);
stu.chengji(b, c, d, f);}}}class Student{private int 學號;private String 姓名;private char 性別;private int 高數;private int 英語;private int c語言;private int Java語言;public Student(int 學號,String 姓名,char 性別,int 高數,int 英語,int c語言,int Java語言){this.c語言=c語言;this.Java語言=Java語言;this.姓名=姓名;this.學號=學號;this.性別=性別;this.英語=英語;this.高數=高數;}public void shuchu(int 學號,String 姓名,char 性別){System.out.print(學號+" "+姓名+" "+性別);}public void chengji(int 高數,int 英語,int c語言,int Java語言){System.out.print(" "+高數+" "+英語+" "+c語言+" "+Java語言+" ");System.out.println((高數+英語+c語言+Java語言)/4+" "+(高數+英語+c語言+Java語言)); }}
總結
以上是生活随笔為你收集整理的学生类的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。