Question

In: Computer Science

LAB3 YearGradeBook A teacher has 5 students who each will have 4 marking period scores. The...

LAB3

YearGradeBook

A teacher has 5 students who each will have 4 marking period scores. The teacher uses the following grading scale to assign a year end letter grade to a student, based on the average of his or her 4 marking period scores.

Marking Period Score                         Letter Grade

92-100                                                 A
83-91                                                   B
74-82                                                   C
65-73                                                   D
0-64                                                     F

Write a class that uses a String array or an ArrayList object to hold the students’ names, an array of five characters to hold the five student’s letter grades, and five arrays of four doubles each to hold each student’s set of marking period scores. You may find using a single 5x4 multi-dimensional array easier to manage instead of a separate array for each set of marking period scores.

The class should have methods that return a specific student’s name, the year end score (average marking period score), and a letter grade based on the average. Although averages are often floating-point values, you should cast the year end score (average marking period score) to an integer when comparing with the grading scale. This reduces the possibility of error. Demonstrate the class in a program that allow the user to enter each student’s name and his or her four marking period scores. It should then display each student’s year end score and letter grade.

Input Validation: Do not accept marking period score less than zero or greater than 100.

Refer to “GradeBook solution.docx” for examples of how to complete this lab.

Your submission to BB should be your “YearGradeBook.java” file only, not included in a .zip file or a .gpj file.

the starting code is below

import java.util.Scanner;

public class GradeBook {

    String[] studentNames;

    char[] letterGrades;

    double[][] testGrades;

    public GradeBook() {

        studentNames = new String[5];

        letterGrades = new char[5];

        testGrades = new double[5][4];

        return;

    }

    public String getStudentName(int number) {

        if ((number >= 1) && (number <= 5))

            return studentNames[number - 1];

        return null;

    }

    public double getAvgTestScore(int number) {

        if ((number >= 1) && (number <= 5)) {

            int sum = 0;

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

                sum += testGrades[number - 1][i];

            return (sum / 4.0);

        }

        return -1.0;

    }

    public char getLetterGrade(double avgScore) {

        int avg = (int) avgScore;

        if ((avg >= 90) && (avg <= 100))

            return 'A';

        else if ((avg >= 80) && (avg <= 89))

            return 'B';

        else if ((avg >= 70) && (avg <= 79))

            return 'C';

        else if ((avg >= 60) && (avg <= 69))

            return 'D';

        else return 'F';

    }

    public static void main(String[] args) {

        GradeBook record = new GradeBook();

        Scanner input = new Scanner(System.in);

        int score;

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

            System.out.printf("Enter student %d name: ", i);

            record.studentNames[i - 1] = input.nextLine();

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

                while (true) {

                    System.out.printf("Enter student %s's"

                            + " grade for test %d: ",

                            record.studentNames[i - 1], j);

                    score = input.nextInt();

                    input.nextLine();

                    if ((score >= 0) && (score <= 100)) {

                        record.testGrades[i - 1][j - 1] = score;

                        break;

                    }

                    System.out.printf("Score cannot be less than 0"

                            + " or greater than 100!"

                            + " Please try again.%n");

                }

            }

        }

        double avg;

        System.out.printf("%n=== Grade Book Data ===%n%n");

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

            avg = record.getAvgTestScore(i);

            System.out.printf("Student name: %s%n"

                    +"\tAverage test score: %.2f%n"

                    + "\tLetter grade: %c%n= = = = =%n",

                    record.getStudentName(i),

                    avg, record.getLetterGrade(avg));

        }

        return;

    }

}

Solutions

Expert Solution

Code

import java.util.Scanner;
public class GradeBook
{
String[] studentNames;
char[] letterGrades;
double[][] testGrades;
public GradeBook() {
studentNames = new String[5];
letterGrades = new char[5];
testGrades = new double[5][4];
}
public String getStudentName(int number) {
if ((number >= 1) && (number <= 5))
return studentNames[number - 1];
return null;
}
public double getAvgTestScore(int number)
{
if ((number >= 1) && (number <= 5)) {
int sum = 0;
for (int i = 0; i < 4; i++)
sum += testGrades[number - 1][i];
return (sum / 4.0);
}
return -1.0;
}
public char getLetterGrade(double avgScore) {
int avg = (int) avgScore;
if ((avg >= 90) && (avg <= 100))
return 'A';
else if ((avg >= 80) && (avg <= 89))
return 'B';
else if ((avg >= 70) && (avg <= 79))
return 'C';
else if ((avg >= 60) && (avg <= 69))
return 'D';
else return 'F';
}
public static void main(String[] args)
{
GradeBook record = new GradeBook();
Scanner input = new Scanner(System.in);
int score;
for (int i = 1; i <= 5; i++)
{
System.out.printf("Enter student %d name: ", i);
record.studentNames[i - 1] = input.nextLine();
for (int j = 1; j <= 4; j++)
{
while (true)
{
System.out.printf("Enter student %s's"+ " grade for test %d: ",record.studentNames[i - 1], j);
score = input.nextInt();
input.nextLine();
if ((score >= 0) && (score <= 100))
{
record.testGrades[i - 1][j - 1] = score;
break;
}
System.out.printf("Score cannot be less than 0 or greater than 100! Please try again.%n");
}
}
}
double avg;
System.out.printf("%n=== Grade Book Data ===%n%n");
for (int i = 1; i <= 5; i++)
{
avg = record.getAvgTestScore(i);
System.out.printf("Student name: %s%n"
+"\tAverage test score: %.2f%n"
+ "\tLetter grade: %c%n= = = = =%n",
record.getStudentName(i),
avg, record.getLetterGrade(avg));
}
}
}

