private int int void j Button Calc Action
原型プログラム private int int } void j. Button. Calc. Action. Performed(Action. Event evt) { year=Integer. parse. Int(j. Text. Field. Year. get. Text()); month=Integer. parse. Int(j. Text. Field. Month. get. Text()); day=Integer. parse. Int(j. Text. Field. Day. get. Text());
基礎課題5 -1 private void j. Button. Calc. Action. Performed(Action. Event evt) { int year=Integer. parse. Int(j. Text. Field. Year. get. Text()); int month=Integer. parse. Int(j. Text. Field. Month. get. Text()); int day=Integer. parse. Int(j. Text. Field. Day. get. Text()); String week. Day=get. Week. Day(year, month, day); j. Label. Result. set. Text(week. Day+"です。"); } String get. Week. Day(int year, int month, int day) { String ans=""; return ans; } 最初に全体構造を設計することがポイント!
基礎課題5 -2 String get. Week. Day(int year, int month, int day) { String ans=""; return ans; }
基礎課題5 -2 String get. Week. Day(int year, int month, int day) { int day. Number=get. Day. Number(year, month, day); int no=day. Number % 7; String[] week. Day={"日曜日", "月曜日", "火曜日", "水曜日", "木曜日", "金曜日", "土曜日"}; String ans= week. Day[no]; return ans; } int get. Day. Number(int year, int month, int day) { int ans=0; return ans; }
基礎課題5 -3 int get. Day. Number(int year, int month, int day) { int ans=0; return ans; }
基礎課題5 -3 int get. Day. Number(int year, int month, int day) { int[] month. Day={0, 31, 28, 31, 30, 31}; int ans=0; // 2000年 12/31から(year-1)年 12/31日までの日数のカウント for(int i=2001; i<year; i++){ if( (i%4)==0 && (i%100)!=0 || (i%400)==0 ){ ans=ans+366; } else { ans=ans+365; } } // year年の 1/1から(month-1)月の月末までの日数のカウント // month月の一日からday日までの日数のカウント return ans; }
基礎課題5 -4 boolean is. Leap. Day(int year){ boolean ans=false; if( (year%4)==0 && (year%100)!=0 || (year%400)==0 ) { ans=true; } return ans; }
モジュール化に基づくプログラムの作成 まとめ① メインプログラムの作成(設計) private void j. Button. Calc. Action. Performed(Action. Event evt) { int Year=Integer. parse. Int(j. Text. Field. Year. get. Text()); int Month=Integer. parse. Int(j. Text. Field. Month. get. Text()); int Day=Integer. parse. Int(j. Text. Field. Day. get. Text()); String week. Day=get. Week. Day(year, month, day); j. Label. Result. set. Text(week. Day+"です。"); } 西暦年月日から曜日を求めるメソッド
- Slides: 21