1 / 8

101. 만년 달력 만들기

101. 만년 달력 만들기. ※ 문제 내용 : 2002 년 3 월 달력을 출력하자 . ※ 학습 내용 : 배열과 메서드를 이용하여 달력을 만든다 . ※ 힌트 내용 : 윤년의 횟수를 구한다 . ※ 소 스 : Calendarln7.java CalendarMain.java ※ 발 표 자 : 김 회승. 코드설명 Calenderln7.java. public class CalendarIn7{// 섹션 101 CalendarMain

Download Presentation

101. 만년 달력 만들기

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 101.만년 달력 만들기 ※ 문제 내용 : 2002년 3월 달력을 출력하자. ※ 학습 내용 : 배열과 메서드를 이용하여 달력을 만든다. ※ 힌트 내용 : 윤년의 횟수를 구한다. ※ 소 스 : Calendarln7.java CalendarMain.java ※ 발 표 자 : 김 회승

  2. 코드설명 Calenderln7.java • public class CalendarIn7{//섹션 101 CalendarMain • private int month[] = new int[]{31,28,31,30,31,30,31,31,30,31,30,31};//평년 • private int lmonth[] = new int[]{31,29,31,30,31,30,31,31,30,31,30,31};//윤년 • public boolean leapYearTF(int year){// 윤년을 체크 • boolean yearTF= false; • if((0 == (year % 4) && 0 != (year %100)) || 0 == year%400 ) • yearTF = true; • return yearTF; • } • //1~year 까지 윤년의 회수 구하기 • public int howManyLeapYear(int year){ • int count = 0; • for(int i = 1; i <=year; i++){ • if ( leapYearTF(i) ){ • count++; • } • } • return count; • }

  3. 코드설명 Calenderln7.java • //2005/9/25일이면 (2005/1/1 ~2005/8/31)일 총 일수 + 25(9월) • public int howManyDaysInYearsMonth(int year, int month, int day){ • int count = day; • if ( leapYearTF(year) ){ • for(int i = 0; i < month-1; i++){ • count+=this.lmonth[i]; • } • }else{ • for(int i = 0; i < month-1; i++){ • count+=this.month[i]; • } • } • return count; • } • //시작날짜가 0-->일,1-->월,2-->화,3-->수,4-->목,5-->금,6-->토 • public int startDayInCal(int year, int month){//년 월 1일의 첫날 • int count=0; • int leapYear=howManyLeapYear(year-1); • int howManyDaysInYear=howManyDaysInYearsMonth(year,month,1); • count=((leapYear)*2+(year-1-leapYear)+howManyDaysInYear); • return count%7; • }

  4. 코드설명 Calenderln7.java • public boolean isLastDay(int year, int month,int day){//마지막날 • boolean isL=false; • if(!leapYearTF(year)){ • if(day==this.month[month-1]){//평년 2월-->28 • isL=true; • } • }else{ • if(day==this.lmonth[month-1]){//윤년 2월-->29 • isL=true; • } • } • return isL; • } • public int getDates(int year, int month){//그달에 몇일이 있는가? • if(leapYearTF(year)){ • return this.lmonth[month-1];//윤년 • }else { • return this.month[month-1];//평년 • } • }

  5. 코드설명 Calenderln7.java • public void printCalendar(int year, int month){ • int linecheck = 0;// 날짜를 처음 찍는 위치 지정하는 변수 • String temp = "";// 처음 문자 간격 • System.out.println("Sun\tMon\tTue\tWed\tThu\tFri\tSat"); • linecheck = startDayInCal(year, month);//1일이 무슨 요일인가? • for(int j = 0; j < linecheck; j++){ • temp += "\t"; //1일이 수요일이면 탭 3개(일,월,화) • } • System.out.print(temp); • int count=getDates(year, month);//총 몇일이 있는가28,29,30,31? • for(int i = 1; i<= count; i++){ • System.out.print(i + "\t"); • linecheck ++; • if(linecheck == 7) {//토요일이냐 그러면 • if(this.isLastDay(year,month,i)){ • return ;//마지막 날이 끝나면 한 줄아래로 내릴 필요없다. • } • System.out.println(); • linecheck = 0; • }//if • }//for • }//printCalendar • }

  6. 코드설명 CalenderMain.java • public class CalendarMain{ • public static void main(String[] args) { • CalendarIn7 cal7 = new CalendarIn7(); • int year=2005; • for(int i=1;i<13;i++){ • System.out.println("\t\t"+year+"년\t"+i+"월\n"); • cal7.printCalendar(year,i); • System.out.println("\n-------------------"); • } • } • }

  7. 참고 028.CircuitTest.java • public class CircuitTest • { • public static void main(String[] args) • { • int ca=10; • int temp=23; • String say="hello"; • if((temp>ca)|((say="y")=="hello")){ • System.out.println("1: | "+say);} • if((temp>ca)||((say="l")=="hello")){ • System.out.println("2:|| "+say);} • if((temp<ca)&((say="s")=="hello")){ • System.out.println("3: & "+say); • }else{ • System.out.println("3:& else: "+say);} • if((temp<ca)&&((say="t")=="hello")){ • System.out.println("4: & "+say); • }else{ • System.out.println("4:& else: "+say); • } }}

  8. 200개의 예제만으로도Java를 정복할 수 있다!! 이 책은 Java 2(J2SE 5.0)를 기준으로 예제를 만들었으며, 자바의 핵심 개념과 주요 응용 사항(변수, 상수, 연산자, 조건/순환문, 기본 타입과 참조 타입, 자바 메모리 구조, 다형성, 메서드 오버라이딩/오버로딩, 스윙 어플리케이션, 채팅, 게임과 로직 등)을 200가지의 실무 예제를 통해 습득할 수 있도록 구성되어 있다. 예제는 파트별로 입문 21가지, 초급 52가지, 중급 59가지, 활용 39가지, 응용 18가지, 실무 11가지로 나누어져 있어 단계에 따라 실력을 향상시킬 수 있다. 또한 J2SE 5.0의 핵심 요약과 편리한 기능, 주요 코드문 등을 마지막 파트인 부록에서 일목요연하게 표로 정리하여 프로그래밍을 할 때에도 바로 찾아 쓸 수 있도록 하였다. - 문법 위주가 아닌 예제로 터득하는 자바 프로그래밍의 기본과 활용- 구체적인 그림을 통한 자바 메모리 구조와 객체지향 프로그래밍 완벽 설명- 로또,야구게임,카드놀이,채팅,개미퀴즈 등 재미있는 예제를 통한 프로그래밍 능력 향상

More Related