Question

Java Gradebook

Requirements:

1.     The number of students to enter will be dynamic, minimum of 5.

2.     Ask the user for a student's:

a.     first name

b.     last name

c.      student ID

d.     4 exam grades (each out of 100 points)

Calculate the student's:

e.     final letter grade.

3.     For each student, if the user enters invalid data he will be allowed to enter it again.

4.     Letter grade calculation will use the standard grading scale.

a.     90% - 100% = A

b.     80% - 89% = B

c.      70% - 79% = C

d.     60% - 69% = D

e.     Below 60% = F

5.     The output will consist of:

a.     A list of students who passed (C or higher)

b.     A list of students who did not pass (D or lower)

c.      The person(s) with the highest grade (points, not letter)

 

Restrictions:

1.     main() will only consist of variable declarations, method calls, and small amounts of logic, if necessary.  The majority of the logic will reside in the core methods.

2.     The exam grades must be stored as an array, not 4 separate variables.

3.     User-defined methods must be used for data input, grade calculation, and data output, at a minimum.



OUTPUT:

 

-------------

PASS

----

Aberdeen, Joe        A

Blake, Kevin         A

Garry, Glen          C

Jenakovski, Mary     B

 

FAIL

----

Zoolander, Derek     F

 

HIGHEST GRADE

----

Blake, Kevin         A


0 0
Add a comment Improve this question Transcribed image text
Answer #1
// Importing Scanner class to take input.
import java.util.Scanner;
 
// StudentGrades  class starts.
class StudentGrades{
 
        // Instance variables for taking input and storing values.
        String firstName, lastName;
        int studentID;
        int examGrades[] = new int[4];
        char finalLetterGrade;
        float percentage = 0.0f;
         
        // inputDetails() methods to take input from the user.
        public void inputDetails(){
                // Instantiating Scanner class to take input.
                Scanner scanner = new Scanner(System.in);
 
                // Taking input of the First Name.
                System.out.print("Enter First Name : ");
                this.firstName = scanner.nextLine();
 
                // Taking input of the Last Name.
                System.out.print("Enter Last Name : ");
                this.lastName = scanner.nextLine();
 
                // Taking input of the Student ID.
                System.out.print("Enter Student ID : ");
                this.studentID = scanner.nextInt();
                 
                // Taking input of Grades of student in 4 exams.
                System.out.println("Enter Grades of 4 Exams (Out of 100) : ");
                 
                for(int i = 0; i < 4; i++ ){
                        System.out.print("Enter  Grade "+ (i+1) +" : ");
                        this.examGrades[i] = scanner.nextInt(); 
                }
        }
 
        // calculatePercentage() methods to calculate the obtained percentage of the student.
        public void  calculatePercentage(){
                //Calculating percentage.
                for(int i = 0; i < 4; i++ ){
                        this.percentage += this.examGrades[i];  
                }
 
                this.percentage = ( (percentage/400) * 100);
        }
 
        // calculateFinalLetterGrade() methods to calculate the obtained Final Letter Grade of the student.
        public void calculateFinalLetterGrade(){
 
                // Calculating Final Letter Grade and storing it into instance variable of the object.
                if(this.percentage >= 90 && this.percentage <= 100){
                        this.finalLetterGrade = 'A';
                }
                else if(this.percentage >= 80 && this.percentage <= 89){
                        this.finalLetterGrade = 'B';
                }
                else if(this.percentage >= 70 && this.percentage <= 79){
                        this.finalLetterGrade = 'C';
                }
                else if(this.percentage >= 60 && this.percentage <= 69){
                        this.finalLetterGrade = 'D';
                }
                else{
                        this.finalLetterGrade = 'F';
                }
        }
 
        // outputDetails() method to print the output according to Final Grade as mention in the question.
        public static void outputDetails(StudentGrades studentGrades[], int numberOfStudents){
 
                // Local Variable to get the Highest Grade.
                float highestGrade = studentGrades[0].percentage;
                int highestGradeIndex = 0;
 
                System.out.println("-------------------------------------------");
                // Printing details of all the passed students.
                System.out.println("\nPASS");
                System.out.println("----");
 
                for(int i = 0; i < numberOfStudents; i++){
                        if(studentGrades[i].percentage >= 70 ){
                                System.out.println(studentGrades[i].firstName +" "+ studentGrades[i].lastName +" "+ studentGrades[i].finalLetterGrade);
                        }
                }
 
                // Printing details of all the failed students.
                System.out.println("\nFAIL");
                System.out.println("----");
 
                for(int i = 0; i < numberOfStudents; i++){
                        if(studentGrades[i].finalLetterGrade == 'F' ){
                                System.out.println(studentGrades[i].firstName +" "+ studentGrades[i].lastName +" "+ studentGrades[i].finalLetterGrade);
                        }
                }
 
                // Printing details of students who obtained the highest Marks/Percentage or Points.
                System.out.println("\nHIGHEST GRADE");
                System.out.println("----");
 
                // Calculating which student obtained heighest marks.
                for(int i = 1; i < numberOfStudents; i++){
                        if( studentGrades[i].percentage > highestGrade ){
                                highestGrade = studentGrades[i].percentage;
                                highestGradeIndex = i;
                        }
                }
                // Printing the details of student who got Highest Marks.
                System.out.println(studentGrades[highestGradeIndex].firstName +" "+ studentGrades[highestGradeIndex].lastName +" "+ studentGrades[highestGradeIndex].finalLetterGrade);
 
                System.out.println("-------------------------------------------");
        }
 
