Skip to content

Commit f85ef2f

Browse files
authored
Merge pull request #2 from mitsuki31/v0.2.0
Release JMatrix version 0.2.0
2 parents 16e5c89 + 4463fa3 commit f85ef2f

File tree

7 files changed

+771
-144
lines changed

7 files changed

+771
-144
lines changed

META-INF/MANIFEST.MF

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Program-Name: JMatrix
2+
Version: v0.2.0
3+
Main-Class: lib.matrix.ExampleMatrix
4+
Created-By: Ryuu Mitsuki
5+
Manifest-Version: 1.0

Makefile

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# MAKEFILE FOR JMATRIX
2+
# Created by Ryuu Mitsuki
3+
4+
SRC_DIR = lib/matrix/
5+
MANIFEST = META-INF/MANIFEST.MF
6+
7+
SRC = $(SRC_DIR)*.java
8+
BIN = $(SRC_DIR)*.class
9+
10+
JAR = Matrix.jar
11+
12+
all: $(SRC)
13+
$(info Creating jar files...)
14+
javac $(SRC)
15+
jar cvfm $(JAR) $(MANIFEST) $(BIN)
16+
17+
run: $(JAR)
18+
java -jar $(JAR)
19+
20+
clean:
21+
rm -r $(BIN) $(JAR)
22+
23+
24+
.PHONY: all run clean

README.md

+85-40
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
> JMatrix is a matrix builder written in Java.<br>
55
> Developed by Ryuu Mitsuki.<br>
6-
> It can create, summarize, subtract and clear the matrix array
6+
> It can create, summarize, subtract, multiply and clear the matrix array.<br>
7+
> Check `LIST FUNCTION` below to see all functions.
78
89
---
910

