Вы находитесь на странице: 1из 3

Deadline: 01.01.2012 06:00 a.m. No late homeworks more than 3 days will be accepted!!!

You have one year to do this project :) Write a class that simulates agrowable 2D integer array with the following properties: +GrowableIntArray(int rows,int cols)+GrowableIntArray() GrowableIntArray -array:int[][]

+addElement(int value, int r, int c) +changeRowSize(int row, int size) +findColMaxs():int[] +findRowMaxs():int[] +findRowMins():int[] +findColMins():int[] +findSum():int +findOdds():int[][] +findEvens():int[][] +findPowerOf3():int[][] +findColAvgs():int[] +findOddPositions():int[][] +addAGrowable(GrowableIntArray gr):void +toString():String +multiplyAGrowable(GrowableIntArray gr):void +subtractAGrowable(GrowableIntArray gr):void +printGrowable():void GrowableIntArray(int rows,int cols) constructor takes the row size and col size of the array as the input, and initializes the 2D array. The no arg. constructor just creates a GrowableIntArrayObject without initializing the 2D array. addElement(int value, int r, int c) takes 3 input, the value to be added to the array, the row position and the column position to be added. If the given position exceeds the row size or the column size, the array should be enlarged in the related position (column or row size should be changed accordingly) so that the new element can be added to the position given without loosing any value given before. changeRowSize(int row, int size) method changes the size of a given row to the given size. The previous values that fits into the new given size are protected, the ones

at the positions out of bounds are lost. So, be sure to write the following methods assuming that the 2D array is a ragged array because it is possible to make the array ragged. findColMaxs(),findRowMaxs(),findRowMins(),findColMins(), methods finds the min or max of each row or column accordingly and returns the vlues find in a 1D array. findSum() method finds the sum of all the elements in the 2D array. findOdds() method finds the odd elements in each row and returns the odd elements of the 2D array in a new 2D array. Ex: 2D array: {{1,2,3},{3,4,6},{3,8,5}} method returns {{1,3},{3},{3,5}} findEvens() method finds the even elements in each row and returns the even elements of the 2D array in a new 2D array. Ex: 2D array: {{1,2,3},{3,4,6}, {3,8,5}} method returns {{},{4,6},{8}} findPowerOf3() method finds the elements that are power of 3 in each row and returns these elements of the 2D array in a new 2D array. Ex: 2D array: {{1,2,3}, {3,4,6},{3,8,5}} method returns {{3},{3,6},{3}} findColAvgs() method finds the average of each column and returns these values in a new 1D array. findOddPositions() method finds the odd positioned elements in each row and returns these elements of the 2D array in a new 2D array. Ex: 2D array: {{1,2,3},{3,4,6}, {3,8,5,2}} method returns {{2},{4},{8,2}} Write a main method in the same class to demonstrate the results of the usage of these methods on a sample GrowableIntArray objects. Check and printout the result of each method on these objects. The quality of the tests and input values will be a part of your grade. addAGrowable(GrowableIntArray gr) method takes a GrowableIntArray object and adds its contents to its contents. The result will be with the sizes of the larger one. Assume 0 value for the absent elements. {{1}{2,3}{2,3,4}} + {{1,2,3},{2}{3,5,6,7}{2,1,0}} ={{2,2,3},{4,3},{5,8,10,7},{2,1,0}} toString() method returns the String representation of the GrowableIntArray object that is ready to be printed to the screen. multiplyAGrowable(GrowableIntArray gr) method takes a GrowableIntArray object and multiply its contents with its contents. The result will be with the sizes of the larger one. Assume 0 value for the absent elements. {{1}{2,3}{2,3,4}} * {{1,2,3},{2}{3,5,6,7}{2,1,0}} ={{1,0,0},{4,0},{6,15,24,0},{0,0,0}} subtractAGrowable(GrowableIntArray gr) method takes a GrowableIntArray object

and subtruct its contents from its contents. The result will be with the sizes of the larger one. Assume 0 value for the absent elements. {{1}{2,3}{2,3,4}} - {{1,2,3},{2}{3,5,6,7}{2,1,0}} ={{0,-2,-3},{0,3},{-1,-2,-2,-7},{-2,-1,0}} Do not forget to include a report showing the details of how your methods work, a screenshot of the runtime, the source code and the class file. Do not forget to send the project to the correct email address with the required subject line. A demo of this project will be presented. So at least be sure to understand what you are copying if you are doing so. Cheating will be severely punished if caught. Deadline: 01.01.2012 06:00 a.m.

Вам также может понравиться