output

your program is running well ..

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.


Related Solutions

A teacher has five students who have taken four tests. The teacher uses the following grading...
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 test scores. -------------------------------------------------------------------- Test Score Letter Grade -------------------------------------------------------------------- 90 – 100 A >= 80 < 90 B >= 70 < 80 C >= 60 < 70 D < 60 F ------------------------------------------------------------------- Write a program that uses Python List of strings to hold the five student names,...
You are a fifth-grade teacher and have just given your students a spelling test. Their scores...
You are a fifth-grade teacher and have just given your students a spelling test. Their scores on the test are as follows: 100, 98,25,30, 100, 100, 20, 100, 100, 99, 97, 96, 20. Calculate the mean for these scores. Do you think it reflects the scores adequately? Explain your answer. Calculate means, medians, and modes for the following 2 sets of scores: Set 1: 100, 20, 100, 98, 100, 99, 100, 100 Set 2: 100, 100, 20 Based on your...
A) Quiz scores of statistics students were obtained by a teacher and listed below. Construct a...
A) Quiz scores of statistics students were obtained by a teacher and listed below. Construct a frequency distribution beginning with a lower class limit of 0 and use a class width of 2. What frequency is listed for the third class? 0, 4, 5, 4, 3, 6, 8,2, 4, 10 B) A frequency table of grades has five classes (A, B, C, D, F) with frequencies of 23, 24, 12, 7, and 24 respectively. Using percentages, what are the relative...
Question 5 (1 point) A high school math teacher believes that male and female students who...
Question 5 (1 point) A high school math teacher believes that male and female students who graduated from the school perform equally well on SAT math test. She randomly chooses 10 male students and 10 female students who graduated from this school. The following are the SAT math scores of the 20 students: Male: 23, 30, 27, 29, 22, 34, 36, 28, 28, 31 Female: 22, 33, 30, 28, 28, 31, 34, 25, 29, 21 Test the teacher's claim. What...
1. As a teacher, you have some students who clearly want to learn the subject matter...
1. As a teacher, you have some students who clearly want to learn the subject matter you are teaching and other students who are interested only in the grades they get in your class. a. Considering the textbook’s discussion of extrinsic versus intrinsic motivation, how would you expect the two groups of students to differ in terms of classroom learning and performance? Describe five differences you are likely to see between them. b. Describe three strategies you might use to...
the following are the scores of 25 students who participated in a psychology experiment. The scores...
the following are the scores of 25 students who participated in a psychology experiment. The scores represent the number of trials required to complete a memorization test. 12, 10, 12, 11, 6, 15, 14, 17, 9, 12, 13, 8, 7, 15, 14, 15, 18, 19, 14, 10, 14, 14, 16, 8, 9 Based on these data, the z score for generated for a person with a raw score of 6 is___ and their percentile is___
4. A teacher believes that whatever he says in class has no effect on his students....
4. A teacher believes that whatever he says in class has no effect on his students. Just as he's about to quit his profession, a statistician enters the room and suggests that the teacher design a study to test his assumption. The study will look at whether providing in-class feedback on homework assignments enhances classroom performance. The teacher wants to know whether providing feedback before or after returning the assignments is most useful. He's also interested in the most effective...
What is the variance for the following population of scores? Scores: 5, 2, 5, 4
What is the variance for the following population of scores? Scores: 5, 2, 5, 4
A group of students takes a 10 point quiz. You have the scores for each student...
A group of students takes a 10 point quiz. You have the scores for each student and decide to calculate the correlation between (a) the number of correct answers on the quiz with (b) the number of incorrect answers on the quiz. A. What would r equal? If you’re stuck, think about this a bit. If you’re really stuck, it may help to make a scatterplot based 10 students getting various scores on the quiz. _________________ (1 point) B. How...
A teacher has students and IF she assigns 2 people per table, she needs 4 more...
A teacher has students and IF she assigns 2 people per table, she needs 4 more lab tables. If she assigns 4 per table she needs 4 more tables ... How many students are there?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT