1
0
Fork 0

Spreadsheet getRow/getCol and more function fixes.

pull/1/head
selim 2023-12-27 02:55:18 +01:00
parent ac408c1f23
commit 1719f8db84
1 changed files with 11 additions and 10 deletions

View File

@ -52,7 +52,7 @@ public class Spreadsheet {
public String get(String cellName) { public String get(String cellName) {
cellName = cellName.toUpperCase(); cellName = cellName.toUpperCase();
return get(getRow(cellName), getCol(cellName)); return get(getRow(cellName)-1, getCol(cellName)-1);
} }
public String getCellName(int row, int col) { public String getCellName(int row, int col) {
@ -70,7 +70,7 @@ public class Spreadsheet {
public void put(String cellName, String value) { public void put(String cellName, String value) {
cellName = cellName.toUpperCase(); cellName = cellName.toUpperCase();
put(getRow(cellName), getCol(cellName), value); put(getRow(cellName)-1, getCol(cellName)-1, value);
} }
private int getCol(String cellName) { private int getCol(String cellName) {
@ -306,10 +306,10 @@ public class Spreadsheet {
Arrays.fill(frequency,1); Arrays.fill(frequency,1);
ArrayList<Double> relativeFrequency = new ArrayList<>(); ArrayList<Double> relativeFrequency = new ArrayList<>();
double mem = 0; double mem = 0;
System.out.println(cellNames);
for(int i = 0; i< cellNames.size(); i++) { for(int i = 0; i< cellNames.size(); i++) {
for(int t = 0; t<cellNames.size(); t++){ for(int t = 0; t<cellNames.size(); t++){
if(!((get(cellNames.get(i)).isEmpty())&&(get(cellNames.get(t)).isEmpty()))&&(t!=i)&&(Double.parseDouble(get(cellNames.get(i))))==(Double.parseDouble(get(cellNames.get(t))))){ if((t!=i)&&(!get(cellNames.get(i)).isEmpty())&&(get(cellNames.get(i)).equals(get(cellNames.get(t))))){
cellNames.remove(t); cellNames.remove(t);
frequency[i] ++; frequency[i] ++;
t = 0; t = 0;
@ -317,10 +317,11 @@ public class Spreadsheet {
} }
} }
//delete all duplicates //delete all duplicates
System.out.println(cellNames);
for(int i = 0; i< cellNames.size(); i++) for(int i = 0; i< cellNames.size(); i++)
relativeFrequency.add(i,frequency[i]/copyCellNames.size()); relativeFrequency.add(i,frequency[i]/copyCellNames.size());
System.out.println(relativeFrequency);
System.out.println(avg);
if(get(cellNames.get(0)).isEmpty()) if(get(cellNames.get(0)).isEmpty())
mem = ((0 - avg)*(0 - avg)) mem = ((0 - avg)*(0 - avg))
@ -423,13 +424,13 @@ public class Spreadsheet {
private long evaluateOperator(long result, long currentOperand, String currentOperator) { private long evaluateOperator(long result, long currentOperand, String currentOperator) {
switch (currentOperator) { switch (currentOperator) {
case "+": case "+":
return result + currentOperand; return (result + currentOperand);
case "-": case "-":
return result - currentOperand; return (result - currentOperand);
case "*": case "*":
return result * currentOperand; return (result * currentOperand);
case "/": case "/":
return result / currentOperand; return (result / currentOperand);
default: default:
throw new IllegalArgumentException("Invalid operator: " + currentOperator); throw new IllegalArgumentException("Invalid operator: " + currentOperator);
} }