StudentGrade

StudentGrade - /Step 2 PrintWriter outFile = new...

Info iconThis preview shows page 1. 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 StudentGrade { public static void main(String[] args) throws FileNotFoundException { //declare and initialize the variables //Step 1 double test1, test2, test3, test4, test5; double average; String firstName; String lastName; Scanner inFile = new Scanner(new FileReader("test.txt"));
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: //Step 2 PrintWriter outFile = new PrintWriter("testavg.out"); //Step 3 firstName = inFile.next(); //Step 4 lastName = inFile.next(); //Step 4 outFile.println("Student Name: " + firstName + " " + lastName); //Step 5 //Step 6 - retrieve the five test scores test1 = inFile.nextDouble(); test2 = inFile.nextDouble(); test3 = inFile.nextDouble(); test4 = inFile.nextDouble(); test5 = inFile.nextDouble(); outFile.printf("Test scores: %5.2f %5.2f %5.2f " + "%5.2f %5.2f %n", test1, test2, test3, test4, test5); //Step 7 average = (test1 + test2 + test3 + test4 + test5) / 5.0; //Step 8 outFile.printf("Average test score: %5.2f %n", average); //Step 9 inFile.close(); //Step 10 outFile.close(); //Step 10 } }...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online