Description
The purpose of this assignment is to demonstrate the programming skills related
with _le reading and data processing. Using the data from a _le, populate a
two dimensional array, then perform operations with the data already stored in
a two dimensional array.
User Interface (40 pts)
Write a program called MatrixProcessor.java. In this program, your task
is to read a _le passed through the command line/terminal arguments of the
program, i.e., the String[] args. In case the computer user does not provide a
_lename as an argument, the program shall display a noti_cation to the user as
follows: Invalid Input. Please provide a filename as an arguments!
You can use the _le matrixA.txt to demonstrate the program. Once you
read the _le, create and populate a two dimensional array with the information
in the _le.
Notice that the _rst line of the _le corresponds to the actual dimensions of
the array (i.e., rows and columns), the rest of the lines in the _le corresponds
to the actual data that must be stored in the two-dimensional array.
When you run your program through the command line/terminal, it should
look as follows:
// Example 1
>javac MatrixProcessor.java
>java MatrixProcessor matrixA.txt
Row Total: {40, 2, 11}
Col Total: {11, 16, 94}
Total Sum: 133
Total AVG: 11.08
Largest Vector: {68, 2, 6, 24, 19}
Smallest Vector: {9, -1, 1, 2, 7}
// Example 2
>javac MatrixProcessor.java
>java MatrixProcessor
Invalid Input. Please provide a filename as an arguments!
Methods (60 pts)
In the same program, implement the following methods de_ned belog. Your
program must test all the methods and write into a _le the answers for each
method invoked. For illustration purposes in di_erent methods, consider the
following matrix as an example:
1. (10 pts.) getRowTotal: takes two arguments: a 2D array that contains
ints, and an int r representing the row for the array, which it is desired
to _nd the total of that row.
2. (10 pts.) getColTotal: takes two arguments: a 2D array that contains
ints, and an int c representing the col for the array, which it is desired
to _nd the total of that column.
3. (10 pts.) getSum: will take the 2D array of ints and will return the sum
of all the indexes of the array.
4. (10 pts.) getAVG: will take the 2D array of ints and will return the average
of the array provided.
5. (10 pts.) getLargestVector: will take the 2D array of ints and will
return a vector containing the product of the largest value per row.
E.g., in the matrix A, the resulting vector will be extracted from the set of
values: {{13, 9, 68}, {2, -1, 1}, {6, 4, 1}, {2, 4, 24}, {8, 19, 7} resulting
on:
{68, 2, 6, 24, 19}..
6. (10 pts.) getSmallesttVector: will take the 2D array of ints and will
return a vector containing the product of the smallest value per row.
E.g., in the matrix A, the resulting vector will be extracted from the set of
values: {{13, 9, 68}, {2, -1, 1}, {6, 4, 1}, {2, 4, 24}, {8, 19, 7} resulting
on:
{9, -1, 1, 2, 7}.
Solution ---
import java.io.*;
import java.util.*;
public class MatrixProcessor {
//method 1 getRowTotal
public static int getRowTotal(int[][] array, int r) {
int rowTotal = 0;
for (int col = 0; col < array[r].length; col++) {
rowTotal += array[r][col];
}
return rowTotal;
}
//method 2 getColTotal

 

 

----

 

 

---

 

Download for full solution

 

Note - Make a matrixA.txt file in same directory by following the data is given below.
4 3
13 9 68
2 -1 1
6 4 1
2 4 24
/*
Output 1 -
Row Total: {90, 2, 11, 30}
Col Total: {23, 16, 94}
Total Sum: 133
Total AVG: 11.0
Largest Vector: {68, 2, 6, 24}
Smallest Vector: {9, -1, 1, 2}
Output 2 -
Invalid Input. Please provide a filename as an arguments!
*/

COSC 1437 Lab 2 Java Solution(Solved)

$100.00 Regular Price
$80.00Sale Price

    INDIA : +91-995-314-1035                                              USA: +1-628-888-9041

                     Rights Reserved - VARCHAS IT SYSTEMS PVT.LTD 

                      Terms of Service  |   Privacy Policy

    • Facebook
    • Twitter
    • YouTube
    • Instagram

    privacy policy right reserved research paper