1
0
Fork 0

improving previous written code

main
ERANZER 2024-01-05 18:42:21 +01:00
parent e8114209f2
commit 7f44b09aa4
3 changed files with 26 additions and 26 deletions

6
.classpath 100644
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="Axel/src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

17
.project 100644
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>PR1-Spreadsheet</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -68,10 +68,7 @@ public class Spreadsheet {
}
private int getRow(String cellName) {
if(cellName.length()==3)
return Integer.parseInt((cellName.charAt(1)+"")+(cellName.charAt(2)+""))-1;
else
return cellName.charAt(1) - '1';
return Integer.parseInt(cellName.substring(1))-1;
}
// -----
@ -164,18 +161,8 @@ public class Spreadsheet {
*/
private long sum(String startCellName, String endCellName) {
int sum=0;
int startCellRow;
int endCellRow;
if(startCellName.length()==3)
startCellRow=Integer.parseInt((startCellName.charAt(1)+"")+(startCellName.charAt(2)+""))-1;
else
startCellRow=startCellName.charAt(1)-'1';
if(endCellName.length()==3)
endCellRow=Integer.parseInt((endCellName.charAt(1)+"")+(endCellName.charAt(2)+""))-1;
else
endCellRow=endCellName.charAt(1)-'1';
for(int i=startCellName.charAt(0)-'A'; i<=endCellName.charAt(0)-'A'; i++) {
for(int j=startCellRow; j<=endCellRow; j++) {
for(int j=Integer.parseInt(startCellName.substring(1))-1; j<=Integer.parseInt(endCellName.substring(1))-1; j++) {
if(cells[j][i].isEmpty()) {
continue;
}
@ -186,18 +173,8 @@ public class Spreadsheet {
}
private long product(String startCellName, String endCellName) {
int product=1;
int startCellRow;
int endCellRow;
if(startCellName.length()==3)
startCellRow=Integer.parseInt((startCellName.charAt(1)+"")+(startCellName.charAt(2)+""))-1;
else
startCellRow=startCellName.charAt(1)-'1';
if(endCellName.length()==3)
endCellRow=Integer.parseInt((endCellName.charAt(1)+"")+(endCellName.charAt(2)+""))-1;
else
endCellRow=endCellName.charAt(1)-'1';
for(int i=startCellName.charAt(0)-'A'; i<=endCellName.charAt(0)-'A'; i++) {
for(int j=startCellRow; j<=endCellRow; j++) {
for(int j=Integer.parseInt(startCellName.substring(1))-1; j<=Integer.parseInt(endCellName.substring(1))-1; j++) {
if(cells[j][i].isEmpty()) {
return 0;
}