자바로 구현한 사칙연산 입출력 프로그램
본 자료는 7페이지 의 미리보기를 제공합니다. 이미지를 클릭하여 주세요.
닫기
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
해당 자료는 7페이지 까지만 미리보기를 제공합니다.
7페이지 이후부터 다운로드 후 확인할 수 있습니다.

소개글

자바로 구현한 사칙연산 입출력 프로그램에 대한 보고서 자료입니다.

목차

1. 프로그램 명세
2. 소스코드
3. 출력결과

본문내용

no=0;no for(int i=0;i Cell myCell = mySheet2.getCell(i,no); // 셀의 행과 열의 정보를 가져온 후...
mystring2=myCell.getContents();
if(mystring2.equals(\"\")){ //공백이라면 브레이크문실행
break;
}
mystring+=\" \"+mystring2;
}
Label dataLabels = new Label(0,no,mystring,dataFormat);
mySheet.addCell(dataLabels);
mystring=\"\";
dataLabels = new Label(1,no,\"->\",dataFormat);
mySheet.addCell(dataLabels);
} //첫번째 두번째 열 공간을 채움.
for(int no=0;no for(int i=0;i if(i==0){
Cell myCell = mySheet2.getCell(i,no);//i번째열의 no행의 정 보를 받음
operation=myCell.getContents(); //operation 어떤 연산자인지 받아옴
math=temp(operation);
}
else{
//숫자의 수와 연산의 결과와 integer exception의 수를 구함
Cell myCell = mySheet2.getCell(i,no);
calculation=myCell.getContents()+\" \";//NULL문자의 비교를 위해 공백을 더해줌
if(calculation.charAt(0)>=48&&calculation.charAt(0)<58){
count+=1;
total=sum(math,total,i,calculation);//열을 순 서대로 돌면서 계산결 과를 수행함
if(math==0)//전체 계산 문자열을 구하기 위한 조건문//더하기 연산이라면
{
if(i==1)//첫번째 연산이라면
totalcalculation+=calculation;
else
totalcalculation+=\"+\"+\" \"+calculation;
}
else if(math==1) //빼기 연산이라면
{
if(i==1)//첫번째 연산이라면
totalcalculation+=calculation;
else
totalcalculation+=\"-\"+\" \"+calculation;
}
else if(math==2) //곱하기 연산이라면
{
if(i==1)//첫번째 연산이라면
totalcalculation+=calculation;
else
totalcalculation+=\"*\"+\" \"+calculation;
}
else if(math==3)
{
if(i==1)//첫번째 연산이라면
totalcalculation+=calculation;
else
totalcalculation+=\"/\"+\" \"+calculation;
}
else if(math==4)
{
totalcalculation+=\" \";
}
}
else if(calculation.compareTo(\" \")!=0)//공백이 아니 고 숫자도 아니라면
integer+=1;
}
}
totalcalculation+=\"=\"+\" \"+Integer.toString(total);// \'=\'전체 결과까지 문자열로 저장
if(math!=4)//command에러가 아닐경우에만 엑셀파일에 저장
{
Label dataLabels = new Label(2,no,totalcalculation,dataFormat);
mySheet.addCell(dataLabels);
dataLabels = new Label(3,no,Integer.toString(integer)+\"integer exception\",dataFormat);
mySheet.addCell(dataLabels);
}
else //command에러일 경우
{
Label dataLabels = new Label(3,no,\"command exception\",dataFormat);
mySheet.addCell(dataLabels);
}
integer=0;//예외의 값을 초기화
totalcalculation=\"\";
total=0;//한번의 행을 돌아가서 계산했으므로 0으로 초기화
}
myWorkbook.write(); // 준비된 정보를 엑셀 포멧에 맞게 작성
myWorkbook.close(); // 처리 후 메모리에서 해제 처리
//myWorkbook2.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (WriteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (BiffException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
int temp(String operation) //어떤 연산인지 확인하는 함수
{
if(operation.equals(\"ADD\")){//더하기 일경우
return 0;
}
else if(operation.equals(\"SUB\")){//빼기 일경우
return 1;
}
else if(operation.equals(\"MUL\")){//곱셈일 경우
return 2;
}
else if(operation.equals(\"DIV\")){//나누기일 경우
return 3;
}
else{//command에러일 경우
return 4;
}
}
int sum(int math,int total,int i,String figure){//연산결과를 리턴하는 함수
StringTokenizer st = new StringTokenizer(figure,\" \");
figure=st.nextToken();
if(math==0)//더하기라면
{
total+=Integer.parseInt(figure);//더해야 할 수를 더함
return total; //더한 결과를 리턴
}
else if(math==1)//
  • 가격3,000
  • 페이지수20페이지
  • 등록일2020.12.08
  • 저작시기2015.3
  • 파일형식한글(hwp)
  • 자료번호#1141705
본 자료는 최근 2주간 다운받은 회원이 없습니다.
다운로드 장바구니