From 73db68002892990373ad5a6f6c82538c493c1d39 Mon Sep 17 00:00:00 2001 From: AustrianToast Date: Tue, 28 Feb 2023 00:03:35 +0100 Subject: [PATCH 01/12] Created Matrix class Created Matrix class with an empty main method --- src/Matrix | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/Matrix diff --git a/src/Matrix b/src/Matrix new file mode 100644 index 0000000..17a4ee7 --- /dev/null +++ b/src/Matrix @@ -0,0 +1,5 @@ +public class Matrix { + public public static void public static void main(String[] args) { + + } +} \ No newline at end of file -- 2.45.2 From 13f8144bb213fe60be86b660f64fcc553468c2c7 Mon Sep 17 00:00:00 2001 From: AustrianToast Date: Tue, 28 Feb 2023 00:08:22 +0100 Subject: [PATCH 02/12] Created Matrix class Created Matrix class with an empty main method --- src/Matrix | 5 ----- src/Matrix.java | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-) delete mode 100644 src/Matrix create mode 100644 src/Matrix.java diff --git a/src/Matrix b/src/Matrix deleted file mode 100644 index 17a4ee7..0000000 --- a/src/Matrix +++ /dev/null @@ -1,5 +0,0 @@ -public class Matrix { - public public static void public static void main(String[] args) { - - } -} \ No newline at end of file diff --git a/src/Matrix.java b/src/Matrix.java new file mode 100644 index 0000000..fd0cc0c --- /dev/null +++ b/src/Matrix.java @@ -0,0 +1,5 @@ +public class Matrix { + public static void main(String[] args) { + + } +} \ No newline at end of file -- 2.45.2 From 5a678633b72d619a1855e291338cf7ab59cb2980 Mon Sep 17 00:00:00 2001 From: AustrianToast Date: Tue, 28 Feb 2023 00:33:17 +0100 Subject: [PATCH 03/12] Created importCSV method Created the empty method importCSV --- src/Matrix.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Matrix.java b/src/Matrix.java index fd0cc0c..c47e882 100644 --- a/src/Matrix.java +++ b/src/Matrix.java @@ -1,5 +1,13 @@ +import java.io.BufferedReader; + public class Matrix { public static void main(String[] args) { } + + public String[] importCSV() { + String[] result = null; + + return result; + } } \ No newline at end of file -- 2.45.2 From f29925a78e3fd74fb12b21401d244e9982173633 Mon Sep 17 00:00:00 2001 From: AustrianToast Date: Sun, 5 Mar 2023 00:08:13 +0100 Subject: [PATCH 04/12] Completed importCSV method Added BufferedReader with FileReader surrounded by a try/catch --- src/Matrix.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Matrix.java b/src/Matrix.java index c47e882..5f23912 100644 --- a/src/Matrix.java +++ b/src/Matrix.java @@ -1,4 +1,7 @@ import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; public class Matrix { public static void main(String[] args) { @@ -7,7 +10,22 @@ public class Matrix { public String[] importCSV() { String[] result = null; + String line; + try { + BufferedReader br = new BufferedReader(new FileReader("")); + + line = br.readLine(); + while (line != null) { + result = line.trim().split(";"); + } + + br.close(); + } catch (FileNotFoundException e) { + e.getStackTrace(); + } catch (IOException e) { + e.getStackTrace(); + } return result; } } \ No newline at end of file -- 2.45.2 From 922ddee386b4518e561b77551203422b3e876014 Mon Sep 17 00:00:00 2001 From: AustrianToast Date: Sun, 5 Mar 2023 00:12:07 +0100 Subject: [PATCH 05/12] Added file parameter Added it so I don't have a hardcoded file location --- src/Matrix.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Matrix.java b/src/Matrix.java index 5f23912..d2c018d 100644 --- a/src/Matrix.java +++ b/src/Matrix.java @@ -8,11 +8,11 @@ public class Matrix { } - public String[] importCSV() { + public String[] importCSV(String file) { String[] result = null; String line; try { - BufferedReader br = new BufferedReader(new FileReader("")); + BufferedReader br = new BufferedReader(new FileReader(file)); line = br.readLine(); -- 2.45.2 From 8b3a28311807196953d53f94eeff2b686ec95a0b Mon Sep 17 00:00:00 2001 From: AustrianToast Date: Sun, 5 Mar 2023 00:46:02 +0100 Subject: [PATCH 06/12] Removed line variable It just wasn't needed --- src/Matrix.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Matrix.java b/src/Matrix.java index d2c018d..c41176a 100644 --- a/src/Matrix.java +++ b/src/Matrix.java @@ -9,22 +9,19 @@ public class Matrix { } public String[] importCSV(String file) { - String[] result = null; - String line; + String[] result = new String[100]; try { BufferedReader br = new BufferedReader(new FileReader(file)); - - line = br.readLine(); - while (line != null) { - result = line.trim().split(";"); + while (br.readLine() != null) { + result = br.readLine().trim().split(";"); } br.close(); } catch (FileNotFoundException e) { - e.getStackTrace(); + e.printStackTrace(); } catch (IOException e) { - e.getStackTrace(); + e.printStackTrace(); } return result; } -- 2.45.2 From 18db15a050a606a554c77d753268acfeb310a55a Mon Sep 17 00:00:00 2001 From: AustrianToast Date: Sun, 5 Mar 2023 00:47:41 +0100 Subject: [PATCH 07/12] Created TestMatrix class For now only has one test for the importCSV method --- src/TestMatrix.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/TestMatrix.java diff --git a/src/TestMatrix.java b/src/TestMatrix.java new file mode 100644 index 0000000..1eb95c5 --- /dev/null +++ b/src/TestMatrix.java @@ -0,0 +1,12 @@ +public class TestMatrix { + public static void main(String[] args) { + testImportCSV(); + } + + public static void testImportCSV() { + Matrix m = new Matrix(); + + m.importCSV("/home/satan/bin/graphprogram/graph.csv"); + System.out.println(m); + } +} -- 2.45.2 From caecaef5d5a2cd13b88bccb25c743e3cd5c01c31 Mon Sep 17 00:00:00 2001 From: AustrianToast Date: Sun, 5 Mar 2023 00:51:08 +0100 Subject: [PATCH 08/12] Created empty printCSV method gonna use it to print out the array which contains the array --- src/Matrix.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Matrix.java b/src/Matrix.java index c41176a..b9ee6bd 100644 --- a/src/Matrix.java +++ b/src/Matrix.java @@ -25,4 +25,8 @@ public class Matrix { } return result; } + + public void printCSV() { + + } } \ No newline at end of file -- 2.45.2 From 442ee37075d08036efaab68cefeac1ce8875c37a Mon Sep 17 00:00:00 2001 From: AustrianToast Date: Sun, 5 Mar 2023 00:58:45 +0100 Subject: [PATCH 09/12] ReAdded line variable It was needed after all --- src/Matrix.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Matrix.java b/src/Matrix.java index b9ee6bd..b58f6dc 100644 --- a/src/Matrix.java +++ b/src/Matrix.java @@ -10,11 +10,12 @@ public class Matrix { public String[] importCSV(String file) { String[] result = new String[100]; + String line; try { BufferedReader br = new BufferedReader(new FileReader(file)); - while (br.readLine() != null) { - result = br.readLine().trim().split(";"); + while ((line = br.readLine()) != null) { + result = line.trim().split(";"); } br.close(); -- 2.45.2 From 4ac94f9ce1ff36132f26e2852f9be27cab4aa521 Mon Sep 17 00:00:00 2001 From: AustrianToast Date: Sun, 5 Mar 2023 00:59:56 +0100 Subject: [PATCH 10/12] Made result a global variable So it can be used by other methods --- src/Matrix.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Matrix.java b/src/Matrix.java index b58f6dc..511de65 100644 --- a/src/Matrix.java +++ b/src/Matrix.java @@ -4,12 +4,14 @@ import java.io.FileReader; import java.io.IOException; public class Matrix { + private String[] result; + public static void main(String[] args) { } public String[] importCSV(String file) { - String[] result = new String[100]; + result = new String[100]; String line; try { BufferedReader br = new BufferedReader(new FileReader(file)); -- 2.45.2 From b16d900532b7908e7b2e0b54953504771e08b81a Mon Sep 17 00:00:00 2001 From: AustrianToast Date: Mon, 6 Mar 2023 00:45:51 +0100 Subject: [PATCH 11/12] Array now initialized with correct size I still don't know how to put the csv into the array tough --- src/Matrix.java | 31 +++++++++++++++++++------------ src/TestMatrix.java | 2 +- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/Matrix.java b/src/Matrix.java index 511de65..14eaec6 100644 --- a/src/Matrix.java +++ b/src/Matrix.java @@ -4,32 +4,39 @@ import java.io.FileReader; import java.io.IOException; public class Matrix { - private String[] result; - + private String[][] matrix; public static void main(String[] args) { } - public String[] importCSV(String file) { - result = new String[100]; - String line; - try { - BufferedReader br = new BufferedReader(new FileReader(file)); + public String[][] importCSV(String file) { + try (BufferedReader br = new BufferedReader(new FileReader(file))) { + String line = br.readLine(); + int rowCount = 0; + int columnCount = line.split(";").length; - while ((line = br.readLine()) != null) { - result = line.trim().split(";"); + while (line != null) { + line = br.readLine(); + rowCount++; } - + + matrix = new String[rowCount][columnCount]; + br.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } - return result; + return matrix; } public void printCSV() { - + for(int i=0; i < matrix.length; i++) { + for(int j=0; j < matrix[i].length; j++) { + System.out.print(matrix[i][j]); + } + System.out.println(); + } } } \ No newline at end of file diff --git a/src/TestMatrix.java b/src/TestMatrix.java index 1eb95c5..1264319 100644 --- a/src/TestMatrix.java +++ b/src/TestMatrix.java @@ -7,6 +7,6 @@ public class TestMatrix { Matrix m = new Matrix(); m.importCSV("/home/satan/bin/graphprogram/graph.csv"); - System.out.println(m); + m.printCSV();; } } -- 2.45.2 From 51daa4a5118d0bedfe5d8dc71cdc3e30d781c68a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Fri, 17 Mar 2023 15:28:36 +0100 Subject: [PATCH 12/12] done don't ask how --- src/Matrix.java | 47 ++++++++++++++++++++++++++------------------- src/TestMatrix.java | 9 ++++----- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/Matrix.java b/src/Matrix.java index 14eaec6..ed3a668 100644 --- a/src/Matrix.java +++ b/src/Matrix.java @@ -1,42 +1,49 @@ import java.io.BufferedReader; -import java.io.FileNotFoundException; -import java.io.FileReader; import java.io.IOException; +import java.io.FileReader; +import java.io.FileNotFoundException; public class Matrix { - private String[][] matrix; - public static void main(String[] args) { - + private int[][] matrix; + + public static void main(String[] args) {} + + public Matrix(String file) { + matrix = this.readCSV(file); } - public String[][] importCSV(String file) { + public int[][] readCSV(String file){ + int[][] intMatrix = null; try (BufferedReader br = new BufferedReader(new FileReader(file))) { String line = br.readLine(); - int rowCount = 0; - int columnCount = line.split(";").length; + int rowCount = line.trim().split(";").length; + int columnCount = rowCount; + String[] lineArray = null; - while (line != null) { - line = br.readLine(); - rowCount++; + intMatrix = new int[rowCount][columnCount]; + + for(int columnIndex = 0; line != null && columnIndex < intMatrix.length; columnIndex++, line = br.readLine()) { + lineArray = line.trim().split(";"); + for(int rowIndex=0; rowIndex < intMatrix[columnIndex].length; rowIndex++) { + intMatrix[columnIndex][rowIndex] = Integer.parseInt(lineArray[rowIndex]); + } } - - matrix = new String[rowCount][columnCount]; - br.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } - return matrix; + return intMatrix; } - public void printCSV() { - for(int i=0; i < matrix.length; i++) { - for(int j=0; j < matrix[i].length; j++) { - System.out.print(matrix[i][j]); + public void print() { + for(int columnIndex=0; columnIndex < matrix.length; columnIndex++) { + for(int rowIndex=0; rowIndex < matrix[columnIndex].length; rowIndex++) { + System.out.print(matrix[columnIndex][rowIndex]); } System.out.println(); } } -} \ No newline at end of file + +} diff --git a/src/TestMatrix.java b/src/TestMatrix.java index 1264319..7db94b0 100644 --- a/src/TestMatrix.java +++ b/src/TestMatrix.java @@ -1,12 +1,11 @@ public class TestMatrix { public static void main(String[] args) { - testImportCSV(); + test1(""); } - public static void testImportCSV() { - Matrix m = new Matrix(); + public static void test1(String file) { + Matrix matrix = new Matrix(file); - m.importCSV("/home/satan/bin/graphprogram/graph.csv"); - m.printCSV();; + matrix.print(); } } -- 2.45.2