114-2 OOP B組 Week11 實習課練習 Problem1
Submit solution
Points:
100 (partial)
Time limit:
5.0s
Memory limit:
98M
Author:
Problem type
Allowed languages
Java 19, Java 8
題目說明
某學校希望設計一個簡單的學生成績系統,用來紀錄學生資料與計算成績。 每位學生會有以下資料:
- 學號
- 姓名
- 計算機概論成績
- 計算機程式設計成績
- 微積分成績
題目要求
題目要求
請完成Student類別:
Attribute:ID:Stringname:StringcomputerIntro:intprogramming:intcalculus:int
Method:showInfo()getTotal()getAverage()
複製下方程式碼作答 注意!! 不可以修改範例程式碼:
import java.util.Scanner;
class Student {
// TODO 1: 宣告屬性
______________________
______________________
______________________
______________________
______________________
// TODO 2: 完成建構子
public Student(String ID, String name, int computerIntro, int programming, int calculus) {
______________________
______________________
______________________
______________________
______________________
}
// TODO 3: 完成 showInfo method
public void showInfo() {
System.out.println("學號: " + ____________________);
System.out.println("姓名: " + ____________________);
System.out.println("計算機概論: " + ____________________);
System.out.println("計算機程式設計: " + ____________________);
System.out.println("微積分: " + ____________________);
}
// TODO 4: 完成 getTotal method
public int getTotal() {
return ________________________________;
}
// TODO 5: 完成 getAverage method
public double getAverage() {
return ________________________________;
}
}
public class test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String ID = sc.next();
String name = sc.next();
int computerIntro = sc.nextInt();
int programming = sc.nextInt();
int calculus = sc.nextInt();
sc.close();
// TODO 6: 建立學生物件
Student stu1 = new Student(ID, name, computerIntro, programming, calculus);
// TODO 7: 呼叫 showInfo()
________________________;
// TODO 8: 印出總分
System.out.println("總分: " + ____________________);
// TODO 9: 印出平均
System.out.println("平均: " + ____________________);
}
}測資範圍
\[0 <= N <= 999999999\]
範例輸入/輸出
範例輸入1
10156135 王小明 80 75 90
範例輸出1
學號: 10156135
姓名: 王小明
計算機概論: 80
計算機程式設計: 75
微積分: 90
總分: 245
平均: 81.66666666666667
範例輸入2
10156198 陳小美 100 95 98
範例輸出2
學號: 10156198
姓名: 陳小美
計算機概論: 100
計算機程式設計: 95
微積分: 98
總分: 293
平均: 97.66666666666667
範例輸入3
10156201 林志豪 60 70 50
範例輸出3
學號: 10156201
姓名: 林志豪
計算機概論: 60
計算機程式設計: 70
微積分: 50
總分: 180
平均: 60.0
Comments