package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf

package Chapter_20; import ToolKit.PostfixNotation; import javafx.application.Application; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.BorderPane; import javafx.scene.layout.HBox; import javafx.stage.Stage; import java.util.ArrayList; import java.util.Stack; public class Exercise_13 extends Application { int[] validNumbers = new int[4]; @Override public void start(Stage primaryStage) { // Top pane Button btRefresh = new Button(\"Shuffle\"); Label lblStatus = new Label(\"\"); HBox topPane = new HBox(lblStatus, btRefresh); topPane.setAlignment(Pos.BASELINE_RIGHT); topPane.setSpacing(10); // Center Pane HBox centerPane = new HBox(); centerPane.setAlignment(Pos.CENTER); centerPane.setSpacing(10); centerPane.setPadding(new Insets(10)); // set first 4 random cards setRandomCards(centerPane); // Bottom pane TextField tfExpression = new TextField(); Label lblExpression = new Label(\"Enter an expression:\"); Button btVerify = new Button(\"Verify\"); HBox bottomPane = new HBox(10, lblExpression, tfExpression, btVerify); // Container Pane BorderPane borderPane = new BorderPane(); borderPane.setPadding(new Insets(10)); borderPane.setTop(topPane); borderPane.setCenter(centerPane); borderPane.setBottom(bottomPane); // Listeners btRefresh.setOnAction(e -> { lblStatus.setText(\"\"); setRandomCards(centerPane); }); btVerify.setOnAction(e -> { String expression = tfExpression.getText(); if (isValid(expression) && isCorrect(expression)) { lblStatus.setText(\"Good job! \" + expression + \" = 24\"); } else { lblStatus.setText(\"Invalid Expression\"); } }); Scene scene = new Scene(borderPane); primaryStage.setTitle(\"4 Random Cards\"); primaryStage.setScene(scene); primaryStage.show(); // Debug } private void setRandomCards(HBox pane) { boolean[] usedCards = new boolean[52]; // choose 4 random distinct cards from the deck int count = 0; pane.getChildren().clear(); while (count < 4) { int card = (int) (Math.random() * 52); if (!usedCards[card]) { usedCards[card] = true; pane.getChildren().add(new ImageView(new Image(\"image/card/\" + (++card) + \".png\"))); int value = card % 13; validNumbers[count] = (value == 0) ? 13 : value; count++; } } } private static boolean isOperator(char ch) { return (ch == \'(\' || ch == \')\' || isArithmeticOperator(ch)); } private static boolean isArithmeticOperator(char ch) { return (ch == \'/\' || ch == \'+\' || ch == \'-\' || ch == \'*\'); } private static String[] separateExpression(String s) { ArrayList tokens = new ArrayList<>(30); char[] chars = s.toCharArray(); String numBuffer = \"\"; for (char ch : chars) { if (isOperator(ch)) { if (numBuffer.length() > 0) { tokens.add(numBuffer); numBuffer = \"\"; } tokens.add(ch + \"\"); } else { if (ch != \' \') numBuffer += ch; } } if (numBuffe.

package Chapter_20;
import ToolKit.PostfixNotation;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import java.util.ArrayList;
import java.util.Stack;
public class Exercise_13 extends Application {
int[] validNumbers = new int[4];
@Override
public void start(Stage primaryStage) {
// Top pane
Button btRefresh = new Button("Shuffle");
Label lblStatus = new Label("");
HBox topPane = new HBox(lblStatus, btRefresh);
topPane.setAlignment(Pos.BASELINE_RIGHT);
topPane.setSpacing(10);
// Center Pane
HBox centerPane = new HBox();
centerPane.setAlignment(Pos.CENTER);
centerPane.setSpacing(10);
centerPane.setPadding(new Insets(10));
// set first 4 random cards
setRandomCards(centerPane);
// Bottom pane
TextField tfExpression = new TextField();
Label lblExpression = new Label("Enter an expression:");
Button btVerify = new Button("Verify");
HBox bottomPane = new HBox(10, lblExpression, tfExpression, btVerify);
// Container Pane
BorderPane borderPane = new BorderPane();
borderPane.setPadding(new Insets(10));
borderPane.setTop(topPane);
borderPane.setCenter(centerPane);
borderPane.setBottom(bottomPane);
// Listeners
btRefresh.setOnAction(e -> {
lblStatus.setText("");
setRandomCards(centerPane);
});
btVerify.setOnAction(e -> {
String expression = tfExpression.getText();
if (isValid(expression) && isCorrect(expression)) {
lblStatus.setText("Good job! " + expression + " = 24");
} else {
lblStatus.setText("Invalid Expression");
}
});
Scene scene = new Scene(borderPane);
primaryStage.setTitle("4 Random Cards");
primaryStage.setScene(scene);
primaryStage.show();
// Debug
}
private void setRandomCards(HBox pane) {
boolean[] usedCards = new boolean[52];
// choose 4 random distinct cards from the deck
int count = 0;
pane.getChildren().clear();
while (count < 4) {
int card = (int) (Math.random() * 52);
if (!usedCards[card]) {
usedCards[card] = true;
pane.getChildren().add(new ImageView(new Image("image/card/" + (++card) +
".png")));
int value = card % 13;
validNumbers[count] = (value == 0) ? 13 : value;
count++;
}
}
}
private static boolean isOperator(char ch) {
return (ch == '(' ||
ch == ')' ||
isArithmeticOperator(ch));
}
private static boolean isArithmeticOperator(char ch) {
return (ch == '/' ||
ch == '+' ||
ch == '-' ||
ch == '*');
}
private static String[] separateExpression(String s) {
ArrayList tokens = new ArrayList<>(30);
char[] chars = s.toCharArray();
String numBuffer = "";
for (char ch : chars) {
if (isOperator(ch)) {
if (numBuffer.length() > 0) {
tokens.add(numBuffer);
numBuffer = "";
}
tokens.add(ch + "");
} else {
if (ch != ' ')
numBuffer += ch;
}
}
if (numBuffer.length() > 0) {
tokens.add(numBuffer);
}
return tokens.toArray(new String[tokens.size()]);
}
private boolean isCorrect(String infixExpression) {
return (24 == PostfixNotation.evaluateInfix(infixExpression));
}
private boolean isValid(String infixExpression) {
String[] tokens = separateExpression(infixExpression);
// Check is tokens contains any letters
for (String s : tokens) {
for (char ch : s.toCharArray()) {
if (Character.isAlphabetic(ch))
return false;
}
}
Stack operands = new Stack<>();
for (String token : tokens) {
if (!isOperator(token.charAt(0))) {
operands.push(Integer.parseInt(token));
}
}
if (operands.size() != validNumbers.length)
return false;
// Put validNumbers into a buffer ArrayList
ArrayList validOperands = new ArrayList<>();
for (int num : validNumbers) {
validOperands.add(num);
}
for (int i = 0; i < validOperands.size(); i++) {
int number = operands.pop();
int index = validOperands.indexOf(number);
if (index != -1) {
validOperands.remove(index);
} else {
return false;
}
}
return true;
}
public static void main(String[] args) {
Application.launch(args);
}
}
import ToolKit.PostfixNotation;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import java.util.ArrayList;
import java.util.Stack;
public class Exercise_13 extends Application {
int[] validNumbers = new int[4];
@Override
public void start(Stage primaryStage) {
// Top pane
Button btRefresh = new Button("Shuffle");
Label lblStatus = new Label("");
HBox topPane = new HBox(lblStatus, btRefresh);
topPane.setAlignment(Pos.BASELINE_RIGHT);
topPane.setSpacing(10);
// Center Pane
HBox centerPane = new HBox();
centerPane.setAlignment(Pos.CENTER);
centerPane.setSpacing(10);
centerPane.setPadding(new Insets(10));
// set first 4 random cards
setRandomCards(centerPane);
// Bottom pane
TextField tfExpression = new TextField();
Label lblExpression = new Label("Enter an expression:");
Button btVerify = new Button("Verify");
HBox bottomPane = new HBox(10, lblExpression, tfExpression, btVerify);
// Container Pane
BorderPane borderPane = new BorderPane();
borderPane.setPadding(new Insets(10));
borderPane.setTop(topPane);
borderPane.setCenter(centerPane);
borderPane.setBottom(bottomPane);
// Listeners
btRefresh.setOnAction(e -> {
lblStatus.setText("");
setRandomCards(centerPane);
});
btVerify.setOnAction(e -> {
String expression = tfExpression.getText();
if (isValid(expression) && isCorrect(expression)) {
lblStatus.setText("Good job! " + expression + " = 24");
} else {
lblStatus.setText("Invalid Expression");
}
});
Scene scene = new Scene(borderPane);
primaryStage.setTitle("4 Random Cards");
primaryStage.setScene(scene);
primaryStage.show();
// Debug
}
private void setRandomCards(HBox pane) {
boolean[] usedCards = new boolean[52];
// choose 4 random distinct cards from the deck
int count = 0;
pane.getChildren().clear();
while (count < 4) {
int card = (int) (Math.random() * 52);
if (!usedCards[card]) {
usedCards[card] = true;
pane.getChildren().add(new ImageView(new Image("image/card/" + (++card) +
".png")));
int value = card % 13;
validNumbers[count] = (value == 0) ? 13 : value;
count++;
}
}
}
private static boolean isOperator(char ch) {
return (ch == '(' ||
ch == ')' ||
isArithmeticOperator(ch));
}
private static boolean isArithmeticOperator(char ch) {
return (ch == '/' ||
ch == '+' ||
ch == '-' ||
ch == '*');
}
private static String[] separateExpression(String s) {
ArrayList tokens = new ArrayList<>(30);
char[] chars = s.toCharArray();
String numBuffer = "";
for (char ch : chars) {
if (isOperator(ch)) {
if (numBuffer.length() > 0) {
tokens.add(numBuffer);
numBuffer = "";
}
tokens.add(ch + "");
} else {
if (ch != ' ')
numBuffer += ch;
}
}
if (numBuffer.length() > 0) {
tokens.add(numBuffer);
}
return tokens.toArray(new String[tokens.size()]);
}
private boolean isCorrect(String infixExpression) {
return (24 == PostfixNotation.evaluateInfix(infixExpression));
}
private boolean isValid(String infixExpression) {
String[] tokens = separateExpression(infixExpression);
// Check is tokens contains any letters
for (String s : tokens) {
for (char ch : s.toCharArray()) {
if (Character.isAlphabetic(ch))
return false;
}
}
Stack operands = new Stack<>();
for (String token : tokens) {
if (!isOperator(token.charAt(0))) {
operands.push(Integer.parseInt(token));
}
}
if (operands.size() != validNumbers.length)
return false;
// Put validNumbers into a buffer ArrayList
ArrayList validOperands = new ArrayList<>();
for (int num : validNumbers) {
validOperands.add(num);
}
for (int i = 0; i < validOperands.size(); i++) {
int number = operands.pop();
int index = validOperands.indexOf(number);
if (index != -1) {
validOperands.remove(index);
} else {
return false;
}
}
return true;
}
public static void main(String[] args) {
Application.launch(args);
}
}
Solution
package Chapter_20;
import ToolKit.PostfixNotation;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import java.util.ArrayList;
import java.util.Stack;
public class Exercise_13 extends Application {
int[] validNumbers = new int[4];
@Override
public void start(Stage primaryStage) {
// Top pane
Button btRefresh = new Button("Shuffle");
Label lblStatus = new Label("");
HBox topPane = new HBox(lblStatus, btRefresh);
topPane.setAlignment(Pos.BASELINE_RIGHT);
topPane.setSpacing(10);
// Center Pane
HBox centerPane = new HBox();
centerPane.setAlignment(Pos.CENTER);
centerPane.setSpacing(10);
centerPane.setPadding(new Insets(10));
// set first 4 random cards
setRandomCards(centerPane);
// Bottom pane
TextField tfExpression = new TextField();
Label lblExpression = new Label("Enter an expression:");
Button btVerify = new Button("Verify");
HBox bottomPane = new HBox(10, lblExpression, tfExpression, btVerify);
// Container Pane
BorderPane borderPane = new BorderPane();
borderPane.setPadding(new Insets(10));
borderPane.setTop(topPane);
borderPane.setCenter(centerPane);
borderPane.setBottom(bottomPane);
// Listeners
btRefresh.setOnAction(e -> {
lblStatus.setText("");
setRandomCards(centerPane);
});
btVerify.setOnAction(e -> {
String expression = tfExpression.getText();
if (isValid(expression) && isCorrect(expression)) {
lblStatus.setText("Good job! " + expression + " = 24");
} else {
lblStatus.setText("Invalid Expression");
}
});
Scene scene = new Scene(borderPane);
primaryStage.setTitle("4 Random Cards");
primaryStage.setScene(scene);
primaryStage.show();
// Debug
}
private void setRandomCards(HBox pane) {
boolean[] usedCards = new boolean[52];
// choose 4 random distinct cards from the deck
int count = 0;
pane.getChildren().clear();
while (count < 4) {
int card = (int) (Math.random() * 52);
if (!usedCards[card]) {
usedCards[card] = true;
pane.getChildren().add(new ImageView(new Image("image/card/" + (++card) +
".png")));
int value = card % 13;
validNumbers[count] = (value == 0) ? 13 : value;
count++;
}
}
}
private static boolean isOperator(char ch) {
return (ch == '(' ||
ch == ')' ||
isArithmeticOperator(ch));
}
private static boolean isArithmeticOperator(char ch) {
return (ch == '/' ||
ch == '+' ||
ch == '-' ||
ch == '*');
}
private static String[] separateExpression(String s) {
ArrayList tokens = new ArrayList<>(30);
char[] chars = s.toCharArray();
String numBuffer = "";
for (char ch : chars) {
if (isOperator(ch)) {
if (numBuffer.length() > 0) {
tokens.add(numBuffer);
numBuffer = "";
}
tokens.add(ch + "");
} else {
if (ch != ' ')
numBuffer += ch;
}
}
if (numBuffer.length() > 0) {
tokens.add(numBuffer);
}
return tokens.toArray(new String[tokens.size()]);
}
private boolean isCorrect(String infixExpression) {
return (24 == PostfixNotation.evaluateInfix(infixExpression));
}
private boolean isValid(String infixExpression) {
String[] tokens = separateExpression(infixExpression);
// Check is tokens contains any letters
for (String s : tokens) {
for (char ch : s.toCharArray()) {
if (Character.isAlphabetic(ch))
return false;
}
}
Stack operands = new Stack<>();
for (String token : tokens) {
if (!isOperator(token.charAt(0))) {
operands.push(Integer.parseInt(token));
}
}
if (operands.size() != validNumbers.length)
return false;
// Put validNumbers into a buffer ArrayList
ArrayList validOperands = new ArrayList<>();
for (int num : validNumbers) {
validOperands.add(num);
}
for (int i = 0; i < validOperands.size(); i++) {
int number = operands.pop();
int index = validOperands.indexOf(number);
if (index != -1) {
validOperands.remove(index);
} else {
return false;
}
}
return true;
}
public static void main(String[] args) {
Application.launch(args);
}
}
import ToolKit.PostfixNotation;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import java.util.ArrayList;
import java.util.Stack;
public class Exercise_13 extends Application {
int[] validNumbers = new int[4];
@Override
public void start(Stage primaryStage) {
// Top pane
Button btRefresh = new Button("Shuffle");
Label lblStatus = new Label("");
HBox topPane = new HBox(lblStatus, btRefresh);
topPane.setAlignment(Pos.BASELINE_RIGHT);
topPane.setSpacing(10);
// Center Pane
HBox centerPane = new HBox();
centerPane.setAlignment(Pos.CENTER);
centerPane.setSpacing(10);
centerPane.setPadding(new Insets(10));
// set first 4 random cards
setRandomCards(centerPane);
// Bottom pane
TextField tfExpression = new TextField();
Label lblExpression = new Label("Enter an expression:");
Button btVerify = new Button("Verify");
HBox bottomPane = new HBox(10, lblExpression, tfExpression, btVerify);
// Container Pane
BorderPane borderPane = new BorderPane();
borderPane.setPadding(new Insets(10));
borderPane.setTop(topPane);
borderPane.setCenter(centerPane);
borderPane.setBottom(bottomPane);
// Listeners
btRefresh.setOnAction(e -> {
lblStatus.setText("");
setRandomCards(centerPane);
});
btVerify.setOnAction(e -> {
String expression = tfExpression.getText();
if (isValid(expression) && isCorrect(expression)) {
lblStatus.setText("Good job! " + expression + " = 24");
} else {
lblStatus.setText("Invalid Expression");
}
});
Scene scene = new Scene(borderPane);
primaryStage.setTitle("4 Random Cards");
primaryStage.setScene(scene);
primaryStage.show();
// Debug
}
private void setRandomCards(HBox pane) {
boolean[] usedCards = new boolean[52];
// choose 4 random distinct cards from the deck
int count = 0;
pane.getChildren().clear();
while (count < 4) {
int card = (int) (Math.random() * 52);
if (!usedCards[card]) {
usedCards[card] = true;
pane.getChildren().add(new ImageView(new Image("image/card/" + (++card) +
".png")));
int value = card % 13;
validNumbers[count] = (value == 0) ? 13 : value;
count++;
}
}
}
private static boolean isOperator(char ch) {
return (ch == '(' ||
ch == ')' ||
isArithmeticOperator(ch));
}
private static boolean isArithmeticOperator(char ch) {
return (ch == '/' ||
ch == '+' ||
ch == '-' ||
ch == '*');
}
private static String[] separateExpression(String s) {
ArrayList tokens = new ArrayList<>(30);
char[] chars = s.toCharArray();
String numBuffer = "";
for (char ch : chars) {
if (isOperator(ch)) {
if (numBuffer.length() > 0) {
tokens.add(numBuffer);
numBuffer = "";
}
tokens.add(ch + "");
} else {
if (ch != ' ')
numBuffer += ch;
}
}
if (numBuffer.length() > 0) {
tokens.add(numBuffer);
}
return tokens.toArray(new String[tokens.size()]);
}
private boolean isCorrect(String infixExpression) {
return (24 == PostfixNotation.evaluateInfix(infixExpression));
}
private boolean isValid(String infixExpression) {
String[] tokens = separateExpression(infixExpression);
// Check is tokens contains any letters
for (String s : tokens) {
for (char ch : s.toCharArray()) {
if (Character.isAlphabetic(ch))
return false;
}
}
Stack operands = new Stack<>();
for (String token : tokens) {
if (!isOperator(token.charAt(0))) {
operands.push(Integer.parseInt(token));
}
}
if (operands.size() != validNumbers.length)
return false;
// Put validNumbers into a buffer ArrayList
ArrayList validOperands = new ArrayList<>();
for (int num : validNumbers) {
validOperands.add(num);
}
for (int i = 0; i < validOperands.size(); i++) {
int number = operands.pop();
int index = validOperands.indexOf(number);
if (index != -1) {
validOperands.remove(index);
} else {
return false;
}
}
return true;
}
public static void main(String[] args) {
Application.launch(args);
}
}

Recomendados

import java.util.ArrayList; import java.util.Scanner; public class .pdf por
  import java.util.ArrayList; import java.util.Scanner;  public class .pdf  import java.util.ArrayList; import java.util.Scanner;  public class .pdf
import java.util.ArrayList; import java.util.Scanner; public class .pdfinfo30292
8 vistas3 diapositivas
import java.util.;public class infixPostfix{Int i,j;char po.pdf por
import java.util.;public class infixPostfix{Int i,j;char po.pdfimport java.util.;public class infixPostfix{Int i,j;char po.pdf
import java.util.;public class infixPostfix{Int i,j;char po.pdfapnashop1
2 vistas7 diapositivas
Data structure por
Data structureData structure
Data structureMarkustec
210 vistas6 diapositivas
Java Programming Below is the lexer shank and token files .pdf por
Java Programming Below is the lexer shank and token files .pdfJava Programming Below is the lexer shank and token files .pdf
Java Programming Below is the lexer shank and token files .pdfmail354931
4 vistas5 diapositivas
Improving the java type system por
Improving the java type systemImproving the java type system
Improving the java type systemJoão Loff
170 vistas12 diapositivas
CBSE Class XII Comp sc practical file por
CBSE Class XII Comp sc practical fileCBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical filePranav Ghildiyal
2.8K vistas48 diapositivas

Más contenido relacionado

Similar a   package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf

The java language cheat sheet por
The java language cheat sheetThe java language cheat sheet
The java language cheat sheetanand_study
36 vistas2 diapositivas
H base programming por
H base programmingH base programming
H base programmingMuthusamy Manigandan
769 vistas20 diapositivas
Queue Implementation Using Array & Linked List por
Queue Implementation Using Array & Linked ListQueue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListPTCL
5.6K vistas16 diapositivas
Below are the lexer- shank- and token files- There are errors in the l.pdf por
Below are the lexer- shank- and token files- There are errors in the l.pdfBelow are the lexer- shank- and token files- There are errors in the l.pdf
Below are the lexer- shank- and token files- There are errors in the l.pdfAdrianj6tHamiltonn
2 vistas8 diapositivas
#includeiostream#includecctypeusing namespace std;class .docx por
#includeiostream#includecctypeusing namespace std;class .docx#includeiostream#includecctypeusing namespace std;class .docx
#includeiostream#includecctypeusing namespace std;class .docxkatherncarlyle
2 vistas3 diapositivas
SDC - Einführung in Scala por
SDC - Einführung in ScalaSDC - Einführung in Scala
SDC - Einführung in ScalaChristian Baranowski
1.2K vistas73 diapositivas

Similar a   package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf(20)

The java language cheat sheet por anand_study
The java language cheat sheetThe java language cheat sheet
The java language cheat sheet
anand_study36 vistas
Queue Implementation Using Array & Linked List por PTCL
Queue Implementation Using Array & Linked ListQueue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked List
PTCL5.6K vistas
Below are the lexer- shank- and token files- There are errors in the l.pdf por Adrianj6tHamiltonn
Below are the lexer- shank- and token files- There are errors in the l.pdfBelow are the lexer- shank- and token files- There are errors in the l.pdf
Below are the lexer- shank- and token files- There are errors in the l.pdf
#includeiostream#includecctypeusing namespace std;class .docx por katherncarlyle
#includeiostream#includecctypeusing namespace std;class .docx#includeiostream#includecctypeusing namespace std;class .docx
#includeiostream#includecctypeusing namespace std;class .docx
katherncarlyle2 vistas
Dip into Coroutines - KTUG Munich 202303 por Alex Semin
Dip into Coroutines - KTUG Munich 202303Dip into Coroutines - KTUG Munich 202303
Dip into Coroutines - KTUG Munich 202303
Alex Semin33 vistas
I still keep getting this error message from the following code. I h.pdf por allurafashions98
I still keep getting this error message from the following code. I h.pdfI still keep getting this error message from the following code. I h.pdf
I still keep getting this error message from the following code. I h.pdf
allurafashions982 vistas
E15.16 Add a (remainder) operator to the expression calculator of .pdf por fastechsrv
E15.16 Add a  (remainder) operator to the expression calculator of .pdfE15.16 Add a  (remainder) operator to the expression calculator of .pdf
E15.16 Add a (remainder) operator to the expression calculator of .pdf
fastechsrv2 vistas
It is the main program that implement the min(), max(), floor(), cei.pdf por annaindustries
It is the main program that implement the min(), max(), floor(), cei.pdfIt is the main program that implement the min(), max(), floor(), cei.pdf
It is the main program that implement the min(), max(), floor(), cei.pdf
annaindustries4 vistas
Calculator code with scientific functions in java por Amna Nawazish
Calculator code with scientific functions in java Calculator code with scientific functions in java
Calculator code with scientific functions in java
Amna Nawazish79 vistas
AngularJS Testing por Eyal Vardi
AngularJS TestingAngularJS Testing
AngularJS Testing
Eyal Vardi8.6K vistas
JBUG 11 - Scala For Java Programmers por Tikal Knowledge
JBUG 11 - Scala For Java ProgrammersJBUG 11 - Scala For Java Programmers
JBUG 11 - Scala For Java Programmers
Tikal Knowledge1K vistas

Más de sudhirchourasia86

When counting electrons for the purpose of drawin.pdf por
                     When counting electrons for the purpose of drawin.pdf                     When counting electrons for the purpose of drawin.pdf
When counting electrons for the purpose of drawin.pdfsudhirchourasia86
3 vistas1 diapositiva
the distance between players is the hypotenuse of.pdf por
                     the distance between players is the hypotenuse of.pdf                     the distance between players is the hypotenuse of.pdf
the distance between players is the hypotenuse of.pdfsudhirchourasia86
2 vistas1 diapositiva
rs 1,00,000 .pdf por
                     rs 1,00,000                                      .pdf                     rs 1,00,000                                      .pdf
rs 1,00,000 .pdfsudhirchourasia86
6 vistas1 diapositiva
Propyl benzoate .pdf por
                     Propyl benzoate                                  .pdf                     Propyl benzoate                                  .pdf
Propyl benzoate .pdfsudhirchourasia86
2 vistas1 diapositiva
O3, SO3, SO2 .pdf por
                     O3, SO3, SO2                                     .pdf                     O3, SO3, SO2                                     .pdf
O3, SO3, SO2 .pdfsudhirchourasia86
10 vistas1 diapositiva
nitrogen is limiting reagent .pdf por
                     nitrogen is limiting reagent                     .pdf                     nitrogen is limiting reagent                     .pdf
nitrogen is limiting reagent .pdfsudhirchourasia86
2 vistas1 diapositiva

Más de sudhirchourasia86(20)

When counting electrons for the purpose of drawin.pdf por sudhirchourasia86
                     When counting electrons for the purpose of drawin.pdf                     When counting electrons for the purpose of drawin.pdf
When counting electrons for the purpose of drawin.pdf
the distance between players is the hypotenuse of.pdf por sudhirchourasia86
                     the distance between players is the hypotenuse of.pdf                     the distance between players is the hypotenuse of.pdf
the distance between players is the hypotenuse of.pdf
highest frequency = shortest wavelength = closest.pdf por sudhirchourasia86
                     highest frequency = shortest wavelength = closest.pdf                     highest frequency = shortest wavelength = closest.pdf
highest frequency = shortest wavelength = closest.pdf
he bromine would be opposite(para to) the isoprop.pdf por sudhirchourasia86
                     he bromine would be opposite(para to) the isoprop.pdf                     he bromine would be opposite(para to) the isoprop.pdf
he bromine would be opposite(para to) the isoprop.pdf
d) in real gases there are attraction between m.pdf por sudhirchourasia86
                     d)   in real gases there are attraction between m.pdf                     d)   in real gases there are attraction between m.pdf
d) in real gases there are attraction between m.pdf
The answer is Rate = k[A]2Applying steady state approximation to i.pdf por sudhirchourasia86
The answer is Rate = k[A]2Applying steady state approximation to i.pdfThe answer is Rate = k[A]2Applying steady state approximation to i.pdf
The answer is Rate = k[A]2Applying steady state approximation to i.pdf
Wavelength = 656 nm = 656 x 10-9 mEnergy E = hc where h is Planc.pdf por sudhirchourasia86
Wavelength  = 656 nm = 656 x 10-9 mEnergy E = hc where h is Planc.pdfWavelength  = 656 nm = 656 x 10-9 mEnergy E = hc where h is Planc.pdf
Wavelength = 656 nm = 656 x 10-9 mEnergy E = hc where h is Planc.pdf
we know that (n X p) matrix when multilied with (p X m) matrix yeild.pdf por sudhirchourasia86
we know that (n X p) matrix when multilied with (p X m) matrix yeild.pdfwe know that (n X p) matrix when multilied with (p X m) matrix yeild.pdf
we know that (n X p) matrix when multilied with (p X m) matrix yeild.pdf
We have 2 variables Response variable = Final grade -- Quantit.pdf por sudhirchourasia86
We have 2 variables Response variable = Final grade -- Quantit.pdfWe have 2 variables Response variable = Final grade -- Quantit.pdf
We have 2 variables Response variable = Final grade -- Quantit.pdf

Último

Ch. 7 Political Participation and Elections.pptx por
Ch. 7 Political Participation and Elections.pptxCh. 7 Political Participation and Elections.pptx
Ch. 7 Political Participation and Elections.pptxRommel Regala
105 vistas11 diapositivas
REPRESENTATION - GAUNTLET.pptx por
REPRESENTATION - GAUNTLET.pptxREPRESENTATION - GAUNTLET.pptx
REPRESENTATION - GAUNTLET.pptxiammrhaywood
107 vistas26 diapositivas
Structure and Functions of Cell.pdf por
Structure and Functions of Cell.pdfStructure and Functions of Cell.pdf
Structure and Functions of Cell.pdfNithya Murugan
701 vistas10 diapositivas
ISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks Effectively por
ISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks EffectivelyISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks Effectively
ISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks EffectivelyPECB
598 vistas18 diapositivas
Jibachha publishing Textbook.docx por
Jibachha publishing Textbook.docxJibachha publishing Textbook.docx
Jibachha publishing Textbook.docxDrJibachhaSahVetphys
47 vistas14 diapositivas
CUNY IT Picciano.pptx por
CUNY IT Picciano.pptxCUNY IT Picciano.pptx
CUNY IT Picciano.pptxapicciano
54 vistas17 diapositivas

Último(20)

Ch. 7 Political Participation and Elections.pptx por Rommel Regala
Ch. 7 Political Participation and Elections.pptxCh. 7 Political Participation and Elections.pptx
Ch. 7 Political Participation and Elections.pptx
Rommel Regala105 vistas
REPRESENTATION - GAUNTLET.pptx por iammrhaywood
REPRESENTATION - GAUNTLET.pptxREPRESENTATION - GAUNTLET.pptx
REPRESENTATION - GAUNTLET.pptx
iammrhaywood107 vistas
Structure and Functions of Cell.pdf por Nithya Murugan
Structure and Functions of Cell.pdfStructure and Functions of Cell.pdf
Structure and Functions of Cell.pdf
Nithya Murugan701 vistas
ISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks Effectively por PECB
ISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks EffectivelyISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks Effectively
ISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks Effectively
PECB 598 vistas
CUNY IT Picciano.pptx por apicciano
CUNY IT Picciano.pptxCUNY IT Picciano.pptx
CUNY IT Picciano.pptx
apicciano54 vistas
11.28.23 Social Capital and Social Exclusion.pptx por mary850239
11.28.23 Social Capital and Social Exclusion.pptx11.28.23 Social Capital and Social Exclusion.pptx
11.28.23 Social Capital and Social Exclusion.pptx
mary850239304 vistas
Pharmaceutical Inorganic chemistry UNIT-V Radiopharmaceutical.pptx por Ms. Pooja Bhandare
Pharmaceutical Inorganic chemistry UNIT-V Radiopharmaceutical.pptxPharmaceutical Inorganic chemistry UNIT-V Radiopharmaceutical.pptx
Pharmaceutical Inorganic chemistry UNIT-V Radiopharmaceutical.pptx
Ms. Pooja Bhandare93 vistas
Classification of crude drugs.pptx por GayatriPatra14
Classification of crude drugs.pptxClassification of crude drugs.pptx
Classification of crude drugs.pptx
GayatriPatra1492 vistas
Use of Probiotics in Aquaculture.pptx por AKSHAY MANDAL
Use of Probiotics in Aquaculture.pptxUse of Probiotics in Aquaculture.pptx
Use of Probiotics in Aquaculture.pptx
AKSHAY MANDAL104 vistas
On Killing a Tree.pptx por AncyTEnglish
On Killing a Tree.pptxOn Killing a Tree.pptx
On Killing a Tree.pptx
AncyTEnglish66 vistas
Education and Diversity.pptx por DrHafizKosar
Education and Diversity.pptxEducation and Diversity.pptx
Education and Diversity.pptx
DrHafizKosar177 vistas

  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf

  • 1. package Chapter_20; import ToolKit.PostfixNotation; import javafx.application.Application; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.BorderPane; import javafx.scene.layout.HBox; import javafx.stage.Stage; import java.util.ArrayList; import java.util.Stack; public class Exercise_13 extends Application { int[] validNumbers = new int[4]; @Override public void start(Stage primaryStage) { // Top pane Button btRefresh = new Button("Shuffle"); Label lblStatus = new Label(""); HBox topPane = new HBox(lblStatus, btRefresh); topPane.setAlignment(Pos.BASELINE_RIGHT); topPane.setSpacing(10); // Center Pane HBox centerPane = new HBox(); centerPane.setAlignment(Pos.CENTER); centerPane.setSpacing(10); centerPane.setPadding(new Insets(10)); // set first 4 random cards setRandomCards(centerPane); // Bottom pane TextField tfExpression = new TextField();
  • 2. Label lblExpression = new Label("Enter an expression:"); Button btVerify = new Button("Verify"); HBox bottomPane = new HBox(10, lblExpression, tfExpression, btVerify); // Container Pane BorderPane borderPane = new BorderPane(); borderPane.setPadding(new Insets(10)); borderPane.setTop(topPane); borderPane.setCenter(centerPane); borderPane.setBottom(bottomPane); // Listeners btRefresh.setOnAction(e -> { lblStatus.setText(""); setRandomCards(centerPane); }); btVerify.setOnAction(e -> { String expression = tfExpression.getText(); if (isValid(expression) && isCorrect(expression)) { lblStatus.setText("Good job! " + expression + " = 24"); } else { lblStatus.setText("Invalid Expression"); } }); Scene scene = new Scene(borderPane); primaryStage.setTitle("4 Random Cards"); primaryStage.setScene(scene); primaryStage.show(); // Debug } private void setRandomCards(HBox pane) { boolean[] usedCards = new boolean[52]; // choose 4 random distinct cards from the deck int count = 0; pane.getChildren().clear(); while (count < 4) { int card = (int) (Math.random() * 52); if (!usedCards[card]) {
  • 3. usedCards[card] = true; pane.getChildren().add(new ImageView(new Image("image/card/" + (++card) + ".png"))); int value = card % 13; validNumbers[count] = (value == 0) ? 13 : value; count++; } } } private static boolean isOperator(char ch) { return (ch == '(' || ch == ')' || isArithmeticOperator(ch)); } private static boolean isArithmeticOperator(char ch) { return (ch == '/' || ch == '+' || ch == '-' || ch == '*'); } private static String[] separateExpression(String s) { ArrayList tokens = new ArrayList<>(30); char[] chars = s.toCharArray(); String numBuffer = ""; for (char ch : chars) { if (isOperator(ch)) { if (numBuffer.length() > 0) { tokens.add(numBuffer); numBuffer = ""; } tokens.add(ch + ""); } else { if (ch != ' ') numBuffer += ch; } }
  • 4. if (numBuffer.length() > 0) { tokens.add(numBuffer); } return tokens.toArray(new String[tokens.size()]); } private boolean isCorrect(String infixExpression) { return (24 == PostfixNotation.evaluateInfix(infixExpression)); } private boolean isValid(String infixExpression) { String[] tokens = separateExpression(infixExpression); // Check is tokens contains any letters for (String s : tokens) { for (char ch : s.toCharArray()) { if (Character.isAlphabetic(ch)) return false; } } Stack operands = new Stack<>(); for (String token : tokens) { if (!isOperator(token.charAt(0))) { operands.push(Integer.parseInt(token)); } } if (operands.size() != validNumbers.length) return false; // Put validNumbers into a buffer ArrayList ArrayList validOperands = new ArrayList<>(); for (int num : validNumbers) { validOperands.add(num); } for (int i = 0; i < validOperands.size(); i++) { int number = operands.pop(); int index = validOperands.indexOf(number); if (index != -1) { validOperands.remove(index); } else {
  • 5. return false; } } return true; } public static void main(String[] args) { Application.launch(args); } } import ToolKit.PostfixNotation; import javafx.application.Application; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.BorderPane; import javafx.scene.layout.HBox; import javafx.stage.Stage; import java.util.ArrayList; import java.util.Stack; public class Exercise_13 extends Application { int[] validNumbers = new int[4]; @Override public void start(Stage primaryStage) { // Top pane Button btRefresh = new Button("Shuffle"); Label lblStatus = new Label(""); HBox topPane = new HBox(lblStatus, btRefresh); topPane.setAlignment(Pos.BASELINE_RIGHT); topPane.setSpacing(10); // Center Pane HBox centerPane = new HBox();
  • 6. centerPane.setAlignment(Pos.CENTER); centerPane.setSpacing(10); centerPane.setPadding(new Insets(10)); // set first 4 random cards setRandomCards(centerPane); // Bottom pane TextField tfExpression = new TextField(); Label lblExpression = new Label("Enter an expression:"); Button btVerify = new Button("Verify"); HBox bottomPane = new HBox(10, lblExpression, tfExpression, btVerify); // Container Pane BorderPane borderPane = new BorderPane(); borderPane.setPadding(new Insets(10)); borderPane.setTop(topPane); borderPane.setCenter(centerPane); borderPane.setBottom(bottomPane); // Listeners btRefresh.setOnAction(e -> { lblStatus.setText(""); setRandomCards(centerPane); }); btVerify.setOnAction(e -> { String expression = tfExpression.getText(); if (isValid(expression) && isCorrect(expression)) { lblStatus.setText("Good job! " + expression + " = 24"); } else { lblStatus.setText("Invalid Expression"); } }); Scene scene = new Scene(borderPane); primaryStage.setTitle("4 Random Cards"); primaryStage.setScene(scene); primaryStage.show(); // Debug } private void setRandomCards(HBox pane) {
  • 7. boolean[] usedCards = new boolean[52]; // choose 4 random distinct cards from the deck int count = 0; pane.getChildren().clear(); while (count < 4) { int card = (int) (Math.random() * 52); if (!usedCards[card]) { usedCards[card] = true; pane.getChildren().add(new ImageView(new Image("image/card/" + (++card) + ".png"))); int value = card % 13; validNumbers[count] = (value == 0) ? 13 : value; count++; } } } private static boolean isOperator(char ch) { return (ch == '(' || ch == ')' || isArithmeticOperator(ch)); } private static boolean isArithmeticOperator(char ch) { return (ch == '/' || ch == '+' || ch == '-' || ch == '*'); } private static String[] separateExpression(String s) { ArrayList tokens = new ArrayList<>(30); char[] chars = s.toCharArray(); String numBuffer = ""; for (char ch : chars) { if (isOperator(ch)) { if (numBuffer.length() > 0) { tokens.add(numBuffer); numBuffer = "";
  • 8. } tokens.add(ch + ""); } else { if (ch != ' ') numBuffer += ch; } } if (numBuffer.length() > 0) { tokens.add(numBuffer); } return tokens.toArray(new String[tokens.size()]); } private boolean isCorrect(String infixExpression) { return (24 == PostfixNotation.evaluateInfix(infixExpression)); } private boolean isValid(String infixExpression) { String[] tokens = separateExpression(infixExpression); // Check is tokens contains any letters for (String s : tokens) { for (char ch : s.toCharArray()) { if (Character.isAlphabetic(ch)) return false; } } Stack operands = new Stack<>(); for (String token : tokens) { if (!isOperator(token.charAt(0))) { operands.push(Integer.parseInt(token)); } } if (operands.size() != validNumbers.length) return false; // Put validNumbers into a buffer ArrayList ArrayList validOperands = new ArrayList<>(); for (int num : validNumbers) { validOperands.add(num);
  • 9. } for (int i = 0; i < validOperands.size(); i++) { int number = operands.pop(); int index = validOperands.indexOf(number); if (index != -1) { validOperands.remove(index); } else { return false; } } return true; } public static void main(String[] args) { Application.launch(args); } } Solution package Chapter_20; import ToolKit.PostfixNotation; import javafx.application.Application; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.BorderPane; import javafx.scene.layout.HBox; import javafx.stage.Stage; import java.util.ArrayList; import java.util.Stack; public class Exercise_13 extends Application {
  • 10. int[] validNumbers = new int[4]; @Override public void start(Stage primaryStage) { // Top pane Button btRefresh = new Button("Shuffle"); Label lblStatus = new Label(""); HBox topPane = new HBox(lblStatus, btRefresh); topPane.setAlignment(Pos.BASELINE_RIGHT); topPane.setSpacing(10); // Center Pane HBox centerPane = new HBox(); centerPane.setAlignment(Pos.CENTER); centerPane.setSpacing(10); centerPane.setPadding(new Insets(10)); // set first 4 random cards setRandomCards(centerPane); // Bottom pane TextField tfExpression = new TextField(); Label lblExpression = new Label("Enter an expression:"); Button btVerify = new Button("Verify"); HBox bottomPane = new HBox(10, lblExpression, tfExpression, btVerify); // Container Pane BorderPane borderPane = new BorderPane(); borderPane.setPadding(new Insets(10)); borderPane.setTop(topPane); borderPane.setCenter(centerPane); borderPane.setBottom(bottomPane); // Listeners btRefresh.setOnAction(e -> { lblStatus.setText(""); setRandomCards(centerPane); }); btVerify.setOnAction(e -> { String expression = tfExpression.getText(); if (isValid(expression) && isCorrect(expression)) { lblStatus.setText("Good job! " + expression + " = 24");
  • 11. } else { lblStatus.setText("Invalid Expression"); } }); Scene scene = new Scene(borderPane); primaryStage.setTitle("4 Random Cards"); primaryStage.setScene(scene); primaryStage.show(); // Debug } private void setRandomCards(HBox pane) { boolean[] usedCards = new boolean[52]; // choose 4 random distinct cards from the deck int count = 0; pane.getChildren().clear(); while (count < 4) { int card = (int) (Math.random() * 52); if (!usedCards[card]) { usedCards[card] = true; pane.getChildren().add(new ImageView(new Image("image/card/" + (++card) + ".png"))); int value = card % 13; validNumbers[count] = (value == 0) ? 13 : value; count++; } } } private static boolean isOperator(char ch) { return (ch == '(' || ch == ')' || isArithmeticOperator(ch)); } private static boolean isArithmeticOperator(char ch) { return (ch == '/' || ch == '+' || ch == '-' ||
  • 12. ch == '*'); } private static String[] separateExpression(String s) { ArrayList tokens = new ArrayList<>(30); char[] chars = s.toCharArray(); String numBuffer = ""; for (char ch : chars) { if (isOperator(ch)) { if (numBuffer.length() > 0) { tokens.add(numBuffer); numBuffer = ""; } tokens.add(ch + ""); } else { if (ch != ' ') numBuffer += ch; } } if (numBuffer.length() > 0) { tokens.add(numBuffer); } return tokens.toArray(new String[tokens.size()]); } private boolean isCorrect(String infixExpression) { return (24 == PostfixNotation.evaluateInfix(infixExpression)); } private boolean isValid(String infixExpression) { String[] tokens = separateExpression(infixExpression); // Check is tokens contains any letters for (String s : tokens) { for (char ch : s.toCharArray()) { if (Character.isAlphabetic(ch)) return false; } } Stack operands = new Stack<>();
  • 13. for (String token : tokens) { if (!isOperator(token.charAt(0))) { operands.push(Integer.parseInt(token)); } } if (operands.size() != validNumbers.length) return false; // Put validNumbers into a buffer ArrayList ArrayList validOperands = new ArrayList<>(); for (int num : validNumbers) { validOperands.add(num); } for (int i = 0; i < validOperands.size(); i++) { int number = operands.pop(); int index = validOperands.indexOf(number); if (index != -1) { validOperands.remove(index); } else { return false; } } return true; } public static void main(String[] args) { Application.launch(args); } } import ToolKit.PostfixNotation; import javafx.application.Application; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.image.Image;
  • 14. import javafx.scene.image.ImageView; import javafx.scene.layout.BorderPane; import javafx.scene.layout.HBox; import javafx.stage.Stage; import java.util.ArrayList; import java.util.Stack; public class Exercise_13 extends Application { int[] validNumbers = new int[4]; @Override public void start(Stage primaryStage) { // Top pane Button btRefresh = new Button("Shuffle"); Label lblStatus = new Label(""); HBox topPane = new HBox(lblStatus, btRefresh); topPane.setAlignment(Pos.BASELINE_RIGHT); topPane.setSpacing(10); // Center Pane HBox centerPane = new HBox(); centerPane.setAlignment(Pos.CENTER); centerPane.setSpacing(10); centerPane.setPadding(new Insets(10)); // set first 4 random cards setRandomCards(centerPane); // Bottom pane TextField tfExpression = new TextField(); Label lblExpression = new Label("Enter an expression:"); Button btVerify = new Button("Verify"); HBox bottomPane = new HBox(10, lblExpression, tfExpression, btVerify); // Container Pane BorderPane borderPane = new BorderPane(); borderPane.setPadding(new Insets(10)); borderPane.setTop(topPane); borderPane.setCenter(centerPane); borderPane.setBottom(bottomPane); // Listeners btRefresh.setOnAction(e -> {
  • 15. lblStatus.setText(""); setRandomCards(centerPane); }); btVerify.setOnAction(e -> { String expression = tfExpression.getText(); if (isValid(expression) && isCorrect(expression)) { lblStatus.setText("Good job! " + expression + " = 24"); } else { lblStatus.setText("Invalid Expression"); } }); Scene scene = new Scene(borderPane); primaryStage.setTitle("4 Random Cards"); primaryStage.setScene(scene); primaryStage.show(); // Debug } private void setRandomCards(HBox pane) { boolean[] usedCards = new boolean[52]; // choose 4 random distinct cards from the deck int count = 0; pane.getChildren().clear(); while (count < 4) { int card = (int) (Math.random() * 52); if (!usedCards[card]) { usedCards[card] = true; pane.getChildren().add(new ImageView(new Image("image/card/" + (++card) + ".png"))); int value = card % 13; validNumbers[count] = (value == 0) ? 13 : value; count++; } } } private static boolean isOperator(char ch) { return (ch == '(' ||
  • 16. ch == ')' || isArithmeticOperator(ch)); } private static boolean isArithmeticOperator(char ch) { return (ch == '/' || ch == '+' || ch == '-' || ch == '*'); } private static String[] separateExpression(String s) { ArrayList tokens = new ArrayList<>(30); char[] chars = s.toCharArray(); String numBuffer = ""; for (char ch : chars) { if (isOperator(ch)) { if (numBuffer.length() > 0) { tokens.add(numBuffer); numBuffer = ""; } tokens.add(ch + ""); } else { if (ch != ' ') numBuffer += ch; } } if (numBuffer.length() > 0) { tokens.add(numBuffer); } return tokens.toArray(new String[tokens.size()]); } private boolean isCorrect(String infixExpression) { return (24 == PostfixNotation.evaluateInfix(infixExpression)); } private boolean isValid(String infixExpression) { String[] tokens = separateExpression(infixExpression); // Check is tokens contains any letters
  • 17. for (String s : tokens) { for (char ch : s.toCharArray()) { if (Character.isAlphabetic(ch)) return false; } } Stack operands = new Stack<>(); for (String token : tokens) { if (!isOperator(token.charAt(0))) { operands.push(Integer.parseInt(token)); } } if (operands.size() != validNumbers.length) return false; // Put validNumbers into a buffer ArrayList ArrayList validOperands = new ArrayList<>(); for (int num : validNumbers) { validOperands.add(num); } for (int i = 0; i < validOperands.size(); i++) { int number = operands.pop(); int index = validOperands.indexOf(number); if (index != -1) { validOperands.remove(index); } else { return false; } } return true; } public static void main(String[] args) { Application.launch(args); } }