Use Student Class
        
            Submit solution
        
    
    
    
    
    
    
    
    
    
                    
                
        
            
        
        Points:
        
                50 (partial)        
    
    
        Time limit:
        1.0s
    
    
        Memory limit:
        256M
    
    
                        Authors:
                        
                    
        
                    Problem types                
                
        
                Allowed languages
            
            
Java 19, Java 8            
        題目說明
以下為Student類別的程式碼
class Student {
    // Field
    private String name = "Unknown";    // 名字
    private String id = "12156000";     // 學號
    private int totalCredits = 0;       // 累計學分數
    // Constructor
    public Student() {
    }
    public Student(String name, String id) {
        this.name = name;
        this.id = id;
    }
    // Method
    public void addCredits(int credits) {
        this.totalCredits += credits;
    }
    public void printId() {
        System.out.print(name + "'s student ID is " + id);
    }
    public int getCredits() {
        return totalCredits;
    }
}
使用上面定義的類別程式碼,在主程式區段寫出【執行學生資料建置】的程式碼
小提示
import java.util.Scanner;  
// 貼上Student類別的程式碼  
// 主程式區段  
public class MyProgram {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        // 宣告name、id
        // 請完成此區段程式碼
        // 必須使用Student類別
        // Student newStudent = new Student(name, id);
        // 累計學分,使用addCredits()
        // 輸出,使用printId()、getCredits()
    }
}輸入
學生名字 學生學號
已修習學分數(可有多項,當遇到0結束計算)
輸出
{name}'s student ID is {id}, total credits: {totalCredits}
測試資料1 輸入
zz 09156146
2 2 3 1 3 2 2 0 3 1測試資料1 輸出
zz's student ID is 09156146, total credits: 15
Comments
題解