Question: Overview The goal of this first programming assignment is two - fold. First, to give you a basic introduction to programming the algorithms discussed in

Overview
The goal of this first programming assignment is two-fold. First, to give you a basic
introduction to programming the algorithms discussed in class. Second, to give you a
chance to get comfortable with programming in Java for the more complicated
Assignments #2 and #3 to be released after the mid-term. Most of the pseudo-code
needed for this assignment is in the lecture slides or problem solutions on moodle.
Starter/Skeleton Code
This document is accompanied by starterCode.zip, which includes three java files,
described below. Each of these files contains a skeleton code to provide you a starter
point. Mainly just the class structure and comments.
matrixMul.java
This is the main java file for this assignment. It contains a single driver method. The
user inputs a single input, a number that defines the size n of' a square matrix. Your
code must create two matrices "lefiMatrix" and "righ Matrix" filled with randomly
generated elements using randMatrix.java below. You then sort the rows in the
leftMatrix, as in every element in a row must be sorted like this
and sort the columns of "rightMatrix" as below
Note, only one row and column are highlighted but each is sorted.
Then you multiply the two matrices to create a third square matrix of size n. You may
at your discretion add more methods if you think they optimize your code.
randMatrix.java
This class creates and holds a 2D matrix object. This object is assigned random values
in the constructor which is called by the main function of matrixMul.java when the
object is created. This class also contains sortMat, that uses the array-sorting
algorithm from the sortAlg.java class below on the rows or columns of the matrix.
sortAlg.java
This class defines a sorting algorithm optimized for randomly generated arrays.
Implement the sorting algorithm that you think is optimal here. It is used by the
randMatrix class. It contains only two methods, a sortA method recursively sorts an
array, and a helper method to perform any external functions the algorithm may need.
These methods are static, so they do not require an instance of this class to be created
Bonus pro-hint: If you want to, you can implement different sorting algorithms and
calculate the exact run-lime using System,nanoTime(), you could test a few input
values of n to average run-time.
Output
The driver code matrixMul.java needs to print the following:
lefMatrix and rightMatrix with random numbers are initialized.
Sorted lef Matrix and rightMatrix after sorling as described above.
Final Matrix afler multiplication.
Additional print and exception handling of good code (extra credit possibly???):
Invalid input..what if the input is not an integer? What would you tell the user?
Edge cases what kind of edge cases you would warn your users against?'(also
something to consider documenting in your code) matrixMul.java
public class matrixMul
{
/*
* This driver creates two 2D matrices of randMatrix class from the user input size
* it then sorts left matrix rows and right matrix columns
* then it multiplies left matrix with the right matrix and saves it as new 2D matrix
* prints: random left and right matrices, sorted left and right matrices, new matrix
*/
public static void main(String[] arr)
{
int size = Integer.parseInt(args[0]);
//Implement rest of this method
}
}
randMatrix.java
public class randMatrix
{
public int[][] matrix ;
boolean sorted;
/*
* Constructor used to build square matrix of size n*n and assign random value to each element in the matrix
*/
public static void randMatrix(int n)
{
//Implement this method
}
/*
* sorts matrix
* input - axisType ( row or column )
*/
public static void sortMat(axisType)
{
//Implement this method
}
}
sortAlg.java
public class sortAl
{
public static void sortA(int[] arr)
{
//Implement this method
}
private static int helper(//fill your input parameters)
{
//Implement this method
}
}
*String[] arr should be String[] args* in the matrixmul.java
Overview The goal of this first programming

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!