DecimalFormat implementiert und bug fixes

This commit is contained in:
2021-04-19 09:30:14 +02:00
parent 8debe58032
commit 120a36735a

View File

@@ -1,5 +1,5 @@
import java.util.Scanner; import java.util.Scanner;
import java.text.DecimalFormat;
/** /**
* Hauptklasse des Projekts * Hauptklasse des Projekts
*/ */
@@ -44,7 +44,7 @@ public class Rechenmaschine {
} }
run(); run();
System.out.println("Ergebnis der Ausführung: " + result);
} }
public boolean scanne( String pEingabe ) { public boolean scanne( String pEingabe ) {
@@ -292,9 +292,13 @@ public class Rechenmaschine {
return false; return false;
} else { } else {
tokenlist.toLast(); tokenlist.toLast();
if (tokenlist.hasAccess()) {
if (!tokenlist.getContent().getToken().equals(")")) { if (!tokenlist.getContent().getToken().equals(")")) {
tokenlist.append(new Token("OPERAND", currentToken.toString())); tokenlist.append(new Token("OPERAND", currentToken.toString()));
return true; }
} else {
tokenlist.append(new Token("OPERAND", currentToken.toString()));
} }
return true; return true;
} }
@@ -438,7 +442,11 @@ public class Rechenmaschine {
//newTokenlist wird ausgerechnet //newTokenlist wird ausgerechnet
berechnet = berechne(newTokenlist); berechnet = berechne(newTokenlist);
//und in die Tokenliste eingefügt //und in die Tokenliste eingefügt
if (pList.hasAccess()) {
pList.insert(new Token("OPERAND", String.valueOf(berechnet))); pList.insert(new Token("OPERAND", String.valueOf(berechnet)));
} else {
pList.append(new Token("OPERAND", String.valueOf(berechnet)));
}
newTokenlist = new List<Token>(); newTokenlist = new List<Token>();
//hier wurde nun 1 klammer gelöst //hier wurde nun 1 klammer gelöst
} }
@@ -505,9 +513,10 @@ public class Rechenmaschine {
public void run() { public void run() {
klammerRegel(tokenlist); klammerRegel(tokenlist);
punktVorStrich(tokenlist); punktVorStrich(tokenlist);
result=berechne(tokenlist); double result=berechne(tokenlist);
DecimalFormat format = new DecimalFormat("#,##0.####");
String resultString=format.format(result);
System.out.println("Ergebnis der Ausführung: " + resultString);
} }
} }