CPSC 212-302 MatrixPatterns Class Test, Exams of Algorithms and Programming

A test for a matrixpatterns class in java. The class has an instance variable which is a two-dimensional int array, a constructor that initializes and populates the array from a user-provided input file, and public methods printmatrix(), numrowones(), and numcolones(). The test driver provided prints the matrix and the number of rows and columns with all ones. Students are required to submit their work using handin.212.302 and are evaluated based on the correctness of their algorithm, selection of storage/data structure, and efficiency.

Typology: Exams

Pre 2010

Uploaded on 07/29/2009

koofers-user-kpd
koofers-user-kpd 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CPSC 212-302 Name: _____________________________
Test #1A February 9, 2005
Honor Pledge:
I pledge that I have neither given nor received unauthorized assistance on this test.
Signed: _______________________ Date: _____________
20 points. 50 minutes. Open Java API. Open cucs API. You may not visit any other web
page.
You are to develop a class called MatrixPatterns which has:
1. an instance variable which is a two-dimensional int array,
2. a one-argument constructor MatrixPatterns (String filename)
which instantiates and populates the array with values (only 0’s and 1’s) read
from the user-provided input file, and
3. public methods: int numRowOnes(), int numColOnes(), void
printMatrix()
which print the number of rows that are all ones, the number of columns that are
all ones, and all values of the array, as shown in the example below.
For example, assume that a sample input file called “inputfile” contains the following
data:
4 5
1 1 1 1 1
1 1 0 0 1
1 1 0 1 1
1 1 1 1 1
The first line contains the number of rows (4 in the sample file) and columns (5) of the
array. The next lines contain array int values. Note that there are 4 lines with 5 int
values per line. Note that an array value is either 0 or 1. Values are separated by spaces.
There are no blank lines. You may assume that the input is error free.
Then the following test driver:
public static void main(String args[]) {
MatrixPatterns mp = new MatrixPatterns("inputfile");
mp.printMatrix();
System.out.println(“Number of rows with all ones: “ + mp.numRowOnes());
System.out.println(“Number of columns with all ones: “ + mp.numColOnes());
} // end main
pf2

Partial preview of the text

Download CPSC 212-302 MatrixPatterns Class Test and more Exams Algorithms and Programming in PDF only on Docsity!

CPSC 212-302 Name: _____________________________

Test #1A February 9, 2005

Honor Pledge:

I pledge that I have neither given nor received unauthorized assistance on this test.

Signed: _______________________ Date: _____________

20 points. 50 minutes. Open Java API. Open cucs API. You may not visit any other web

page.

You are to develop a class called MatrixPatterns which has:

1. an instance variable which is a two-dimensional int array,

2. a one-argument constructor MatrixPatterns (String filename)

which instantiates and populates the array with values (only 0’s and 1’s) read

from the user-provided input file, and

3. public methods: int numRowOnes(), int numColOnes(), void

printMatrix()

which print the number of rows that are all ones, the number of columns that are

all ones, and all values of the array, as shown in the example below.

For example, assume that a sample input file called “inputfile” contains the following

data:

The first line contains the number of rows ( 4 in the sample file) and columns ( 5 ) of the

array. The next lines contain array int values. Note that there are 4 lines with 5 int

values per line. Note that an array value is either 0 or 1. Values are separated by spaces.

There are no blank lines. You may assume that the input is error free.

Then the following test driver:

public static void main(String args[]) { MatrixPatterns mp = new MatrixPatterns("inputfile"); mp.printMatrix(); System.out.println(“Number of rows with all ones: “ + mp.numRowOnes()); System.out.println(“Number of columns with all ones: “ + mp.numColOnes()); } // end main

produces the following output:

The matrix has 3 rows and 5 columns:

Number of rows with all ones: 2

Number of columns with all ones: 3

Submission:

Submit your work using: handin.212.302 1 MatrixPatterns.java

Also submit any helper methods you developed during this test and required by your

class.

Evaluation:

Your program will be evaluated on: (a) correctness of algorithm, and (b) selection of

storage/data structure, and (c) efficiency of algorithm.

Note: Make sure that you include public methods printMatrix(), numRowOnes(), and

numColOnes() in your class even if you were not able to complete them. This is in order

that your program will compile with our test driver. If you cannot complete a method,

print one line in the method stating so. For example:

numRowOnes() method not completed

or

numColOnes() method not completed

Moreover, do not forget to have the methods return an int (0 is good) as required by the

specifications.