javaProject2 - } out.printf("The test average:...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.io.*; import java.util.*; public class Project2 { public static void main(String[] s) throws FileNotFoundException { Scanner in = null; PrintWriter out = null; String name; final int STUDENTS = 6; final int GRADES = 3; int[][] array = new int [STUDENTS][GRADES]; int sum1 = 0, sum2 = 0, sum3 = 0; try{ FileReader reader = new FileReader("gradeRoster.txt"); out = new PrintWriter("output.txt"); in = new Scanner(reader); out.printf(" Test1 Test2 Test3 Average%n"); for(int student= 0;student<STUDENTS;student++){ name = in.next(); out.print(name + "\t\t"); int sum = 0; for(int grade =0; grade<GRADES;grade++){ int number = in.nextInt(); out.print(number+ "\t"); sum += number; array[student][grade]=number; } out.println( sum / GRADES);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } out.printf("The test average: \t"); for(int student = 0; student<STUDENTS; student++){ sum1 += array[student][0]; sum2 += array[student][1]; sum3 += array[student][2]; } out.printf(sum1/ STUDENTS+"\t"); out.printf(sum2/ STUDENTS+"\t"); out.printf(sum3/ STUDENTS+"\t"); }catch(FileNotFoundException exception) { System.out.println("File not found."); }catch(InputMismatchException exception) { System.out.println("There are to many or to little numbers."); System.out.println("The file contains information incompatible with the reading format"); }catch(Exception exception) { exception.printStackTrace(); } finally{ if(in!= null) in.close(); if(out!=null) out.close(); } } }...
View Full Document

This note was uploaded on 04/17/2008 for the course CS 221 taught by Professor Drzhou during the Spring '08 term at Rhode Island College.

Page1 / 2

javaProject2 - } out.printf("The test average:...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online