import uwcse.io.*;
/**
* A class to illustrate the concept of dynamic allocation.
* The class methods allow the user to input an unknown number of grades
* (between 0 and 100). Internally the grades are stored in array that grows
* in size as more grades are entered.
*/
public class DynamicAllocation {
/**
* Input an unknown number of grades (store them in an array that
* grows in size as more grades are entered).
*/
public void inputGrades()
{
// Define the array (empty initially)
int[] grades = new int[0];
// Read the grades in a loop
// Store each grade in the array grades
int grade;
Input input = new Input();
do
{
grade = input.readInt("Enter the grade (<0 to quit): ");
if (grade>=0 && grade<=100)
{
// increase the size of the array
// Use the method increaseSizeByOne
grades = copyAndIncreaseSizeByOne(grades);
// store the new grade
grades[grades.length-1]=grade;
}
}
while(grade>=0);
// Display all of the grades
for(int i=0; i