forked from IF-LK-2020/rechenmaschine
DecimalFormat implementiert und bug fixes
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
/**
|
||||
* Hauptklasse des Projekts
|
||||
*/
|
||||
@@ -44,7 +44,7 @@ public class Rechenmaschine {
|
||||
}
|
||||
|
||||
run();
|
||||
System.out.println("Ergebnis der Ausführung: " + result);
|
||||
|
||||
}
|
||||
|
||||
public boolean scanne( String pEingabe ) {
|
||||
@@ -292,9 +292,13 @@ public class Rechenmaschine {
|
||||
return false;
|
||||
} else {
|
||||
tokenlist.toLast();
|
||||
|
||||
if (tokenlist.hasAccess()) {
|
||||
if (!tokenlist.getContent().getToken().equals(")")) {
|
||||
tokenlist.append(new Token("OPERAND", currentToken.toString()));
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
tokenlist.append(new Token("OPERAND", currentToken.toString()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -438,7 +442,11 @@ public class Rechenmaschine {
|
||||
//newTokenlist wird ausgerechnet
|
||||
berechnet = berechne(newTokenlist);
|
||||
//und in die Tokenliste eingefügt
|
||||
if (pList.hasAccess()) {
|
||||
pList.insert(new Token("OPERAND", String.valueOf(berechnet)));
|
||||
} else {
|
||||
pList.append(new Token("OPERAND", String.valueOf(berechnet)));
|
||||
}
|
||||
newTokenlist = new List<Token>();
|
||||
//hier wurde nun 1 klammer gelöst
|
||||
}
|
||||
@@ -505,9 +513,10 @@ public class Rechenmaschine {
|
||||
public void run() {
|
||||
klammerRegel(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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user