Java Reference
In-Depth Information
In the preceding sections, we analyzed the problem and determined the formulas to
perform the calculations. We also determined the necessary variables. Now we can
expand the algorithm given in the Problem Analysis and Algorithm Design section
to solve the Student Grade problem given at the beginning of this programming
example.
1. Declare the variables.
2. Create a Scanner object and associate it with the input source.
3. Create a PrintWriter object and associate it with the output
source.
4. Get the student's first name and last name.
5. Output the student's first name and last name.
6. Read the five test scores.
7. Output the five test scores.
8. Find the average test score.
9. Output the average test score.
10. Close the files.
This program reads the data from a file and outputs the data to a file, so it must
import the necessary classes from the package s java.io and java.util .
MAIN
ALGORITHM
3
COMPLETE PROGRAM LISTING
//***************************************************************
// 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.*;
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;
Search WWH ::




Custom Search