1
0
Fork 0

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

test
main
Jan Bachmann 2024-01-08 18:16:08 +01:00
parent fe45bcf50c
commit ba4469b358
1 changed files with 54 additions and 17 deletions

View File

@ -1,5 +1,6 @@
package de.hs_mannheim.informatik.spreadsheet;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
@ -7,8 +8,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
* A simplified spreadsheet class for the PR1 programming lab at Hochschule Mannheim.
* One aspect worth mentioning is that it only supports long numbers, not doubles.
@ -17,8 +17,7 @@ import java.util.List;
*/
public class Spreadsheet {
Cell[][] cells;
/**
/*
* Constructor that creates a Spreadsheet of size rows * cols.
* @param rows number of rows
* @param cols number of columns
@ -34,6 +33,23 @@ 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();
}
// -----
/*
@ -55,7 +71,7 @@ public class Spreadsheet {
cellName = cellName.toUpperCase();
return get(getRow(cellName), getCol(cellName));
}
private void put(int row, int col, String value) {
void put(int row, int col, String value) {
if (!value.startsWith("="))
cells[row][col].setValue(value);
else {
@ -67,10 +83,10 @@ public class Spreadsheet {
cellName = cellName.toUpperCase();
put(getRow(cellName), getCol(cellName), value);
}
private int getCol(String cellName) {
public int getCol(String cellName) {
return cellName.charAt(0) - 'A';
}
private int getRow(String cellName) {
public int getRow(String cellName) {
if (cellName.length()==3) {
int Row = 0;
Row +=((cellName.charAt(1)-'0')*10);
@ -86,13 +102,34 @@ public class Spreadsheet {
/**
* A method for reading in data from a CSV file.
* @param path The file to read.
* @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.
* @param startCellName 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, char separator, String startCellName) throws FileNotFoundException {
// TODO: implement this
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();
}
/**
@ -169,7 +206,7 @@ public class Spreadsheet {
* @param endCellName The name of the cell in the lower right corner of the rectangle.
* @return The sum calculated.
*/
private long sum(String startCellName, String endCellName) {
public 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++) {
@ -186,7 +223,7 @@ public class Spreadsheet {
* @param endCellName The name of the cell in the lower right corner of the rectangle.
* @return The product calculated.
*/
private long prod(String startCellName, String endCellName) {
public long prod(String startCellName, String endCellName) {
long res = 1;
boolean anyNumbers= false;
for(int j = getRow(startCellName); j<= (getRow(endCellName));j++){
@ -208,7 +245,7 @@ public class Spreadsheet {
* @param endCellName The name of the cell in the lower right corner of the rectangle.
* @return The Mid Value calculated.
*/
private long mid(String startCellName, String endCellName) {
public long mid(String startCellName, String endCellName) {
long res = 0;
int Numbers= 0;
for(int j = getRow(startCellName); j<= (getRow(endCellName));j++){
@ -228,7 +265,7 @@ public class Spreadsheet {
* @param endCellName The name of the cell in the lower right corner of the rectangle.
* @return The Standard deviation calculated.
*/
private long stabw(String startCellName, String endCellName) {
public long stabw(String startCellName, String endCellName) {
long res=0;
long midSum=0;
//mid(startCellName,endCellName)
@ -262,7 +299,7 @@ public class Spreadsheet {
* @param endCellName The name of the cell in the lower right corner of the rectangle.
* @return The minimum value calculated.
*/
private long min(String startCellName, String endCellName) {
public long min(String startCellName, String endCellName) {
long res = 0;
List<Long> args = new ArrayList<>();
for(int j = getRow(startCellName); j<= (getRow(endCellName));j++){
@ -288,7 +325,7 @@ public class Spreadsheet {
* @param endCellName The name of the cell in the lower right corner of the rectangle.
* @return The maximum value calculated.
*/
private long max(String startCellName, String endCellName) {
public long max(String startCellName, String endCellName) {
long res = 0;
List<Long> args = new ArrayList<>();
for(int j = getRow(startCellName); j<= (getRow(endCellName));j++){