1. 程式人生 > 其它 >|NO.Z.00038|——————————|BigDataEnd|——|Java&方法封裝.V20|---------------------------------------------|Java.v20|學生資訊錄入|JavaBean概念|

|NO.Z.00038|——————————|BigDataEnd|——|Java&方法封裝.V20|---------------------------------------------|Java.v20|學生資訊錄入|JavaBean概念|



[BigDataJava:Java&方法封裝.V20]                                                                             [BigDataJava.面向物件] [|章節二|方法和封裝|學生資訊的錄入和JavaBean的概念|]








一、學生資訊的錄入和JavaBean的概念
### --- 案例題目

~~~     ——>        提示使用者輸入班級的學生人數以及每個學生的資訊,
~~~     ——>        學生的資訊有:學號、姓名,最後分別打印出來。
~~~     ——>        提示:Student[] arr= new Student[num];
二、案例分析圖 三、JavaBean——JavaEE的引數
### --- JavaBean的概念

~~~     ——>        JavaBean是一種Java語言寫成的可重用元件,其它Java 類可以通過反射機制發現和操作這些JavaBean 的屬性。
~~~     ——>        JavaBean本質上就是符合以下標準的Java類:
~~~     ——>        類是公共的
~~~     ——>        有一個無參的公共的構造器
~~~     ——>        有屬性,且有對應的get、set方法
四、程式設計實現
### --- 程式設計實現

/*
    程式設計實現學生資訊的錄入和列印
 */
import java.util.Scanner; 
 
public class StudentTest2 {
    
    public static void main(String[] args) {
        
        // 1.提示使用者輸入學生的人數並使用變數記錄
        System.out.println("請輸入學生的人數:");
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        
        // 2.根據學生的人數準備對應的一維陣列
        // int[] arr = new int[3];  - 表示宣告一個長度為3元素型別為int型別的一維陣列
        // 陣列中的每個元素都是int型別,也就是說陣列中的每個元素都可以看做是一個int型別的變數,使用整數資料進行初始化 arr[0] = 10;
        // 下面的程式碼是宣告一個長度為num元素型別為Student型別的一維陣列
        // 陣列中的每個元素都是Student型別,也就是說陣列中的每個元素都可以看做Student型別的變數,arr[0] = new Student();
        Student[] arr = new Student[num];
        
        
        // 3.提示使用者輸入每個學生的資訊(學號 姓名)並記錄到一維陣列中
        for(int i = 0; i < num; i++) {
            System.out.println("請輸入第" + (i+1) + "個學生的資訊(學號 姓名):");
            arr[i] = new Student(sc.nextInt(), sc.next());
        }
        
        System.out.println("-----------------------------------------------");
        // 4.列印所有學生資訊
        System.out.println("該班級的所有學生資訊有:");
        for(int i = 0; i < num; i++) {
            //System.out.println(arr[i]);
            arr[i].show();
        }
    }
}
五、編譯列印
C:\Users\Administrator\Desktop\project>java StudentTest2
請輸入學生的人數:
3
請輸入第1個學生的資訊(學號 姓名):
1001 zhangfei
請輸入第2個學生的資訊(學號 姓名):
1002 guanyu
請輸入第3個學生的資訊(學號 姓名):
1003 liubei
-----------------------------------------------
該班級的所有學生資訊有:
我是zhangfei,我的學號是1001
我是guanyu,我的學號是1002
我是liubei,我的學號是1003








===============================END===============================


Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart                                                                                                                                                    ——W.S.Landor



來自為知筆記(Wiz)