標籤:div logs 程式設計基礎 str private 英語 com name nbsp
最近JAVA開了物件導向的課程,老師布置了作業,嗯,就是這樣,啥作業我不怎麼會描述,代碼如下,自己做的,代碼很不成熟,請諒解!大概就是這樣:
class Student{ private String stuno; private String name; private float math; private float english; private float computer; /*Student() { }*/ public void StuPer(String stuno,String name) { this.stuno = stuno; this.name = name; } public void stuGrade(float math,float english,float computer) { this.math = math; this.english = english; this.computer = computer; } public void count() { float average = (math + english + computer)/3; System.out.println("平均成績為:" + average); float sum = (math + english + computer); System.out.println("總成績為:" + sum); float max = 0; if(math > english) { max = math; } else { max = english; } if(max > computer) { System.out.println("最高成績為:" + max); } else { System.out.println("最高成績為:" + computer); } float min = 0; if(math > english) { min = english; } else { min = math; } if(min > computer) { System.out.println("最低成績為:" + computer); } else { System.out.println("最低成績為:" + min); } } public void tell() { System.out.println("姓名:" + name + " 學號: " + stuno); System.out.println("數學成績: " + math + "英語成績: " + english + "電腦成績: " + computer); }}class stuInfo{ public static void main(String[] args) { Student person = new Student(); person.StuPer("2015025500","張三"); person.stuGrade(50,60,70); person.tell(); person.count(); } }
程式運行結果為:
姓名:張三 學號: 2015025500
數學成績: 50.0英語成績: 60.0電腦成績: 70.0
平均成績為:60.0
總成績為:180.0
最高成績為:70.0
最低成績為:50.0
Java程式設計基礎 物件導向 練習