/* 「授業表」の定義 */ import java.io.*; //入出力関連パッケージの利用を宣言する public class ClassTable{ int no; // 属性1・時限 String subject; // 属性2・科目名 String room; // 属性3・教室名 /* メソッド1・属性の値を表示する */ public void showData (){ System.out.print("時限:"); System.out.println(no); // 「時限」の値を表示して改行 System.out.print("科目名:"); System.out.println(subject); // 「科目名」の値を表示して改行 System.out.print("教室名:"); System.out.println(room); // 「教室名」の値を表示して改行 } /* メソッド2・属性の値を入力する */ public void inputData( BufferedReader reader )throws Exception{ try{ System.out.print("時限:"); //ユーザーに入力の対象を示す no = Integer.parseInt(reader.readLine()); //「時限」の値を入力する System.out.print("科目名:"); subject = reader.readLine(); //「科目名」の値を入力する System.out.print("教室名:"); room = reader.readLine(); //「教室名」の値を入力する }//エラーが発生したらエラーメッセージを示しプログラムを終了する catch(Exception e){System.out.println("エラーが発生したのでプログラムを終了します");} } } |
>>第4講・その2(2)に戻る