diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index 1760287..1ff2a95 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -36,11 +36,6 @@ public class Spreadsheet { for (int c = 0; c < colWithMax26; c++) cells[r][c] = new Cell(); } - /** - * Sets a Spreadsheet of size rows * cols. - * @param rows number of rows - * @param cols number of columns - */ public void changeSize(int rows, int cols) { cells = new Cell[0][0]; @@ -74,7 +69,7 @@ public class Spreadsheet { cellName = cellName.toUpperCase(); return get(getRow(cellName), getCol(cellName)); } - void put(int row, int col, String value) { + private void put(int row, int col, String value) { if (!value.startsWith("=")) cells[row][col].setValue(value); else { @@ -209,7 +204,7 @@ public class Spreadsheet { * @param endCellName The name of the cell in the lower right corner of the rectangle. * @return The sum calculated. */ - public long sum(String startCellName, String endCellName) { + private long sum(String startCellName, String endCellName) { long res = 0; for(int j = getRow(startCellName); j<= (getRow(endCellName));j++){ for(int i = getCol(startCellName); i<= (getCol(endCellName));i++) { @@ -226,7 +221,7 @@ public class Spreadsheet { * @param endCellName The name of the cell in the lower right corner of the rectangle. * @return The product calculated. */ - public long prod(String startCellName, String endCellName) { + private long prod(String startCellName, String endCellName) { long res = 1; boolean anyNumbers= false; for(int j = getRow(startCellName); j<= (getRow(endCellName));j++){ @@ -248,7 +243,7 @@ public class Spreadsheet { * @param endCellName The name of the cell in the lower right corner of the rectangle. * @return The Mid Value calculated. */ - public long mid(String startCellName, String endCellName) { + private long mid(String startCellName, String endCellName) { long res = 0; int Numbers= 0; for(int j = getRow(startCellName); j<= (getRow(endCellName));j++){ @@ -268,7 +263,7 @@ public class Spreadsheet { * @param endCellName The name of the cell in the lower right corner of the rectangle. * @return The Standard deviation calculated. */ - public long stabw(String startCellName, String endCellName) { + private long stabw(String startCellName, String endCellName) { long res=0; long midSum=0; //mid(startCellName,endCellName) @@ -302,7 +297,7 @@ public class Spreadsheet { * @param endCellName The name of the cell in the lower right corner of the rectangle. * @return The minimum value calculated. */ - public long min(String startCellName, String endCellName) { + private long min(String startCellName, String endCellName) { long res = 0; List args = new ArrayList<>(); for(int j = getRow(startCellName); j<= (getRow(endCellName));j++){ @@ -328,7 +323,7 @@ public class Spreadsheet { * @param endCellName The name of the cell in the lower right corner of the rectangle. * @return The maximum value calculated. */ - public long max(String startCellName, String endCellName) { + private long max(String startCellName, String endCellName) { long res = 0; List args = new ArrayList<>(); for(int j = getRow(startCellName); j<= (getRow(endCellName));j++){ diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/nr5.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/nr5.java deleted file mode 100644 index b28aba3..0000000 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/nr5.java +++ /dev/null @@ -1,139 +0,0 @@ -package de.hs_mannheim.informatik.spreadsheet; - -import static org.junit.jupiter.api.Assertions.*; - -import org.junit.jupiter.api.Test; - -public class nr5 { - private Spreadsheet spr; - private String[] spreadsheetData = { - "40", "12", "87", "54", "32", "66", "78", "21", "90", "89", - "25", "74", "88", "91", "33", "98", "67", "45", "19", "11", - "65", "69", "50", "84", "74", "61", "53", "99", "29", "46", - "16", "89", "79", "62", "45", "31", "73", "23", "13", "81", - "60", "88", "45", "51", "36", "16", "46", "3", "18", "85", - "4", "27", "87", "91", "29", "84", "95", "65", "71", "94", - "84", "49", "3", "79", "67", "89", "10", "74", "77", "51", - "48", "38", "41", "59", "2", "15", "62", "18", "40", "29", - "93", "13", "5", "58", "30", "64", "58", "6", "67", "96", - "67", "77", "25", "81", "87", "27", "53", "31", "85", "98"}; - - public void setup() { - spr = new Spreadsheet(10,10); - - for(int i=0;i<10;i++) { - for(int j=0;j<10;j++) { - spr.put(i,j, spreadsheetData[i+j*10]); - } - } - } - - @Test - public void testSum() { - setup(); - System.out.println(spr); - long expectedSum = 40 + 12 + 87 + 54 + 32 + 66 + 78 + 21 + 90 + 89 + - 25 + 74 + 88 + 91 + 33 + 98 + 67 + 45 + 19 + 11 + - 65 + 69 + 50 + 84 + 74 + 61 + 53 + 99 + 29 + 46 + - 16 + 89 + 79 + 62 + 45 + 31 + 73 + 23 + 13 + 81 + - 60 + 88 + 45 + 51 + 36 + 16 + 46 + 3 + 18 + 85 + - 4 + 27 + 87 + 91 + 29 + 84 + 95 + 65 + 71 + 94 + - 84 + 49 + 3 + 79 + 67 + 89 + 10 + 74 + 77 + 51 + - 48 + 38 + 41 + 59 + 2 + 15 + 62 + 18 + 40 + 29 + - 93 + 13 + 5 + 58 + 30 + 64 + 58 + 6 + 67 + 96 + - 67 + 77 + 25 + 81 + 87 + 27 + 53 + 31 + 85 + 98; - - assertEquals(expectedSum, spr.sum("A1", "J10")); - } - - - @Test - public void testProd() { - setup(); - long expectedProduct = 1; - for (String value : spreadsheetData) { - expectedProduct *= Integer.parseInt(value); - } - assertEquals(expectedProduct, spr.prod("A1", "J10")); - } - @Test - public void testMid() { - setup(); - int mid = 0; - for (String value : spreadsheetData) { - mid += Integer.parseInt(value); - } - mid /= 100; - - assertEquals((long) mid, spr.mid("A1", "J10")); - } - @Test - public void testStabw() { - setup(); - double Stabw = stabw(); - assertEquals((long) Stabw, spr.stabw("A1", "J10")); - } - @Test - public void testMin() { - setup(); - long Min = calMin(); - assertEquals(Min, spr.min("A1", "J10")); - } - @Test - public void testMax() { - setup(); - long Max = calMax(); - assertEquals(Max, spr.max("A1", "J10")); - } - - - - - - private double stabw() { - double midVal = cMV(); - double sum = 0.0; - int numbers = 0; - for (String value : spreadsheetData) { - if (!value.isBlank()) { - long longValue = Long.parseLong(value); - sum += Math.pow(longValue - midVal, 2); - numbers++; - } - } - return Math.sqrt(sum / numbers); - } - private double cMV() { - double midSum = 0.0; - int numbers = 0; - for (String value : spreadsheetData) { - if (!value.isBlank()) { - midSum += Long.parseLong(value); - numbers++; - } - } - return midSum / numbers; - } - private long calMin() { - long min = Long.MAX_VALUE; - for (String value : spreadsheetData) { - if (!value.isBlank()) { - long longValue = Long.parseLong(value); - min = Math.min(min, longValue); - } - } - return min; - } - private long calMax() { - long max = Long.MIN_VALUE; - - for (String value : spreadsheetData) { - if (!value.isBlank()) { - long longValue = Long.parseLong(value); - max = Math.max(max, longValue); - } - } - - return max; - } -}