2014-03-12 2 views
1

성적표를 인쇄 할 때 내 성적 책 프로그램 (성적을 입력하고 평균을 찾음)이 제대로 작동하지 않습니다. 학생 1과 헤더 인쇄물의 평균과 학생 1의 평균값은 시험 성적이없는 0입니다. 여기 내 성적표 프로그램이 제대로 문서를 인쇄하지 못합니다.

내 코드입니다 : 내가 뭘 잘못

import java.io.FileInputStream; 
import java.io.FileOutputStream; 
import java.io.IOException; 
import java.text.DecimalFormat; 
import org.apache.poi.hssf.usermodel.HSSFSheet; 
import org.apache.poi.hssf.usermodel.HSSFWorkbook; 
import org.apache.poi.ss.usermodel.Cell; 
import org.apache.poi.ss.usermodel.Row; 

public class array { 


public static final String Dabook = "wording.xls"; 



@SuppressWarnings("unused") 
public static void main(String[] args) throws IOException { 

HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream("wording.xls")); 
HSSFSheet sheet = wb.getSheet("Sheet1"); 

    int col = 0, num = 1; 
    Row startRow = sheet.createRow(0); 
    Cell startCell = startRow.createCell(0); 
    int cellNumber = 0; 
    double total = 0; 

    double [ ] [ ] gridGrades = 
     { { 87.5, 61.0, 70.5 }, 
      { 90.0, 88.5, 87.5 }, 
      { 78.0, 65.5, 70.5 }, 
      { 80.0, 79.0, 81.5 }, 
      { 60.5, 55.5, 50.0 } }; 
    for (int colTest = 0; colTest < gridGrades[colTest].length + 1; colTest++) { 
     for (int testNum = 0; testNum < gridGrades[colTest].length + 1;testNum++) { 

      if (testNum == 1) { 
       startCell.setCellValue(""); 
      } 
     if (testNum == gridGrades[0].length) { 
      startCell = startRow.createCell(testNum + 1); 
      startCell.setCellValue("Average"); 
      startCell = startRow.createCell(testNum + 2); 

     } 
    } 
    } 
for (double grade[] : gridGrades) { 
    startRow = sheet.createRow(num); 
    startCell = startRow.createCell(cellNumber); 
    startCell.setCellValue("Student " + num); 

    for (int poop = 0; poop < gridGrades[num - 1].length; poop++) { 
     if (poop == gridGrades[0].length - 1) { 
      double average = total/gridGrades[num - 1].length; 

      startCell = startRow.createCell(poop + 2); 
      DecimalFormat df = new DecimalFormat("###.##"); 
      Double averageDouble = Double.parseDouble(df 
        .format(average)); 
      startCell.setCellValue(averageDouble); 
      startCell = startRow.createCell(poop + 3); 

      total = 0; 
     } 
     for (int Scott = 0; startRow.getCell(Scott) != null; Scott++) { 
      sheet.autoSizeColumn(Scott); 
     } 

     FileOutputStream output = new FileOutputStream("wording.xls"); 
     wb.write(output); 
     output.close(); 
    } 

} 
{  
     System.out.printf("     Test %d:  Test %d: Test %d: Average:%n", num, num+1, num+2); 
    for(double[] grade : gridGrades) { 
     double average = (grade[col] + grade[col+1] + grade[col+2])/3; 
    System.out.printf("Student %d   %.2f  %.2f  %.2f  %.2f %n", num, grade[col], grade[col+1], grade[col+2], average); 
    num++; 


    } 
} 

} }

?

+0

어떤 오류가 있습니까? – user902383

+0

당신은 그것이 어떻게 생겼는지와 실제로 어떻게 생겼는지에 대한 예를 보여줄 필요가 있습니다. –

+0

@ user902383 유일한 오류는 스프레드 시트를 인쇄하기 위해 인쇄하지 않는다는 것입니다. – Scott

답변

0
  • 쓰기 블록을 루프 밖으로 배치하면 한 번만 작성하면됩니다.
  • @ user902383은 아웃 루프에서 num++ 문이 필요하다고 말했습니다.
  • 셀에 성적을 설정하지 않고 "test N"헤더를 설정하지 마십시오.
  • 셀에서 등급을 설정할 때 @ user902383으로이 값을 total에 추가하십시오.

희망이 도움이됩니다.

관련 문제