- Read these instructions repeatedly until you understand, then begin your project. If something is not clear, ask.
- Log in to GitHub.
- Fork this repo(sitory). See this video on how to carry out this step and step
3
. - Clone your fork, using either the web site or the GitHub Desktop client.
- Checkout your personalized branch, the one with your name and GitHub handle.
Write a program that does the following:
- Requests from the user a positive number representing the size of a matrix
- Prints a matrix consisting of
0
s - Populates the matrix with values from
1–(input × input)
- Prints the matrix with the newly-populated values
- Swaps the contents of the matrix on one side of the diagonal formed from top right to bottom left with the other side, highlighting the elements along the diagonal and leaving them untouched/unswapped
- Prints the flipped matrix
As mentioned in item 5, the elements in the diagonal must not be touched, while the other elements in the matrix must be swapped. The numbers in every cell of the matrix is arbitrary; each cell could have contained a letter, string, image, or other object/primitive. Numbers are being used in this assignment because they produce a sequence that is easy to follow when working with the matrix. A movie of how this assignment should behave in its resolved state is available here.
This repo contains the following files, all required to carry out this assignment. Before you start working, ensure you understand the role of each file below.
Makefile
— Runmake
in your command line interface, or CLI, from this repo’s root folder to build your assignment. As you test input, runmake run
to only run a previously-compiled Java program, not compile it. Runmake clean
to remove the class file..editorconfig
— Everything in this file is a redundancy of what’s already in the.editorconfig
file you installed in your home folder. It’s here to make sure you’re working with the formatting rules defined in.editorconfig
, as this is part of your grade. Ensure EditorConfig is working in VS Code, before beginning this assignment..gitignore
— Do not modify this file.Matrix.java
— Where the entireMatrix
class and its methods will be defined.RunMatrix.java
— Methodmain
goes in this file, along withe the instantiation of theMatrix
object and all the required behavior.
All your code may only be written in the .java
files of this project’s scaffold.
- Your
Matrix
class should contain a single field calledmatrix
of the primitive type required to create a matrix. - The
Matrix
constructor should accept an integer value as an argument namedsize
, then create amatrix
field whose width and height are equivalent to the integer passed to it. The constructor should also report to the user the dimensions of the matrix. - As part of the
Matrix
class, write aprivate
method calledswap
that will accept four arguments:x1
,y1
,x2
, andy2
, each representing the indices of the two elements in the matrix that should be swapped. - Write a
public
method calledprintMatrix
that accepts no arguments and returns nothing. It should print the matrix, highlighting in yellow the diagonal from top right to bottom left. - Write a
public
method calledpopulateMatrix
that accepts no arguments and returns nothing. It should simply populate the matrix with values from1–(size × size)
. - Write a
public
method calledflipMatrix
that accepts no arguments and returns nothing. It should “flip” the matrix’s values along the diagonal from top right to bottom left. The elements that comprise the diagonal should be highlight and not swapped.
Item | Points |
---|---|
Program works according to instructions | 20 |
Code avoids being clever in favor of readability | 20 |
Code is neat and professional | 20 |
Variable naming is logical | 20 |
Comments are used thoughtfully in places where code is not self documenting | 20 |
Wednesday, 5 April 2023, at 5:00 PM.
You will need to issue a pull request back into the original repo, the one from which your fork was created for this project. See the Issuing Pull Requests section of this site for help on how to submit your assignment.
Note: This assignment may only be submitted via GitHub. No other form of submission will be accepted.