1
0
Fork 0

Dateien nach "Axel/src/de/hs_mannheim/informatik/spreadsheet" hochladen

test
main
Jan Bachmann 2024-01-07 23:32:20 +01:00
parent cf3be4d319
commit 1aa39e7344
1 changed files with 11 additions and 51 deletions

View File

@ -1,6 +1,5 @@
package de.hs_mannheim.informatik.spreadsheet;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
@ -8,7 +7,6 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
@ -36,23 +34,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];
int rowWithMax99= Math.min(rows, 99);
int colWithMax26= Math.min(cols, 26);
cells = new Cell[rowWithMax99][colWithMax26];
for (int r = 0; r < rowWithMax99; r++)
for (int c = 0; c < colWithMax26; c++)
cells[r][c] = new Cell();
}
// -----
/*
@ -74,7 +55,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 {
@ -105,34 +86,13 @@ public class Spreadsheet {
/**
* A method for reading in data from a CSV file.
* @param path The file to read.
* @param startCellName The upper left cell where data from the CSV file should be inserted.
* @param separator The char used to split up the input, e.g. a comma or a semicolon.
* @param starCellName The upper left cell where data from the CSV file should be inserted.
* @return Nothing.
* @exception IOException If path does not exist.
*/
public void readCsv(String path, String startCellName) throws FileNotFoundException {
Scanner csvIn = new Scanner(new File(path));
int index= 0;
while(csvIn.hasNextLine()){
String line =csvIn.nextLine();
String all="";
int filled=0;
for(int i = 0;i<line.length();i++) {
if(line.charAt(i)==',') {
if(!all.isBlank()) {
put(index,i-filled,all);
all="";
}
}else {
filled++;
all+=line.charAt(i);
}
}
index++;
}
csvIn.close();
public void readCsv(String path, char separator, String startCellName) throws FileNotFoundException {
// TODO: implement this
}
/**
@ -209,7 +169,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 +186,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 +208,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 +228,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 +262,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<Long> args = new ArrayList<>();
for(int j = getRow(startCellName); j<= (getRow(endCellName));j++){
@ -328,7 +288,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<Long> args = new ArrayList<>();
for(int j = getRow(startCellName); j<= (getRow(endCellName));j++){