Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

IMPORTANT NOTE: ***** This program must be altered so that all info is read in f

ID: 3540747 • Letter: I

Question

IMPORTANT NOTE:
***** This program must be altered so that all info is read in from a text file to java*****


A teacher has five students who have taken four tests/ The teacher uses the following grading scale

to assign a letter grade to a student, based on the average of his or her four tests:


90-100  A
80-99    B
70-79    C
60-69    D
0-59      F


Write a class that uses a String array (or an ArrayList object) to hold the five students' names, an array

of five characters to hold the five students' letter grades, and five arrays of four doubles each to hold

each student's set of test scores.  The class should have methods that return STUDENT'S NAMES, a

AVERAGE TEST SCORE, and a LETTER GRADE based on the average.


The text file that will be read in will look like this:

Joanne Smith

98

89

100

76

Will Jones

67

89

91

88

Kerry McDonald

78

79

88

91

Sam Young

88

98

76

56

Jill Barnes

94

93

91

98

Here is the SAMPLE OUTPUT I was provided:


Name:  Joanne Smith       Average Score:  90.75       Grade:  A
Name:  Will Jones             Average Score:  83.75       Grade:  B

Name:  Kerry McDonald  Average Score:  84.0          Grade:  B

Name:  Same Young        Average Score:  79.5         Grade:  C

Name:  Jill Barnes             Average Score:  94.0         Grade:  A


A teacher has five students who have taken four tests/ The teacher uses the following grading scale to assign a letter grade to a student, based on the average of his or her four tests: Write a class that uses a String array (or an ArrayList object) to hold the five students' names, an array of five characters to hold the five students' letter grades, and five arrays of four doubles each to hold each student's set of test scores. The class should have methods that return STUDENT'S NAMES, a AVERAGE TEST SCORE, and a LETTER GRADE based on the average. The text file that will be read in will look like this: Joanne Smith Will Jones Kerry McDonald Sam Young Jill Barnes

Explanation / Answer

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package webcrawling;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;

/**
*
* @author ASHOK RAAVI
*/
public class StudentGrade {
    ArrayList<String> studentNames=new ArrayList<String>();
    ArrayList<String> studentGrades = new ArrayList<String>();
    ArrayList<Double> averageScore=new ArrayList<Double>();
    ArrayList<Integer> student1=new ArrayList<Integer>();
    ArrayList<Integer> student2=new ArrayList<Integer>();
    ArrayList<Integer> student3=new ArrayList<Integer>();
    ArrayList<Integer> student4=new ArrayList<Integer>();
    ArrayList<Integer> student5=new ArrayList<Integer>();
   
    public static void main(String args[]) throws FileNotFoundException
    {
        StudentGrade sg=new StudentGrade();
        Scanner sc = new Scanner(new File("student.txt"));
        int loop=1;
        while (sc.hasNextLine()) {
           
            try{
                if(loop==1 || loop==6||loop==11||loop==16||loop==21)
                {
                    String value=sc.nextLine();
                    sg.studentNames.add(value);
                }
                else{   
               
               
                if(loop<=5)
                {
                    Integer marks = Integer.parseInt(sc.nextLine());
                    sg.student1.add(marks);
                }
                else if(loop<=11)
                {
                    Integer marks = Integer.parseInt(sc.nextLine());
                    sg.student2.add(marks);
                }
                else if(loop<=16)
                {
                    Integer marks = Integer.parseInt(sc.nextLine());
                    sg.student3.add(marks);
                }
                else if(loop<=21)
                {
                    Integer marks = Integer.parseInt(sc.nextLine());
                    sg.student4.add(marks);
                }
                else
                {
                    Integer marks = Integer.parseInt(sc.nextLine());
                    sg.student5.add(marks);
                }
                }
                loop++;
            }
           
            catch(Exception ex){
             ex.printStackTrace();
            }
        }
        sg.letterGrade();
        for(int i=0;i<5;i++)
        {
            System.out.println("Name: "+sg.studentNames.get(i)+" Average score:"+sg.averageScore.get(i)+"   Grade:"+sg.studentGrades.get(i));
        }
       
    }
   
    double averageTestScore(ArrayList<Integer> student)
    {
        double sum1=0.0,sum2=0.0,sum3=0.0,sum4=0.0,sum5=0.0;
        for(int i=0;i<4;i++)
        {
            sum1=sum1+student.get(i);
           
        }
        averageScore.add(sum1/4.0);
        return sum1/(4.0);
    }
    void letterGrade()
    {
        if(averageTestScore(student1)>=90)
        {
            studentGrades.add("A");
        }
        else if(averageTestScore(student1)>=80 && averageTestScore(student1)<=89)
        {
            studentGrades.add("B");
        }
        else if(averageTestScore(student1)>=70 && averageTestScore(student1)<=79)
        {
            studentGrades.add("C");
        }
        else if(averageTestScore(student1)>=60 && averageTestScore(student1)<=69)
        {
            studentGrades.add("D");
        }
        else
        {
            studentGrades.add("E");
        }
        if(averageTestScore(student2)>=90)
        {
            studentGrades.add("A");
        }
        else if(averageTestScore(student2)>=80 && averageTestScore(student2)<=89)
        {
            studentGrades.add("B");
        }
        else if(averageTestScore(student2)>=70 && averageTestScore(student2)<=79)
        {
            studentGrades.add("C");
        }
        else if(averageTestScore(student2)>=60 && averageTestScore(student1)<=69)
        {
            studentGrades.add("D");
        }
        else
        {
            studentGrades.add("E");
        }
        if(averageTestScore(student3)>=90)
        {
            studentGrades.add("A");
        }
        else if(averageTestScore(student3)>=80 && averageTestScore(student3)<=89)
        {
            studentGrades.add("B");
        }
        else if(averageTestScore(student3)>=70 && averageTestScore(student3)<=79)
        {
            studentGrades.add("C");
        }
        else if(averageTestScore(student3)>=60 && averageTestScore(student3)<=69)
        {
            studentGrades.add("D");
        }
        else
        {
            studentGrades.add("E");
        }
        if(averageTestScore(student4)>=90)
        {
            studentGrades.add("A");
        }
        else if(averageTestScore(student4)>=80 && averageTestScore(student4)<=89)
        {
            studentGrades.add("B");
        }
        else if(averageTestScore(student4)>=70 && averageTestScore(student4)<=79)
        {
            studentGrades.add("C");
        }
        else if(averageTestScore(student4)>=60 && averageTestScore(student4)<=69)
        {
            studentGrades.add("D");
        }
        else
        {
            studentGrades.add("E");
        }
        if(averageTestScore(student5)>=90)
        {
            studentGrades.add("A");
        }
        else if(averageTestScore(student5)>=80 && averageTestScore(student5)<=89)
        {
            studentGrades.add("B");
        }
        else if(averageTestScore(student2)>=70 && averageTestScore(student5)<=79)
        {
            studentGrades.add("C");
        }
        else if(averageTestScore(student5)>=60 && averageTestScore(student5)<=69)
        {
            studentGrades.add("D");
        }
        else
        {
            studentGrades.add("E");
        }
    }
}