I am in a low-level java class where I need to make an app using java and JavaScript. I have decided to create a game that creates a random equation using addition, subtraction, multiplication, and division. the trouble I am having is that my equation is created in the form of a string and I need to be able to calculate the answer to compare it to the users answer. I thought I had a descent solution to my issue but I keep getting some issues. can you help? my code is below:
import java.util.*;
public class GameClient {
private static Stack<String> operations;
private static Stack<Integer> numbers;
private static String[] tokens;
private static int i;
private static Stack<String> subAdd;
private static Stack<Integer> restOfNumbers;
public static void main(String[] args) {
Random variable = new Random();
int numberOfVariables = variable.nextInt(5)+2; //determines length of equation
String equation = "";
equation = equationGenerator(equation, numberOfVariables, variable);
System.out.println(equation);
System.out.print(calculateAnswer(equation));
}
public static String equationGenerator(String equation, int numberOfVariables, Random variable){
int operation;
int var;
var = variable.nextInt(10)+1;
equation += var;
operation = variable.nextInt(4)+1;
if(numberOfVariables == 1){
equation += " = ";
return equation;
}
if(operation == 1)
{
equation += " + ";
}
else if(operation == 2)
{
equation += " - ";
}
else if(operation == 3)
{
equation += " / ";
}
else if(operation == 4)
{
equation += " * ";
}
return equationGenerator(equation, numberOfVariables-1, variable);
}
public static int calculateAnswer(String equation){
String delims = "[ ]+";
tokens = equation.split(delims);
for(i=0; i< tokens.length; i++) //does all multiplication and division first leaving just addition and subtraction
switch(tokens[i]){
case "0": case "1":case "2":case "3":case "4":case "5":case "6":case "7":case "8":case "9":
int number = Integer.parseInt(tokens[i]);
popOrPush(number);
break;
case "*": case "/": case "+": case "-":
popOrPush(tokens[i], tokens);
}
while(!numbers.empty()){ //flips number and operation stacks to do addition and subtraction in correct order
restOfNumbers.push(numbers.pop());
}
while(!operations.empty()){
subAdd.push(operations.pop());
}
while(!subAdd.empty()){
switch(subAdd.pop()){
case "+":
restOfNumbers.push(restOfNumbers.pop() + restOfNumbers.pop());
case "-":
restOfNumbers.push(restOfNumbers.pop() - restOfNumbers.pop());
}
}
return restOfNumbers.pop();
}
public static void popOrPush(int number){
numbers.push(number);
}
public static void popOrPush(String operation, String[] tokens){
switch(operation){
case "*":
int multipliedValue = numbers.pop();
i++;
multipliedValue = multipliedValue * Integer.parseInt(tokens[i]);
numbers.push(multipliedValue);
case "/":
int dividedValue = numbers.pop();
i++;
dividedValue = dividedValue / Integer.parseInt(tokens[i]);
numbers.push(dividedValue);
case "+": case "-":
operations.push(operation);
}
}
}
You're not initializing your Stack, so you're likely getting a NPE when trying to use the numbers variable.
Make sure to initialize all of your variables (particularly your Stack objects). For example:
Stack<Integer> numbers = new Stack<>();
Related
The title says this is homework, I have been beating my head into the wall for hours, so please help. It works fine, at least the math part does, I work the conversion it worked just fine. I went to change the output dialog box to list what the ending unit was, instead of just listing the variable e.g. your lbs is the end. And not to allow negative starting weights.
Now I can't get the dialog box to not give me an error. (Lines 145 -148) I put in a sample dialog box using the Return option that doesn't work, but if I set it to a variable in my case test, it will work fine. He gave us starting code, I recopied his original code and that doesn't work. The next error I get is I wrote a method that takes two doubles and a char. When I call the function I pass it two doubles and a char it says it can't convert a string (Line 255).
This has been frustrating I over engineered this and now to have it not work is killing me. I don't understand how I can copy his original code in and it no longer works. Dialog boxes confuse me but I think I understand them.
return JOptionPane.showConfirmDialog(A)(null(B), display(C),0,1);
A is the call of the for the box what type
B is the object type my understanding its always call
C is the string, text message of the box
The last two got to do with the the icon and button displayed.
He got us started on eclipse, which said I had error in code where there none, I spent hours looking at them, they went away once I reloaded my code.
Please any thing would be helpful, but an example or corrected code (I know that is a lot) with explanations on why there are correct would be helpful. My husband knows java but not dialog boxes, so he can't help. And the method call looks right to both of us.
/*
* Uses: methods, dialog boxes, and a menu to convert weights
*
*/
import javax.swing.JOptionPane;
public class WeightCon {
char choices, choicee;
public static char menu() {
char choice;
int typeNum = 3;
boolean OK;
String prompt, results, title;
prompt = "Choose Starting Unit\n";
prompt += "A. Pounds\n";
prompt += "B. Kilograms\n";
prompt += "C. Stones\n";
prompt += "D. ounces\n";
prompt += "E. Netons\n";
prompt += "F.Grams\n";
prompt += "\n\nEnter the letter of your choice:";
title = "Weights";
do {
results = JOptionPane.showInputDialog(null,prompt,title, typeNum);
choice = results.toUpperCase().charAt(0);
if(choice >= 'A' && choice <= 'F') {
OK = true;
}
else {
OK = false;
title = "Not Valid Input!";
typeNum = 0;
}
}while(! OK);
return choice;
}
public static double LbstoKG(double k) {
return k * 0.453592;
}
public static double KtoLBS(double L) {
return L / 0.453592;
}
public static double LbstoStone(double S) {
return S / 14;
}
public static double LBStoOunce(double O) {
return O / .0625;
}
public static double LbstoNewton(double N) {
return N * 4.4482216282509;
}
public static double LBStoGarm(double G) {
return G / 0.00220462 ;
}
public static double KtoL(double L) {
return L / 0.453592;
}
public static double stoneToLbs(double L) {
return L * 14;
}
public static double ounceToLBS(double L) {
return L * .0625;
}
public static double NewtonToLBS(double L) {
return L / 4.4482216282509;
}
public static double GramtoLBS(double L) {
return L * 0.00220462 ;
}
//public static double
public static double getDouble(String prompt) {
boolean OK;
double val=0;
String temp, title = "Enter a double value";
int typeNum = 3;
do {
OK = true;
temp = JOptionPane.showInputDialog(null, prompt, title, typeNum);
try {
val = Double.parseDouble(temp);
}
catch(Exception e) {
OK = false;
title = "Error! Invalid input. Must be a double value";
typeNum = 0;
}
try {
val = Double.parseDouble(temp);
}
catch(Exception b) {
if( val < 0) {
title = "Error! Invalid input. Must be a positive double value";
typeNum = 0;
}
}while(! OK);
}while(! OK);
return val;
}
public static String outputResults(double start, double end, char choices){
int test;
String end1;
if(choices == 'A') {
end1 = "Your end weight is the following pounds: ";
} else if (choices == 'B') {
end1 = " Your end weight is the following kilograms: ";
} else if (choices == 'C') {
end1 = " Your end weight is the following stones: ";
} else if (choices == 'D') {
end1 = " Your end weight is the following ounces: ";
} else if (choices == 'E') {
end1 = " Your end weight is the following newtons: ";
} else if (choices == 'F') {
end1 = " Your end weight is the following grams: ";
} else {end1 = " ERROR ERROR UNDEFINDED ERROR PLEASE CONSOLT DOCUMENTATION";}
String endreal = String.valueOf(end);
String display = "" + end1 + endreal;
//int input =
test = JOptionPane.showConfirmDialog(null, display,0,1);
test = JOptionPane.showConfirmDialog(null, display);
return JOptionPane.showConfirmDialog(null, display);
return JOptionPane.showConfirmDialog(null, display,0,1);
}
//display += "Do again?";
//return JOptionPane.showConfirmDialog(null,"test",0,1);
//return JOptionPane.showConfirmDialog(null,display,0,1);}}
//return JOptionPane.showConfirmDialog(null, "test",0,1);}}
//}
//
public static void main(String[] args) {
double get;
double lbs=0,ounce=0,kgs=0, stone=0,newton=0,gram=0 ;
double temp,start, end;
char choice, choices;
int button;
//String end1;
start =-99;
end = -999;
get = 0;
temp = 0;
do {
choice = menu();
choices = choice;
switch(choice) {
case 'A':
get = getDouble("Enter pounds : ");
lbs = get;
start = get; //LbstoKG(get);
temp = kgs;
break;
case 'B':
get = getDouble("Enter kilograms : ");
kgs = get;
start = KtoL(get);
temp = lbs;
break;
case 'C':
get = getDouble("Enter Stones : ");
stone = get;
start = stoneToLbs(get);
temp = lbs;
break;
case 'D':
ounce = getDouble("Enter Ounces : ");
start = ounceToLBS(get);
temp = lbs;
break;
case 'E':
get= getDouble("Enter Newtons : ");
newton = get;
start = NewtonToLBS(get);
temp = lbs;
break;
case 'F':
get = getDouble("Enter grams : ");
gram = get;
start = GramtoLBS(get);
temp = lbs;
break;
}
//button = outputResults(get,get);
//} while(button == 0);
// do {
choice = menu();
switch(choice) {
case 'A':
//get = getDouble("Enter pounds : ");
//lbs = getDouble("Enter pounds : ");
//kgs = get;
end = start;
break;
case 'B':
//get = getDouble("Enter kilograms : ");
end = LbstoKG(start);
break;
case 'C':
//get = getDouble("Enter Stones : ");
//stone = get;
end = LbstoStone(start);
break;
case 'D':
//ounce = getDouble("Enter Ounces : ");
end = LBStoOunce(start);
break;
case 'E':
//get= getDouble("Enter Newtons : ");
end = LbstoNewton(start);
System.out.printf("Hello");
break;
case 'F':
//get = getDouble("Enter grams : ");
end = LBStoGarm(start);
break;
}
button = outputResults(end,start,choice);
} while(button == 0);
}}
After copying and pasting your code into my compiler, there were multiple errors.
First Mistake in outputResults(): Remove the 0, and the 1.
The method showConfirmDialog(Component, Object, String, int) in the type JOptionPane
is not applicable for the arguments (null, String, int, int)
Line:
test = JOptionPane.showConfirmDialog(null, display,0,1);
Correction:
test = JOptionPane.showConfirmDialog(null, display);
Second and Third Mistake also in outputResults(): You cannot return two objects. Also, your method returns a String.
return JOptionPane.showConfirmDialog(null, display);
return JOptionPane.showConfirmDialog(null, display,0,1); // 0, 1 again.
// The second return statement is dead code, and this also makes the first mistake again
Your method returns a String.
JOptionPane.showConfirmDialog(null, display); returns an int.
So in your method returning a String, if you return an int instead, it will be a compiler error. For example:
... String outputResults(...){
return JOptionPane.showConfirmDialog(null, display);
}
1 quick fix: change return type to int (method: String outputResults(double, double, char))
Fourth Mistake in main(): Fix your Third Mistake and ignore this fix.
int button = ...;
...
button = outputResults(end,start,choice); // Returns String, but button is an int
// Change button to a string?
// Integer.parseInt(outputResults(end,start,choice)); ?
This is some code I got from my textbook which is a calculator solving expressions entered as postfix notation. I was wondering if there was a way I could keep using the stack instead of the stack restarting once the program evaluates an expression.
import java.util.Scanner;
import java.util.Stack;
public class RPN2
{
private Stack<Integer> stack;
public RPN2()
{
stack = new Stack<Integer>(); //creates stack
}
public static void main(String[] args)
{
String expression, again;
int result;
Scanner keyboard = new Scanner(System.in);
do
{
RPN2 evaluator = new RPN2();
System.out.println("Enter a valid post-fix expression one token " +
"at a time with a space between each token (e.g. 5 4 + 3 2 1 - + *)");
System.out.println("Each token must be an integer or an operator (+,-,*,/)");
expression = keyboard.nextLine();
result = evaluator.evaluate(expression);
System.out.println();
System.out.println("That expression equals " + result);
System.out.print("Evaluate another expression [Y/N]? ");
again = keyboard.nextLine();
System.out.println();
}
while (again.equalsIgnoreCase("y"));
}
public int evaluate(String expr)
{
int op1, op2, result = 0;
String token;
Scanner parser = new Scanner(expr);
while (parser.hasNext())
{
token = parser.next();
if (isOperator(token)) //if operator pop
{
op2 = (stack.pop()).intValue();
op1 = (stack.pop()).intValue();
result = evaluateSingleOperator(token.charAt(0), op1, op2); //
stack.push(new Integer(result));
}
else
stack.push(new Integer(Integer.parseInt(token)));
}
return result;
}
private boolean isOperator(String token)
{
return ( token.equals("+") || token.equals("-") ||
token.equals("*") || token.equals("/") || token.equals("%") );
}
private int evaluateSingleOperator(char operation, int op1, int op2)
{
int result = 0;
switch (operation)
{
case '+':
result = op1 + op2;
break;
case '-':
result = op1 - op2;
break;
case '*':
result = op1 * op2;
break;
case '/':
result = op1 / op2;
break;
case '%':
result = op1 % op2;
break;
}
return result;
}
}
Yes you can, see comments :
public RPN2() {
stack = new Stack<>(); //creates stack
}
void clearStack(){ //add clear stach method
stack.clear();
}
public static void main(String[] args)
{
String expression, again;
int result;
Scanner keyboard = new Scanner(System.in);
RPN2 evaluator = new RPN2(); //move out of the do loop
do
{
evaluator.clearStack();//use clear stack method
//rest of the code omitted (no change in it)
I have no clue what I am supposed to be doing here, but I think I have most of my code good. I can only edit code inside the Evaluate() method. Pls help.
Here is my class with my main method
package labs.lab3;
import java.util.Scanner; // Needed for the Scanner
import java.io.*; // Needed for the File and IOException
public class TestDriver {
/**
* #param args
*/
public static void main(String[] args) throws IOException {
System.out.printf("%-30s", "Postfix Expression");
System.out.printf("%-30s", "Evaluation Result");
System.out.println();
String filename = "./src/labs/lab3/PostfixExpressions.txt";
File file = new File(filename);
Scanner inputFile = new Scanner(file);
while (inputFile.hasNext())
{
String expression = inputFile.nextLine();
System.out.printf("%-30s", expression);
PostfixEvaluator evaluator = new PostfixEvaluator(expression);
System.out.printf("%-30s" , evaluator.Evaluate());
System.out.println();
}
inputFile.close();
}
}
And Here is my Post Fix Evaluator class:
package labs.lab3;
import java.util.Stack;
import java.util.EmptyStackException;
import java.util.StringTokenizer;
public class PostfixEvaluator
{
private Stack<Integer> stack;
private String expression;
private String token;
public PostfixEvaluator(String e)
{
stack = new Stack<Integer>();
expression = e;
}
// Evaluate the postfix expression and return the evaluation result
public int Evaluate()
{
int op1,op2;
int result;
StringTokenizer st = new StringTokenizer(expression);//split the expression into tokens
String token=st.nextToken();
while (st.hasMoreTokens()){
if (Character.isDigit(token.charAt(0))) {
int value = Integer.parseInt(token);
stack.push(value);
}
else if (!Character.isDigit(token.charAt(0))) {
op1=stack.pop();
op2=stack.pop();
result = Calculate(op1,op2,token.charAt(0));
stack.push(result);
}
}
int answer = stack.pop();
return answer;
}
// Perform an operation on the two operands
public int Calculate(int operand1, int operand2, char operation)
{
int result = 0;
switch (operation)
{
case '+':
result = operand1 + operand2;
break;
case '-':
result = operand1 - operand2;
break;
case '/':
result = operand1 / operand2;
break;
case '*':
result = operand1 * operand2;
break;
case '%':
result = operand1 % operand2;
break;
}
return result;
}
}
Thanks
I can't see you move forward in the tokenizer. You call nextToken just
once, outside the loop. The rest of the code seems to indicate that evaluate
should consume the entire expression, So nextToken needs to be called inside
the loop.
i am trying to implement a java method which accepts an input in RPN (Reverse Polish Notation) and through use of a stack converts it into an infix notation and calculates it. I have built the stack and a working converter but i am finding problems when it comes to accepting multiple digit numbers (such as 10), my idea to solve this was to enter each separate entity separated by a space, 10+20 would be entered as "10 20 +" but this is resulting in an out of bounds error. Without the section marked below the program works fine for equations such as "12+" (1+2) and more complex ones as long as they involve single digit values. The stack is fully functiopnal too with push and pop methods
public static void stackRPN(){
Stack myStack = new Stack();
Scanner sc = new Scanner(System.in);
System.out.println("Enter an equation: ");
String eq = sc.nextLine();
int len = eq.length();
for (int i = 0; i < len; i++){
String car1 = String.valueOf(eq.charAt(i));
if ("+".equals(car1) || "-".equals(car1) || "/".equals(car1) || /*"car1"*/"x".equals(car1)){
String a = myStack.pop();
String b = myStack.pop();
//This handlws all the digits
double bI = Double.parseDouble(b);
double aI = Double.parseDouble(a);
double finalNo = 0;
switch (car1) {
case "+": finalNo = bI + aI;
break;
case "-": finalNo = bI - aI;
break;
case "/": finalNo = bI / aI;
break;
case "x": finalNo = bI * aI;
break;
}
myStack.push(finalNo+"");
String finEq = b+car1+a;
System.out.println(finEq + " = " +finalNo);
} else {
This bit does not work
while (len < i+1 && eq.charAt(i+1) != ' '){
car1 = car1+eq.charAt(i+1);
i++;
}
Till here
myStack.push(car1);
}
}
mainMenu();
}
This was fixed using the split method in the string class as so
public static void stackRPN(){
Stack myStack = new Stack();
Scanner sc = new Scanner(System.in);
System.out.print("Enter an equation: ");
System.out.println();
String eq = sc.nextLine();
//This Bit splits up the string where it meets a space
String[] eqS = eq.split(" ");
int len = eqS.length;
for (int i = 0; i < len; i++){
String car1 = eqS[i];
if ("+".equals(car1) || "-".equals(car1) || "/".equals(car1) || /*"car1"*/"x".equals(car1)){
String a = myStack.pop();
String b = myStack.pop();
//This handlws all the digits
double bI = Double.parseDouble(b);
double aI = Double.parseDouble(a);
double finalNo = 0;
switch (car1) {
case "+": finalNo = bI + aI;
break;
case "-": finalNo = bI - aI;
break;
case "/": finalNo = bI / aI;
break;
case "x": finalNo = bI * aI;
break;
}
myStack.push(finalNo+"");
String finEq = b+car1+a;
System.out.println(finEq + " = " +finalNo);
} else {
myStack.push(car1);
}
}
mainMenu();
}
I have this method which will generate a random maths expression solve it and output the answer to a variable:
public int Nov2()
{
char[] ops = new char[] {'+', '-', '*', '/'};
int i = rand.nextInt(4-0) + 0;
char op1 = ops[i];
int novnum1 = rand.nextInt(101-1) + 1;
int novnum2 = rand.nextInt(101-1) + 1;
int nov2result = 0;
switch(op1) {
case '+': nov2result = novnum1 + novnum2; break;
case '-': nov2result = novnum1 - novnum2; break;
case '*': nov2result = novnum1 * novnum2; break;
case '/': nov2result = novnum1 / novnum2; break;
}
String nov2Exp = novnum1 + " " + op1 + " " + novnum2 + " = ";
Nov2resstor = nov2result;
setContentView(R.layout.gameview);
TextView display = (TextView) findViewById(R.id.exp);
display.setText(nov2Exp);
return nov2result;
}
How would i use the same sort of thing for expressions with more than two terms without having to write really complex if statements like this in my next method:
public int Eas3()
{
char[] ops = new char[] {'+', '-', '*', '/'};
int i = rand.nextInt(4-0) + 0;
char op1 = ops[i];
i = rand.nextInt(4-0) + 0;
char op2 = ops[i];
int easnum1 = rand.nextInt(101-1) + 1;
int easnum2 = rand.nextInt(101-1) + 1;
int easnum3 = rand.nextInt(101-1) + 1;
int eas3result = 0;
if (op1 == '+' && op2 == '+')
{
eas3result = ((easnum1 + easnum2) + easnum3);
}
else if (op1 == '+' && op2 == '-')
{
eas3result = ((easnum1 + easnum2) - easnum3);
}
else if (op1 == '+' && op2 == '*')
{
eas3result = ((easnum1 + easnum2) * easnum3);
}
else if (op1 == '+' && op2 == '-')
{
eas3result = ((easnum1 + easnum2) - easnum3);
}
.../
I have methods which do this for 2,3,4,5 and 6 so my if statements would become very large using this method.
Any ideas?
you can use the built-in Javascript engine.
import javax.script.ScriptEngineManager;
import javax.script.ScriptEngine;
public class Test
{
public static void main(String[] args) throws Exception
{
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("JavaScript");
String foo = "40+2";
System.out.println(engine.eval(foo));
}
}
Yes, another way to do it is to write Command objects:
public interface Command<V> {
V execute(Object ... args);
}
You'll write an object that implements this interface:
public class AdditionCommand implements Command<Double> {
public Double execute(Object ... args) {
Double x = (Double)args[0];
Double y = (Double)args[1];
return x+y;
}
}
Now you can look up in a Map using the operator:
Map<String, Command> opsLookup = new HashMap<String, Command>() {{
opsLookup.put("+", new AddCommand<Number>());
opsLookup.put("-", new SubtractCommand<Number>());
}};
No need for a switch.
Check out this MathEval class I found online It will evaluate a String that represents an equation for you.
mySolver = new MathEval();
double answer = mySolver.evaluate(equation);
What you're looking for is called the composite pattern. You define an abstract Expression base class and derive it.
The classes must implement an evaluate() method which returns the result.
One sub class will be the constant which return it's value, another one would be a binary expression like plus, minus, etc. The evaluate() method will add/subtract/etc the result of the evaluated sub-expressions.
You can then build arbitrary expressions out of other expressions and then evaluate it without using one if condition.
How about using recursion:
int num(int numberOfOperands, int current){
if(numberOfOperands<=0) return current;
switch(rand.nextInt(4)){
case 0: return num(numberOfOperands-1, current + (rand.nextInt(100)+1)); break;
case 1: return num(numberOfOperands-1, current - (rand.nextInt(100)+1)); break;
case 2: return num(numberOfOperands-1, current * (rand.nextInt(100)+1)); break;
case 3: return num(numberOfOperands-1, current / (rand.nextInt(100)+1)); break;
}
}
int num(int numberOfOperands) throws Exception{
if(numberOfOperands <=0)
throw new Exception("invalid number of operands: "+numberOfOperands);
return num(numberOfOperands, rand.nextInt(100)+1);
}
This would, of course, ignore precedence of operations.
You could make a string with the variables you are using like this:
String temp = "(" + easnum1 + op1 + easnum2 + ")" + op2 + easnum3;
after that you can use the ScriptEngineManager class to use javascript as the engine so you can use the eval method.
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("js");
Object result = engine.eval(temp);
this method does the calculations and returns the result.
Hope this helps.
I would use an array for the values easnum[], an array for the operands op[] and an array with intermediate values.
Something along the following lines
for(...)
{
if(op[i]=='+') easintermediat[i+1] = easintermediate[i] + easnum[i]
...
}
If you've got n operations on n+1 numbers, and you do the first one, then you're left with n-1 operations on n numbers. You can use this as the basis for a loop that will process any number of items easily.
int operate(int[] numbers, int[] operations) {
if (numbers.length < 1 || numbers.length != operations.length + 1) {
throw new IllegalArgumentException();
}
int result = numbers[0];
for (int i = 0; i < operations.length; ++i) {
result = operate(operations[i], result, numbers[i+1]);
// where operate() is your switch statement
}
return result;
}
Try this:
public int Eas3()
{
char[] ops = new char[] {'+', '-', '*', '/'};
int i = rand.nextInt(4-0) + 0;
char op1 = ops[i];
i = rand.nextInt(4-0) + 0;
char op2 = ops[i];
int easnum1 = rand.nextInt(101-1) + 1;
int easnum2 = rand.nextInt(101-1) + 1;
int easnum3 = rand.nextInt(101-1) + 1;
int eas3result = 0;
if (op1 == '+')
{
switch(op2)
{
case '+': eas3result=((easnum1 + easnum2) + easnum3); break;
case '-': eas3result=((easnum1 - easnum2) - easnum3); break;
case '*': eas3result=((easnum1 * easnum2) * easnum3); break;
case '/': eas3result=((easnum1 / easnum2) / easnum3); break;
}
}
..../
}
or even you can put outer IF in SWITCH like the following
public int Eas3()
{
char[] ops = new char[] {'+', '-', '*', '/'};
int i = rand.nextInt(4-0) + 0;
char op1 = ops[i];
i = rand.nextInt(4-0) + 0;
char op2 = ops[i];
int easnum1 = rand.nextInt(101-1) + 1;
int easnum2 = rand.nextInt(101-1) + 1;
int easnum3 = rand.nextInt(101-1) + 1;
int eas3result = 0;
int tempResult=0;
switch(op1)
{
case '+': tempResult=(easnum1 + easnum2); break;
case '-': tempResult=(easnum1 + easnum2) ; break;
case '*': tempResult=(easnum1 + easnum2) ; break;
case '/': tempResult=(easnum1 + easnum2) ; break;
}
switch(op2)
{
case '+': eas3result=(tempResult + easnum3); break;
case '-': eas3result=(tempResult - easnum3); break;
case '*': eas3result=(tempResult * easnum3); break;
case '/': eas3result=(tempResult / easnum3); break;
}
}