Welcome to Computer Programming

 

HWJ13_2D Arrays

Start with the file below and use it to create the 5 methods described.

Advanced people MUST do at least 2 of the advanced.

/**
 * Practice with 2 dimensional arrays
 *
 * @author (your name)
 * @version (a version number or a date)
 */
public class HWJ13_2DArrays
{
    static int table[][]=new int[5][3];

    //the constructor fills in the 2d array with some values below:
    public static void setup2DArray()
    {
        table[0][0]=6;  table[0][1]=4;  table[0][2]=0;
        table[1][0]=19;  table[1][1]=13;  table[1][2]=53;
        table[2][0]=44;  table[2][1]=51;  table[2][2]=27;
        table[3][0]=30;  table[3][1]=31;  table[3][2]=30;
        table[4][0]=24;  table[4][1]=40;  table[4][2]=10;

    }

    //have it print out the array in a nice fashion
    public static void printArray()
    {
        setup2DArray();  //keep this line - sets up the array
        //put code below

    }

    //replace every element with a random value
    public static void fillWithRandom()
    {
        setup2DArray();  //keep this line - sets up the array
        //put code below

    }
    //have it add x to every element in the table
    public static void addToEach(int x)
    {
        setup2DArray();  //keep this line - sets up the array
        //put code below

    }
    public static int findMaxValue()
    {
        setup2DArray();  //keep this line - sets up the array
        //put code below

        return 0;
    }

    public static double findAvgValue()
    {
        setup2DArray();  //keep this line - sets up the array
        //put code below

        return 0;
    }

    //ADVANCED
    //find the sum of whatever row they put in (assume row is between 0 and 4 if they put in 2 it would be 72)
    public static int findSumRow(int row)
    {
        setup2DArray();  //keep this line - sets up the array
        //put code below

        return 0;
    }

    //ADVANCED
    //find the sum of whatever column they put in (assume col is between 0 and 2 [so if they put in 2 it would be 130)
    public static int findSumCol(int col)
    {
        setup2DArray();  //keep this line - sets up the array
        //put code below

        return 0;
    }

    //ADVANCED - This method will add x to beginning of table, shifting all values over one (and losing the last value)
    public static void addToBeginning(int x)
    {
        setup2DArray();  //keep this line - sets up the array
        //put code below

    }
    //ADVANCED - This method will return the entire table as a 1d array
    public static int[] createSingleDimension()
    {
        setup2DArray();  //keep this line - sets up the array
        //put code below

        return null;
    }

    public static int findRandom (int min, int max)
    {
        int range=max-min+1;
        int rand=(int)(Math.random()*range)+min;
        return rand;
    }



}