package Arrays2D;

import java.util.Scanner;

/*
==========================2026 (c) Basit Qureshi ===========================

CS102 Programming II
Dept. of Computer Sc, Prince Sultan University
August 8, 2026
https://www.ieeepsu.org/basit/cs102/

//Exercise 1
Write a program that calculates the total score for students in a class. 
Suppose the scores are stored in a 2-dimensional array named scores.
The rows in scores refers to a student.
The column refers to the earned score in an exam (between 0 and 10).
The user provides the number of students, and the number of exams.
Your program randomly fills the values in the 2D array.
Your program shows the sum of scores for each student.
*/

public class EXArray2D1 {
    public static void main(String [] s)
    {
        //TO DO: Ask the user to input number of students and number of exams
        Scanner In = new Scanner(System.in);
        System.out.println("Enter number of students: ");
        int Students = In.nextInt();
        
        System.out.println("Enter number of exams: ");
        int Exams = In.nextInt();
        //Define array
        //int [][] a = new int [rows][cols];
            
        double [][] Arr = new double [Students][Exams];

        //Randomly fill the array
        fillArray(Arr);
        
        //Display the sum for each student
        for(int i=0;i<Arr.length;i++)
        {
            System.out.println("Student " + i 
                             + ": " + sumRow(Arr, i));
        }
    }
    
    public static void fillArray(double [][] S)
    {
        int rows = S.length;
        int cols = S[0].length;
        
        for(int i=0; i< rows; i++)
        {
            for(int j=0;j< cols; j++)
            {
                S[i][j]= Math.random()*10;
            }
        }
    }
    
    public static double sumRow(double [][]S, int student)
    {
        double sum = 0;
        for(int i=0; i<S[student].length;i++)
        {
            sum = sum + S[student][i];
        }
        return sum;
    }
    
}