        //main() method ot the driver method.
        public static void main(String[] args) {
                // Instantiating Scanner class to take input.
                Scanner scanner = new Scanner(System.in);
                // Variable for taking input of number of students.
                int numberOfStudents;
 
                // Taking student of number of Student.
                System.out.print("Enter the number of students (minimum 5) : ");
                numberOfStudents = scanner.nextInt();
 
                // Instantiating Array of StudentGrades class of size as entered by the user.
                StudentGrades studentGrades[] = new StudentGrades[numberOfStudents];
                 
                // Taking Input details, Calculating percentage  and Calculating the Grade for each student.
                for(int i = 0; i < numberOfStudents; i++ ){
                        System.out.println("\n\nEnter details of "+ (i+1) +" student : ");
 
                        //Instantiating StudentGrades object for every student.
                        studentGrades[i] = new StudentGrades();
                        //Calling inputDetails() method for taking input.
                        studentGrades[i].inputDetails();
 
                        //Calling calculatePercentage() method for calculating Percentage of student.
                        studentGrades[i].calculatePercentage();
 
                        //Calling calculateFinalLetterGrade() method for calculating Grade of student.
                        studentGrades[i].calculateFinalLetterGrade();
                }
 
                // Calling outputDetails() method for printing details of all the student as mentions in the question.
                outputDetails(studentGrades, numberOfStudents);
 
        // End of Main method.
        }
// StudentGrades  class Ends.
}


answered by: codegates
Add a comment
Know the answer?
Add Answer to:
Java Gradebook
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C Langage Write a grading program for a class with the following grading policies:- a. There are two quizzes, each gr...

    In C Langage Write a grading program for a class with the following grading policies:- a. There are two quizzes, each graded on the basis of 10 points. b. There is one midterm exam and one final exam, each graded on the basis of 100 points. c. The final exam counts for 50 percent of the grade, the midterm counts for 25 percent and the two quizzes together count for a total of 25 percent. Grading system is as follows:-...

  • Write a Java program that reads a file until the end of the file is encountered....

    Write a Java program that reads a file until the end of the file is encountered. The file consists of an unknown number of students' last names and their corresponding test scores. The scores should be integer values and be within the range of 0 to 100. The first line of the file is the number of tests taken by each student. You may assume the data on the file is valid. The program should display the student's name, average...

  • Java Program: In this project, you will write a program called GradeCalculator that will calculate the...

    Java Program: In this project, you will write a program called GradeCalculator that will calculate the grading statistics of a desired number of students. Your program should start out by prompting the user to enter the number of students in the classroom and the number of exam scores. Your program then prompts for each student’s name and the scores for each exam. The exam scores should be entered as a sequence of numbers separated by blank space. Your program will...

  • using C# Write a program which calculates student grades for multiple assignments as well as the...

    using C# Write a program which calculates student grades for multiple assignments as well as the per-assignment average. The user should first input the total number of assignments. Then, the user should enter the name of a student as well as a grade for each assignment. After entering the student the user should be asked to enter "Y" if there are more students to enter or "N" if there is not ("N" by default). The user should be able to...

  • A continuation of your grading software will be made (you do not need your other code...

    A continuation of your grading software will be made (you do not need your other code for this assignment). In this one you will intake a students first name and last name from a file called "students.txt". Next, there is a file called grades.txt that contains the grades in a course. There will be three grades for each student in "grades.txt" (see example file bellow). In "student.txt" there are two students first and last names. In "grades.txt" the grades for...

  • First, create two inputs that can be stored in variables consisting of a student's name. When...

    First, create two inputs that can be stored in variables consisting of a student's name. When the program begins ask "Who is the first student?" followed by "Who is the second student?" You only have to have two students for this program. Ask the user for the scores for the last three test grades for each of the students .   After the user has entered both names, and three scores for each, the program should display the following as output:...

  • C++ Language A continuation of your grading software will be made you do not need your...

    C++ Language A continuation of your grading software will be made you do not need your other code for this assignment). In this one you will intake a students first name and last name from a file called "students.txt". Next, there is a file called grades.txt that contains the grades in a course. There will be three grades for each student in "grades.txt" (see example file bellow). In "student.txt" there are two students first and last names. In "grades.txt" the...

  • The professor of a introductory calculus class has stated that, historically, the distribution of final exam...

    The professor of a introductory calculus class has stated that, historically, the distribution of final exam grades in the course resemble a Normal distribution with a mean final exam mark of μ=63μ=63% and a standard deviation of σ=9σ=9%. If using/finding zz-values, use three decimals. (a) What is the probability that a random chosen final exam mark in this course will be at least 73%? Answer to four decimals. (b) In order to pass this course, a student must have a...

  • This code should be written in php. Write a program that allows the user to input...

    This code should be written in php. Write a program that allows the user to input a student's last name, along with that student's grades in English, History, Math, Science, and Geography. When the user submits this information, store it in an associative array, like this: Smith=61 67 75 80 72 where the key is the student's last name, and the grades are combined into a single space-delimited string. Return the user back to the data entry screen, to allow...

  • IN JAVA WITH COMMENTS, The assignment: This program inputs the names of 5 students and the...

    IN JAVA WITH COMMENTS, The assignment: This program inputs the names of 5 students and the (integer) grades they earned in 3 tests. It then outputs the average grade for each student. It also outputs the highest grade a student earned in each test, and the average of all grades in each test. Your output should look like this: Mary's average grade was 78.8% Harry's average grade was 67.7% etc... : In test 1 the highest grade was 93% and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT