Skip to main content

Exercise Overview

In this exercise, you’ll learn how to create a comprehensive grade management system that:
  • Captures student grades from user input
  • Calculates averages
  • Identifies grades above the average
  • Detects failing grades
  • Manages multiple lists (movies, colors, etc.)

Exercise 1: Grade Analysis System

Problem Statement

Create a program that:
1

Capture 5 grades

Ask the user to input 5 grades (decimal numbers)
2

Calculate average

Compute the average of all grades
3

Find grades above average

Display all grades that are greater than or equal to the average
4

Identify failing grades

Display all grades below 6.0 (failing grades)

Solution Components

Function 1: Capture Grades

This function uses double.parse() to convert string input to decimal numbers, allowing for grades like 8.5 or 9.75.

Function 2: Calculate Average

The function:
  1. Initializes a sum variable to 0.0
  2. Iterates through all grades, adding each to the sum
  3. Divides the sum by the total number of grades
  4. Returns the result as a double

Function 3: Display Grades Above Average

Function 4: Display Failing Grades

In this system, any grade below 6.0 is considered failing. Make sure to adjust this threshold based on your grading system.

Complete Program

Exercise 2: Multiple List Management

Problem Statement

Create a program that manages two lists (movies and colors) and:
1

Load initial data

Collect 5 items for each list from the user
2

Add more data

Add one more item to each list
3

Display lists

Print all items in a numbered format
4

Show list sizes

Display the total count of items in each list

Solution Components

Reusable Function: Load List

By accepting a mensaje parameter, this function can be reused for any type of list, making the code more maintainable.

Reusable Function: Add Data

Reusable Function: Print Lists

The list is printed with 1-based numbering (i + 1) to make it more user-friendly, even though list indices start at 0.

Reusable Function: Display Size

Complete Program

Key Concepts

List<double>

Used for storing decimal numbers like grades

List<String>

Used for storing text like movie names or colors

Reusable Functions

Functions with parameters can work with different data

Data Validation

Important to check for failing grades and other conditions

Practice Challenges

Add functions to find:
  • Highest grade
  • Lowest grade
  • Number of passing grades
  • Percentage of students passing
Categorize grades into:
  • Excellent (9.0-10.0)
  • Good (8.0-8.9)
  • Satisfactory (7.0-7.9)
  • Passing (6.0-6.9)
  • Failing (below 6.0)
Modify the movie/color program to:
  • Allow the user to choose how many items to add initially
  • Add a search function to find specific items
  • Sort the lists alphabetically
  • Remove items by index

Best Practices

Separation of Concerns

Each function should do one thing well

Meaningful Names

Use descriptive function and variable names

Input Validation

Always validate user input to prevent crashes

Code Reusability

Write functions that can be used in different contexts