Create a Java application with generated comments to simulat

Create a Java application (with generated comments) to simulate a “GradeBook”. A teacher has five students who have taken four exams. The teacher uses the following grading scale to assign a letter grade to a student, based on the average of his or her four exam scores:

Average

Letter Grade

90 – 100

A

80 – 89

B

70 – 79

C

60 – 60

D

0 – 59

F

Write logic to create a String array to hold student names, a character array to hold student letter grades, and a two-dimensional array to hold each of the five students’ test scores for each of the four exams completed during the semester.

Use nested for loop logic to fill the names and test scores arrays. Do not accept test scores less than zero or greater than 100. Make sure you test both ends of the range!

Use another nested for loop to compute the average test score for each student and then assign the corresponding letter the letter grade array. Make sure you test each letter grade value!

Use while loop logic to display each student’s name and letter grade in tabular fashion.

Average

Letter Grade

90 – 100

A

80 – 89

B

70 – 79

C

60 – 60

D

0 – 59

F

Solution

Code

import java.util.Scanner;

public class StudentGrades {

   public static void main(String[] args) {

       String[] students = new String[5];

       char[] grades = new char[5];

       int[][] marks = new int[5][4];

       Scanner in = new Scanner(System.in);

       for (int i = 0; i < 5; i++) {

           // to take student name from user

           System.out.println(\"Enter student name\");

           students[i] = in.next();

           int sum = 0;

           // for loop to take input for marks for each student

           for (int j = 0; j < 4; j++) {

               System.out.println(\"Enter marks for \" + students[i] + \" for test\" + (j + 1));

               marks[i][j] = in.nextInt();

               // while loop to to take only valid input

               while (marks[i][j] < 0 || marks[i][j] > 100) {

                   System.out.println(\"Invalid marks! marks should be >=0 and <=100\");

                   marks[i][j] = in.nextInt();

               }

               // to sum all marks

               sum += marks[i][j];

           }

           // to calculate average marks

           int avg = sum / 4;

           // System.out.println(\"Average score is \" + avg);

           // grading based on marks

           if (avg >= 90)

               grades[i] = \'A\';

           else if (avg >= 80)

               grades[i] = \'B\';

           else if (avg >= 70)

               grades[i] = \'C\';

           else if (avg >= 60)

               grades[i] = \'D\';

           else

               grades[i] = \'E\';

       }

       // to print student name and respective grade

       System.out.println(\"Student Name\\tgrades\");

       for (int i = 0; i < 5; i++)

           System.out.println(students[i] + \"\\t\\t\\t\" + grades[i]);

   }

}

Sample output

Enter student name

akhila

Enter marks for akhila for test1

100

Enter marks for akhila for test2

98

Enter marks for akhila for test3

95

Enter marks for akhila for test4

96

Enter student name

anusha

Enter marks for anusha for test1

34

Enter marks for anusha for test2

59

Enter marks for anusha for test3

98

Enter marks for anusha for test4

87

Enter student name

kalyani

Enter marks for kalyani for test1

70

Enter marks for kalyani for test2

69

Enter marks for kalyani for test3

89

Enter marks for kalyani for test4

93

Enter student name

sindhu

Enter marks for sindhu for test1

12

Enter marks for sindhu for test2

93

Enter marks for sindhu for test3

23423

Invalid marks! marks should be >=0 and <=100

234

Invalid marks! marks should be >=0 and <=100

120

Invalid marks! marks should be >=0 and <=100

98

Enter marks for sindhu for test4

65

Enter student name

smruthi

Enter marks for smruthi for test1

56

Enter marks for smruthi for test2

86

Enter marks for smruthi for test3

98

Enter marks for smruthi for test4

56

Student Name   grades

akhila           A

anusha           D

kalyani           B

sindhu           D

smruthi           C

Create a Java application (with generated comments) to simulate a “GradeBook”. A teacher has five students who have taken four exams. The teacher uses the follo
Create a Java application (with generated comments) to simulate a “GradeBook”. A teacher has five students who have taken four exams. The teacher uses the follo
Create a Java application (with generated comments) to simulate a “GradeBook”. A teacher has five students who have taken four exams. The teacher uses the follo
Create a Java application (with generated comments) to simulate a “GradeBook”. A teacher has five students who have taken four exams. The teacher uses the follo
Create a Java application (with generated comments) to simulate a “GradeBook”. A teacher has five students who have taken four exams. The teacher uses the follo

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site