@@ -13,12 +14,6 @@ If not, download here:<br>
1314
2. [https://developers.redhat.com/products/openjdk/download](https://developers.redhat.com/products/openjdk/download)
1415

1516
## LIST FUNCTION:rocket:
16-
> NOTE:<br>
17-
> All below functions isn't static, so create a new Matrix object first :)<br>
18-
> Except for:
19-
> - static void display(int[ ][ ] array)
20-
> - static void sort(int[ ][ ] array)
21-
2217

2318
### add()
2419
Fill column of matrix array with push method.<br>
@@ -27,35 +22,91 @@ If you attempt to call `add()` function again and you've matrix size 2x3, but yo
2722
Function parameters:
2823
- void add(int... values)
2924
- void add(int value)
30-
> For the second parameter, it would create a single column with same value and for size equal to total matrix rows, then assign to matrix array.
31-
3225

3326
### sum()
34-
Summarize current matrix array with other matrix array.<br>
27+
Summarize current matrix array with other matrix.<br>
3528
<br>
3629
Function parameters:
37-
- int[ ][ ] sum(Matrix object)
38-
- int[ ][ ] sum(int[ ][ ] array)
30+
- void sum(Matrix object)
31+
- void sum(int[ ][ ] array)
32+
<br>
33+
34+
- static int[ ][ ] sum(int[ ][ ] array, int[ ][ ] array)
35+
- static Matrix sum(Matrix obj1, Matrix obj2)
3936

4037
### sub()
41-
Subtract current matrix array with other matrix array.<br>
38+
Subtract current matrix array with other matrix.<br>
39+
<br>
40+
Function parameters:
41+
- void sub(Matrix obj)
42+
- void sub(int[ ][ ] arr)
43+
<br>
44+
45+
- static int[ ][ ] sub(int[ ][ ] arr, int[ ][ ] arr)
46+
- static Matrix sub(Matrix obj1, Matrix obj2)
47+
48+
### mult()
49+
Multiply current matrix with other matrix.<br>
50+
<br>
51+
Function parameters:
52+
- void mult(Matrix obj)
53+
- void mult(int[ ][ ] arr)
54+
<br>
55+
56+
- static int[ ][ ] mult(int[ ][ ] arr, int[ ][ ] arr)
57+
- static Matrix mult(Matrix obj1, Matrix obj2)
58+
59+
### transpose()
60+
Transpose current matrix or current matrix transpose to other matrix.<br>
61+
<br>
62+
Function parameters:
63+
- void transpose()
64+
<br>
65+
66+
- static int[ ][ ] transpose(int[ ][ ] arr)
67+
- static Matrix transpose(Matrix obj)
68+
69+
70+
### create()
71+
Create a new matrix with specified rows and columns.<br>
72+
<br>
73+
Function parametera:
74+
- void create(int rows, int cols)
75+
76+
### select()
77+
Select row matrix by given index.<br>
78+
<br>
79+
Function parameters:
80+
- void select()
81+
82+
### change()
83+
Change values of selected row with given values.<br>
84+
> Use this together with `select` function.<br>
85+
> Example: `matrixA.select(<index>).change(<values>)`
86+
<br>
87+
88+
Function parameters:
89+
- void change(int... values)
90+
- void change(int value)
91+
92+
### copy()
93+
Copy current matrix to another matrix object.<br>
4294
<br>
4395
Function parameters:
44-
- int[ ][ ] sub(Matrix object)
45-
- int[ ][ ] sub(int[ ][ ] array)
96+
- Matrix copy()
4697

4798
### sort()
4899
Sort all columns inside matrix array.<br>
49100
<br>
50101
Function parameters:
51102
- void sort()
52-
- static void sort(int[ ][ ] array)
103+
- static void sort(int[ ][ ] arr)
53104

54105
### getSize()
55-
Return list of matrix size.<br>
106+
Return list of matrix size [rows, columns].<br>
56107
<br>
57108
Function parameters:
58-
- int[ ] getSize() <- return [\<rows\>, \<cols\>]
109+
- int[ ] getSize()
59110

60111
### clear()
61112
Clear all each column inside matrix array, and change all values with 0.<br>
@@ -68,32 +119,26 @@ Display the matrix to console output.<br>
68119
<br>
69120
Function parameters:
70121
- void display()
71-
- static void display(int[ ][ ] array)
72-
73-
74-
## EXAMPLE USAGE
122+
- void display(int index)
123+
<br>
75124

76-
I've created example for `JMatrix` usage in `examples` directory (just for references).<br>
125+
- static void display(int[ ][ ] arr)
126+
- static void display(int[ ][ ] arr, int index)
77127

78-
---
128+
<br>
79129

80-
**Clone this repository and goto `jmatrix` directory<br>**
81-
```shell|powershell
82-
git clone https://github.com/mitsuki31/jmatrix.git
83-
cd jmatrix
130+
## USAGE
131+
Compile and create a `JAR` file with `Makefile`
132+
```bash|powershell
133+
make
84134
```
85135

86-
**Compile the program<br>**
87-
- Linux / Unix
88-
```shell
89-
javac examples/ExampleMatrix.java
90-
```
91-
- Windows
92-
```powershell
93-
javac "examples\ExampleMatrix.java"
136+
Run the program
137+
```bash|powershell
138+
make run
94139
```
95140

96-
**Run the program<br>**
97-
```shell|powershell
98-
java examples.ExampleMatrix
99-
```
141+
## EDIT MANIFEST
142+
If you want to change the `Main` file while running the program,
143+
change `Main-Class` in `META-INF/MANIFEST.MF`.<br>
144+
Default: `lib.matrix.ExampleMatrix`

examples/ExampleMatrix.java

-71
This file was deleted.

lib/matrix/ExampleMatrix.java

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// ::-------------------:: //
2+
/* ExampleMatrix */
3+
// ::-------------------:: //
4+
package lib.matrix;
5+
6+
import java.util.Arrays;
7+
8+
import lib.matrix.*; // import all packages in "lib.matrix"
9+
10+
public class ExampleMatrix
11+
{
12+
public static void main(String[ ] args)
13+
throws NullMatrixException, IllegalMatrixSizeException, MatrixArrayFullException, InvalidIndexException
14+
{
15+
// Rows and columns size for new Matrix
16+
int rows = 2;
17+
int cols = 3;
18+
19+
// Values for each row
20+
int[ ] row1 = { 1, 2, 3 };
21+
int[ ] row2 = { 4, 5, 6 };
22+
int[ ] row3 = { 7, 8, 9 };
23+
24+
int[ ] rowA1 = { -9, -6, -3 };
25+
int[ ] rowA2 = { -8, -5, -2 };
26+
int[ ] rowA3 = { -7, -4, -1 };
27+
28+
// Create new Matrix object
29+
Matrix matrixA = new Matrix(rows, cols);
30+
Matrix matrixB = new Matrix(rows, cols);
31+
Matrix result = new Matrix(); // null matrix
32+
33+
// Get the Matrix size
34+
int[ ] matrixSize = matrixA.getSize(); // return [rows, cols]
35+
36+
// Display matrix size
37+
System.out.println("\nSIZE OF MATRIX A: " + Arrays.toString(matrixSize));
38+
39+
// Adding values into Matrix
40+
matrixA.add(row1);
41+
matrixA.add(row2);
42+
43+
matrixB.add(rowA1);
44+
matrixB.add(rowA2);
45+
46+
// Display the matrix
47+
System.out.println("\nMATRIX A");
48+
matrixA.display();
49+
50+
System.out.println("\nMATRIX B");
51+
matrixB.display();
52+
53+
System.out.println("\n-------------------------");
54+
System.out.println(" SUMMATION");
55+
System.out.println("-------------------------");
56+
57+
System.out.println("MATRIX A + MATRIX B\n");
58+
result = Matrix.sum(matrixA, matrixB);
59+
result.display();
60+
61+
System.out.println("\n-------------------------");
62+
System.out.println(" SUBTRACTION");
63+
System.out.println("-------------------------");
64+
65+
System.out.println("MATRIX A - MATRIX B\n");
66+
result = Matrix.sub(matrixA, matrixB);
67+
result.display();
68+
69+
System.out.println("\n-------------------------");
70+
System.out.println(" MULTIPLICATION");
71+
System.out.println("-------------------------");
72+
73+
System.out.println("MATRIX A * MATRIX B\n");
74+
result = Matrix.mult(matrixA, matrixB);
75+
result.display();
76+
77+
System.out.println("\n-------------------------");
78+
System.out.println(" TRANSPOSE");
79+
System.out.println("-------------------------");
80+
81+
System.out.println("TRANSPOSED MATRIX B\n");
82+
matrixB.transpose();
83+
matrixB.display();
84+
85+
System.out.println("\n-------------------------");
86+
System.out.println(" CLEARING MATRIX");
87+
System.out.println("-------------------------");
88+
89+
System.out.println("CLEARED MATRIX A\n");
90+
matrixA.clear();
91+
matrixA.display();
92+
93+
System.out.println("\n-------------------------");
94+
System.out.println(" COPY MATRIX");
95+
System.out.println("-------------------------");
96+
97+
System.out.println("COPY MATRIX B TO MATRIX A\n");
98+
matrixA = matrixB.copy();
99+
matrixA.display();
100+
}
101+
}

0 commit comments

Comments
 (0)