StudentGradeVersion2

StudentGradeVersion2 - //Read the first test score...

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

View Full Document Right Arrow Icon
//*************************************************************** // Author D.S. Malik // // Program to calculate the average test score. // Given a student's name and five test scores, this program // calculates the average test score. The student's name, the // five test scores, and the average test score is stored in the // file testavg.out. The data is input from the file test.txt. //*************************************************************** / import java.io.*; import java.util.*; i public class StudentGradeVersion2 { public static void main(String[] args) throws FileNotFoundException { //Declare and initialize variables double testScore; double sum = 0; String firstName; String lastName; Scanner inFile = new Scanner(new FileReader("test.txt")); S PrintWriter outFile = new PrintWriter("testavg.out"); firstName = inFile.next(); lastName = inFile.next(); l outFile.println("Student Name: " + firstName + " " + lastName); outFile.print("Test scores: "); testScore = inFile.nextDouble();
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: //Read the first test score outFile.printf(" %5.2f", testScore); //Output the test score sum = sum + testScore; //Update sum testScore = inFile.nextDouble(); //Read the second test score outFile.printf(" %5.2f", testScore); //Output the test score sum = sum + testScore; //Update sum testScore = inFile.nextDouble(); //Read the third test score outFile.printf(" %5.2f", testScore); //Output the test score sum = sum + testScore; //Update sum testScore = inFile.nextDouble(); //Read the fourth test score outFile.printf(" %5.2f", testScore); //Output the test score sum = sum + testScore; //Update sum testScore = inFile.nextDouble(); //Read the fifth test score outFile.printf(" %5.2f", testScore); //Output the test score sum = sum + testScore; //Update sum outFile.println(); outFile.printf("Average test score: %5.2f %n", sum / 5.0); //Output the average test score inFile.close(); outFile.close(); } }...
View Full Document

This note was uploaded on 06/17/2011 for the course COMP 2301 taught by Professor Staff during the Spring '10 term at Kennesaw.

Page1 / 2

StudentGradeVersion2 - //Read the first test score...

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