Weekly Lab 1 – Arrays

Maximum Points = 10

 The purpose of this lab is to review your study of computer programming and algorithms from CS 1.

 

Design and implement a class that represents a gradebook.

Your program should ask the user for the number of grades (1-100) to enter for the assignment, followed by the grades (0-50). Your program will then display the grades, followed by the average grade for the assignment, and the highest, and lowest grades.

 

/**

 *

 *Gradebook.java

 *

 * Reads a words from the standard input and prints the number of

 * occurrences of each letter in that word.

 *         

 * @author (Wayne Summers)

 * @version (january 12, 2011)

 */

 

import java.util.Scanner;

 

public class Gradebook

{

    public static void main(String[] args)

    {

        int[] grades = new int[100];

        int nbrGrades;

        int grade;

        Scanner scan = new Scanner(System.in);

 

        //get number of grades from user

        do

        {

            System.out.println("Enter the number of grades (0-100): ");

            nbrGrades = scan.nextInt();

        }

        while (nbrGrades > 100 || nbrGrades < 0);

 

        //read in the grades

        for (int i=0; i < nbrGrades; i++)

        {

            do

            {

                System.out.println("Enter the " + (i+1) + "th grade (0-50): ");

                grade = scan.nextInt();

            }

            while (grade > 50 || grade < 0);

            grades[i] = grade;

        }

 

        /******************************************************************************

        * COMPUTE THE AVERAGE GRADE, THE LOWEST GRADE, and THE HIGHEST GRADE          *

        ******************************************************************************/

       

        //print grades

        System.out.println(" The list of grades is:");

        for (int i=0; i < nbrGrades; i++)

            System.out.print(grades[i] + " ");

           

        /******************************************************************************

        * PRINT THE AVERAGE GRADE, THE LOWEST GRADE, and THE HIGHEST GRADE          *

        ******************************************************************************/

    }

}

 

 (Due before end of the day on Friday, January 14, 2011) Submit your .java files containing your program to the dropbox in WebCT.

 Grades are determined using the following scale:

Grading Rubric  (Word document)