오랜만에 올려보는 과제 코딩 일기~
그동안은 수업시간에 새로 배우는 내용들을 응용해서 구구단, 로또번호 생성, 주민번호 체크 이렇게 세가지 내용을 반복적으로 만들어 왔었는데, 오늘은 새롭게 Referenced API 로 jexcel API 를 사용해보았다.
과제로 내어진 문제는 회차별 로또 당첨 기록 excel 데이터를 이용해서, 각 번호가 여태 얼마나 당첨되었었는지 출력하는 프로그램을 짜는게 과제였다.
참고자료 사이트는
package ex03;
import java.io.File;
import java.io.IOException;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class LottoExcelEx01 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Workbook workbook = null;
try {
workbook = Workbook.getWorkbook(new File("./lotto(1~962).xls"));
Sheet sheet = workbook.getSheet(0);
int totalRow = sheet.getRows();
int num = 1;
int countNum = 0;
while (num <46) {
for (int x=13; x<20; x++) {
for (int y=3; y<totalRow; y++) {
Cell cell = sheet.getCell(x,y);
int contents = Integer.parseInt(cell.getContents());
if (contents == num) {
countNum++;
}
}
}
System.out.printf("%d 번 누적 당첨수: %d 회\n",num,countNum);
countNum = 0;
num ++;
}
} catch (BiffException e) {
// TODO Auto-generated catch block
System.out.println("에러 : "+e.getMessage());
} catch (IndexOutOfBoundsException e) {
// TODO Auto-generated catch block
System.out.println("에러 : "+e.getMessage());
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("에러 : "+e.getMessage());
} finally {
if (workbook != null) try { workbook.close();} catch (Exception e) {}
}
}
}
음... 행열 개념이 갑자기 훅 헷갈리면서 한참 혼동했었는데, (x,y) 좌표라 생각하니 편-안
일단 이 코드는 아직 한번 더 정리해보지 못했기 때문에!!!
우선은 기록으로 남기고 공부부터 하러 총총
풍마 버전 추가 예정 ToBeContinued...