Menu
Coddy logo textTech

Data Entry Logic

Part of the Logic & Flow section of Coddy's C# journey — lesson 41 of 66.

challenge icon

Challenge

Easy

Now that we have our data structure, let's implement logic for entering and updating student scores.

Create a class called DataEntry with these methods:

  1. SetStudentScore(int[][] scoreGrid, int studentIndex, int assignmentIndex, int score): Sets the score for a specific student and assignment if it's valid. Returns:
    • 0 if successful
    • -1 if any index is out of bounds
    • -2 if the score is invalid
  2. UpdateAllScores(int[][] scoreGrid, int[] studentIndices, int assignmentIndex, int score): Updates scores for multiple students on the same assignment. Returns the number of successfully updated scores.

Note: Use the ValidateScore method from the DataCollector class to check score validity.

Try it yourself

using System; // Don't delete this line
public class DataEntry
{
    public static int SetStudentScore(int[][] scoreGrid, int studentIndex, int assignmentIndex, int score)
    {
        // Write your code here
        
    }
    
    public static int UpdateAllScores(int[][] scoreGrid, int[] studentIndices, int assignmentIndex, int score)
    {
        // Write your code here
        
    }
}

// Required for testing - do not modify
public class DataCollector
{
    public static int[][] CreateScoreGrid(int students, int assignments)
    {
        int[][] scoreGrid = new int[students][];
        for (int i = 0; i < students; i++)
        {
            scoreGrid[i] = new int[assignments];
        }
        return scoreGrid;
    }
    
    public static bool ValidateScore(int score)
    {
        return score >= 0 && score <= 100;
    }
    
    public static int[][] PopulateWithDefaultValues(int[][] scoreGrid)
    {
        for (int i = 0; i < scoreGrid.Length; i++)
        {
            for (int j = 0; j < scoreGrid[i].Length; j++)
            {
                scoreGrid[i][j] = -1;
            }
        }
        return scoreGrid;
    }
}

All lessons in Logic & Flow