0% found this document useful (0 votes)
19 views5 pages

Exercises Making Guide

Uploaded by

tamboalexandra8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views5 pages

Exercises Making Guide

Uploaded by

tamboalexandra8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Exercise: Student Grading System

Objective:

In this exercise, you will develop a program to calculate the grade of students based on their exam
scores. The program will use algorithms with conditional statements, loops, and Java's Collections
Framework to store and process student data efficiently.

Problem Description:

You need to implement a grading system that will take input from a list of student names and their
corresponding exam scores. Based on the score, the program will assign a grade to each student and
print out the results.

• Grading Scale:

o A: 90 and above

o B: 80-89

o C: 70-79

o D: 60-69

o F: Below 60

Requirements:

1. Input: A list of student names and their exam scores.

2. Processing:

o Iterate over the list of students.

o For each student, use a conditional statement to determine their grade based on
their score.

o Store the grades in a collection (e.g., HashMap<String, String> where the key is the
student's name and the value is their grade).

3. Output: Print out the student's name along with their score and grade.

Constraints:

• You are to use a List to store the student data and a Map to store the results.

• Use a loop to iterate through the students and conditional statements to determine the
grades.

Page 1 of 5
Step-by-Step Guide:

1. Set up the student data:

You will start by creating a list of students and their scores. This can be done using a List and storing
data as pairs (name, score).

2. Create a Map to store grades:

Use a HashMap to store the grades with the student's name as the key and the grade as the value.

3. Implement the grading logic:

Use a loop to go through each student.

Use if-else or switch statements to determine the grade based on the score.

4. Output the results:

After processing all the students, output the name, score, and grade for each student.

Page 2 of 5
import java.util.*;

public class StudentGradingSystem {

public static void main(String[] args) {

// Step 1: Create a List of students with their names and scores

List<Student> students = new ArrayList<>();

students.add(new Student("Alice", 85));

students.add(new Student("Bob", 92));

students.add(new Student("Charlie", 74));

students.add(new Student("David", 60));

students.add(new Student("Eve", 45));

// Step 2: Create a Map to store grades based on student names

Map<String, String> studentGrades = new HashMap<>();

// Step 3: Iterate through the list of students and assign grades

for (Student student : students) {

String grade = determineGrade(student.getScore());

studentGrades.put(student.getName(), grade);

// Step 4: Print out the results

System.out.println("Student Grades:");

for (String studentName : studentGrades.keySet()) {

System.out.println(studentName + ": " + studentGrades.get(studentName));

// Function to determine grade based on the score

public static String determineGrade(int score) {

if (score >= 90) {

Page 3 of 5
return "A";

} else if (score >= 80) {

return "B";

} else if (score >= 70) {

return "C";

} else if (score >= 60) {

return "D";

} else {

return "F";

// Student class to hold name and score

static class Student {

private String name;

private int score;

public Student(String name, int score) {

this.name = name;

this.score = score;

public String getName() {

return name;

public int getScore() {

return score;

Page 4 of 5
Breakdown of Code:

1. Student Class: A simple class that holds the name and score of each student.

2. List of Students: A List<Student> is used to store the student objects.

3. HashMap for Grades: A HashMap<String, String> is used to store each student's name and
their corresponding grade.

4. Grading Logic: The method determineGrade(int score) uses conditional statements (if-else) to
determine the grade based on the score.

5. Loop: A for-each loop iterates over the students and applies the grading logic, storing the
results in the HashMap.

6. Output: A second loop iterates over the keys of the Map to print the final grades.

Page 5 of 5

You might also like