SlideShare a Scribd company logo
**********Evaluator.java****************
package evaluator;
import java.util.*;
import operand.Operand;
import operator.Operator;
public class Evaluator {
private Stack<Operand> operandStack;
private Stack<Operator> operatorStack;
private StringTokenizer tokenizer;
private static final String DELIMITERS = "+-*^/() ";
public Evaluator() {
operandStack = new Stack<Operand>();
operatorStack = new Stack<Operator>();
}
public int eval(String expression) {
int result = 0;
String token;
Operator hashOpr = Operator.operators.get("#");
oprStack.push(hashOpr);
String delimiters = "+-*/#!";
// The 3rd argument is true to indicate that the delimiters should be used
// as tokens, too. But, we'll need to remember to filter out spaces.
this.tokenizer = new StringTokenizer(expression, DELIMITERS, true);
while (this.tokenizer.hasMoreTokens()) {
// filter out spaces
if (!(token = this.tokenizer.nextToken()).equals(" ")) {
// check if token is an operand
if (Operand.check(token)) {
operandStack.push(new Operand(token));
} else {
if (!Operator.check(token)) {
System.out.println("*****invalid token******");
System.exit(1);
}
// TODO Operator is abstract - this line will need to be fixed:
// ( The Operator class should contain an instance of a HashMap,
// and values will be instances of the Operators. See Operator class
// skeleton for an example. )
Operator newOperator = null; // new Operator( token );
while (operatorStack.peek().priority() >= newOperator.priority()) {
// note that when we eval the expression 1 - 2 we will
// push the 1 then the 2 and then do the subtraction operation
// This means that the first number to be popped is the
// second operand, not the first operand - see the following code
Operator oldOpr = operatorStack.pop();
Operand op2 = operandStack.pop();
Operand op1 = operandStack.pop();
operandStack.push(oldOpr.execute(op1, op2));
}
operatorStack.push(newOperator);
}
}
}
// Control gets here when we've picked up all of the tokens; you must add
// code to complete the evaluation - consider how the code given here
// will evaluate the expression 1+2*3
// When we have no more tokens to scan, the operand stack will contain 1 2
// and the operator stack will have + * with 2 and * on the top;
// In order to complete the evaluation we must empty the stacks (except
// the init operator on the operator stack); that is, we should keep
// evaluating the operator stack until empty
// Suggestion: create a method that takes an operator as argument and
// then executes the while loop; also, move the stacks out of the main
// method
return 0;
}
/**
* Class to help test your Evaluator:
* javac EvaluatorTester
* java EvaluatorTester "1+2" "3*5"
*/
public static void main(String[] args) {
Evaluator evaluator = new Evaluator();
for (String arg : args) {
System.out.format("%s = %dn", arg, evaluator.eval(arg));
}
}
}
************************************Operand.Java*******************************
*******************
package operand;
public class Operand {
public Operand( String token ) {
}
public Operand( int value ) {
}
public int getValue() {
return 0;
}
public static boolean check( String token ) {
return false;
}
}
*******************************************************EvaluatorTest.java*******
****************************************
package tests;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import evaluator.Evaluator;
public class EvaluatorTest {
@Test
void testSimpleAddition() {
Evaluator evaluator = new Evaluator();
assertEquals(3, evaluator.eval("1 +2"));
}
@Test
void testSimpleDivision() {
Evaluator evaluator = new Evaluator();
assertEquals(0, evaluator.eval("1/2"));
}
@Test
void testSimpleExpression() {
Evaluator evaluator = new Evaluator();
assertEquals(7, evaluator.eval("1+2*3"));
}
@Test
void testSimpleParenthesizedExpression() {
Evaluator evaluator = new Evaluator();
assertEquals(9, evaluator.eval("(1+2)*3"));
}
@Test
void testComplexExpressionWithNegativeResult() {
Evaluator evaluator = new Evaluator();
assertEquals(7, evaluator.eval("2-(3/10)+2-5"));
}
@Test
void testAnotherComplexExpressionWithNegativeResult() {
Evaluator evaluator = new Evaluator();
assertEquals(-6, evaluator.eval("(6-12*2)/3"));
}
@Test
void testSimpleExponentiation() {
Evaluator evaluator = new Evaluator();
assertEquals(9, evaluator.eval("3^2"));
}
@Test
void testSlightlyMoreComplexExponentiation() {
Evaluator evaluator = new Evaluator();
assertEquals(4, evaluator.eval("3^2/2"));
}
@Test
void testHardMode() {
Evaluator evaluator = new Evaluator();
assertEquals(1176, evaluator.eval("2+3-5*((2-3)*2-5*2+3*(2-3-5-5*6)+4/2)*2-9"));
}
@Test
void testProperStackUsage() {
Evaluator evaluator = new Evaluator();
// Stacks should be emptied and in a valid state after the first evaluation occurs,
// so the second evaluation should run without exception and provide
assertEquals(6, evaluator.eval("1+2+3"));
assertEquals(1, evaluator.eval("10-8-1"));
}
}
******************************************************OperandTest.java*********
**********************************************************
package tests;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.ArrayList;
import java.util.Arrays;
import org.junit.jupiter.api.Test;
import operand.Operand;
public class OperandTest {
@Test
void testCheck() {
ArrayList<String> validOperands =
new ArrayList<>(Arrays.asList( "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ));
validOperands.forEach(operand -> assertTrue(Operand.check(operand)));
assertFalse(Operand.check("a"));
}
@Test
void testGetValueFromOriginalString() {
Operand operandOne = new Operand("3");
assertEquals(3, operandOne.getValue());
}
@Test
void testGetValueFromOriginalInt() {
Operand operandTwo = new Operand(7);
assertEquals(7, operandTwo.getValue());
}
}
*******************************************************OperatorTest.java********
*********************************************
package tests;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import java.util.ArrayList;
import java.util.Arrays;
import operator.Operator;
public class OperatorTest {
@Test
void testCheck() {
ArrayList<String> validOperators =
new ArrayList<>(Arrays.asList( "+", "-", "*", "/", "^" ));
validOperators.forEach(operator -> assertTrue(Operator.check(operator)));
assertFalse(Operator.check("1"));
}
}
******************************************************************************
****************
This is the readme
[![Open in Visual Studio Code](https://classroom.github.com/assets/open-in-vscode-
c66648af7eb3fe8bc4f294546bfd86ef473780cde1dea487d3c4ff354943c9ae.svg)](https://classroo
m.github.com/online_ide?assignment_repo_id=10049933&assignment_repo_type=AssignmentR
epo)
# Assignment 1 Documentation
Author: Eduardo Ruiz (please keep the Author: heading for my grading script)
## Overview of code skeleton
The folders `.devcontainer`, `.vscode`, and `lib` contain configuration information that must not
be deleted or modified. The remaining folders will be discussed in class.
## Scope of Work
| Requirement | Completed? | Comments from student |
| ------------------------- | ---------- | --------------------- |
| 1 - Implement algorithm | [] | |
| 2 - Tests | [] | |
| 3 - Class implementations | [] | |
## Class diagrams
REPLACE THIS TEXT: Include a diagram of all of the classes you worked with in this
assignment, indicating their relationships. For each class, include a one line description of its
responsibility. If you are looking for a tool to use to create the class diagram, check out
[Mermaid](https://mermaid.js.org/syntax/classDiagram.html) - this allows you to write
markdown in this file that will be rendered as class diagrams.
## Results and Conclusions
### What I Learned
REPLACE THIS TEXT: Describe what you learned by completing this assignment
### Challenged I Encountered
REPLACE THIS TEXT: Describe challenges you encountered completing this assignment, and
how you overcame those challenges
********************************************************
********************************************************
While the operator stack is not empty, pop the operator from the operator stack, create an
operand object from the popped operator, and push it to the operand stack. While the operand
stack has more than one operand, pop two operands from the operand stack and one operator
from the operator stack, and apply the operator to the operands. Push the result back to the
operand stack. The result of the expression is the single operand left on the operand stack. You
are required to implement the missing parts of this algorithm in the eval method of the Evaluator
class.
Please help, thank you
----------Evaluator-java---------------- package evaluator-   import j.docx

More Related Content

Similar to ----------Evaluator-java---------------- package evaluator- import j.docx

Core java concepts
Core    java  conceptsCore    java  concepts
Core java concepts
Chikugehlot
 
Ruby on Rails Intro
Ruby on Rails IntroRuby on Rails Intro
Ruby on Rails Intro
zhang tao
 
Scala test
Scala testScala test
Scala test
Meetu Maltiar
 
Scala test
Scala testScala test
Java Concepts
Java ConceptsJava Concepts
Java Concepts
AbdulImrankhan7
 
C-Sharp Arithmatic Expression Calculator
C-Sharp Arithmatic Expression CalculatorC-Sharp Arithmatic Expression Calculator
C-Sharp Arithmatic Expression Calculator
Neeraj Kaushik
 
Unittesting JavaScript with Evidence
Unittesting JavaScript with EvidenceUnittesting JavaScript with Evidence
Unittesting JavaScript with Evidence
Tobie Langel
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
Manvendra Singh
 
Ppt on java basics1
Ppt on java basics1Ppt on java basics1
Ppt on java basics1
Mavoori Soshmitha
 
java write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdfjava write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdf
arjuntelecom26
 
JavaScript Editions ES7, ES8 and ES9 vs V8
JavaScript Editions ES7, ES8 and ES9 vs V8JavaScript Editions ES7, ES8 and ES9 vs V8
JavaScript Editions ES7, ES8 and ES9 vs V8
Rafael Casuso Romate
 
PQTimer.java A simple driver program to run timing t.docx
  PQTimer.java     A simple driver program to run timing t.docx  PQTimer.java     A simple driver program to run timing t.docx
PQTimer.java A simple driver program to run timing t.docx
joyjonna282
 
How To Test Everything
How To Test EverythingHow To Test Everything
How To Test Everything
noelrap
 
object oriented programming java lectures
object oriented programming java lecturesobject oriented programming java lectures
object oriented programming java lectures
MSohaib24
 
--------------- FloatArrays-java - ckage csi213-lab05-import java-u.pdf
--------------- FloatArrays-java -    ckage csi213-lab05-import java-u.pdf--------------- FloatArrays-java -    ckage csi213-lab05-import java-u.pdf
--------------- FloatArrays-java - ckage csi213-lab05-import java-u.pdf
AdrianEBJKingr
 
Core java
Core javaCore java
Core java
Rajkattamuri
 
Specs2
Specs2Specs2
java-programming.pdf
java-programming.pdfjava-programming.pdf
java-programming.pdf
Prof. Dr. K. Adisesha
 
CS2309 JAVA LAB MANUAL
CS2309 JAVA LAB MANUALCS2309 JAVA LAB MANUAL
CS2309 JAVA LAB MANUAL
Lavanya Arunachalam A
 
Unit testing
Unit testingUnit testing
Unit testing
Pooya Sagharchiha
 

Similar to ----------Evaluator-java---------------- package evaluator- import j.docx (20)

Core java concepts
Core    java  conceptsCore    java  concepts
Core java concepts
 
Ruby on Rails Intro
Ruby on Rails IntroRuby on Rails Intro
Ruby on Rails Intro
 
Scala test
Scala testScala test
Scala test
 
Scala test
Scala testScala test
Scala test
 
Java Concepts
Java ConceptsJava Concepts
Java Concepts
 
C-Sharp Arithmatic Expression Calculator
C-Sharp Arithmatic Expression CalculatorC-Sharp Arithmatic Expression Calculator
C-Sharp Arithmatic Expression Calculator
 
Unittesting JavaScript with Evidence
Unittesting JavaScript with EvidenceUnittesting JavaScript with Evidence
Unittesting JavaScript with Evidence
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
 
Ppt on java basics1
Ppt on java basics1Ppt on java basics1
Ppt on java basics1
 
java write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdfjava write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdf
 
JavaScript Editions ES7, ES8 and ES9 vs V8
JavaScript Editions ES7, ES8 and ES9 vs V8JavaScript Editions ES7, ES8 and ES9 vs V8
JavaScript Editions ES7, ES8 and ES9 vs V8
 
PQTimer.java A simple driver program to run timing t.docx
  PQTimer.java     A simple driver program to run timing t.docx  PQTimer.java     A simple driver program to run timing t.docx
PQTimer.java A simple driver program to run timing t.docx
 
How To Test Everything
How To Test EverythingHow To Test Everything
How To Test Everything
 
object oriented programming java lectures
object oriented programming java lecturesobject oriented programming java lectures
object oriented programming java lectures
 
--------------- FloatArrays-java - ckage csi213-lab05-import java-u.pdf
--------------- FloatArrays-java -    ckage csi213-lab05-import java-u.pdf--------------- FloatArrays-java -    ckage csi213-lab05-import java-u.pdf
--------------- FloatArrays-java - ckage csi213-lab05-import java-u.pdf
 
Core java
Core javaCore java
Core java
 
Specs2
Specs2Specs2
Specs2
 
java-programming.pdf
java-programming.pdfjava-programming.pdf
java-programming.pdf
 
CS2309 JAVA LAB MANUAL
CS2309 JAVA LAB MANUALCS2309 JAVA LAB MANUAL
CS2309 JAVA LAB MANUAL
 
Unit testing
Unit testingUnit testing
Unit testing
 

More from Adamq0DJonese

1) What are the five tenets of wireless LAN (802-11) troubleshooting- (1).docx
1) What are the five tenets of wireless LAN (802-11) troubleshooting- (1).docx1) What are the five tenets of wireless LAN (802-11) troubleshooting- (1).docx
1) What are the five tenets of wireless LAN (802-11) troubleshooting- (1).docx
Adamq0DJonese
 
1) Water soluble compounds have lower bioconcentration factors than do.docx
1) Water soluble compounds have lower bioconcentration factors than do.docx1) Water soluble compounds have lower bioconcentration factors than do.docx
1) Water soluble compounds have lower bioconcentration factors than do.docx
Adamq0DJonese
 
1) Spatial Concepts of Location- Direction and Distance (absolute and.docx
1) Spatial Concepts of Location- Direction and Distance (absolute and.docx1) Spatial Concepts of Location- Direction and Distance (absolute and.docx
1) Spatial Concepts of Location- Direction and Distance (absolute and.docx
Adamq0DJonese
 
1) How are DNA and RNA similar and how are they different- 2) What are.docx
1) How are DNA and RNA similar and how are they different- 2) What are.docx1) How are DNA and RNA similar and how are they different- 2) What are.docx
1) How are DNA and RNA similar and how are they different- 2) What are.docx
Adamq0DJonese
 
1) Identify the following parts of a flower-2) Identify these flowers.docx
1) Identify the following parts of a flower-2) Identify these flowers.docx1) Identify the following parts of a flower-2) Identify these flowers.docx
1) Identify the following parts of a flower-2) Identify these flowers.docx
Adamq0DJonese
 
1) design a clocked latch version using NOR gates2) Design the version.docx
1) design a clocked latch version using NOR gates2) Design the version.docx1) design a clocked latch version using NOR gates2) Design the version.docx
1) design a clocked latch version using NOR gates2) Design the version.docx
Adamq0DJonese
 
1) Given the following program- Count -0 While (Count !- 5)- Count - C.docx
1) Given the following program- Count -0 While (Count !- 5)- Count - C.docx1) Given the following program- Count -0 While (Count !- 5)- Count - C.docx
1) Given the following program- Count -0 While (Count !- 5)- Count - C.docx
Adamq0DJonese
 
1) Explain at least two different things that can happen when a meteor.docx
1) Explain at least two different things that can happen when a meteor.docx1) Explain at least two different things that can happen when a meteor.docx
1) Explain at least two different things that can happen when a meteor.docx
Adamq0DJonese
 
1) Assume that you measure the OD of two E-coli cultures- culture A an.docx
1) Assume that you measure the OD of two E-coli cultures- culture A an.docx1) Assume that you measure the OD of two E-coli cultures- culture A an.docx
1) Assume that you measure the OD of two E-coli cultures- culture A an.docx
Adamq0DJonese
 
1) Define filtration- phagocytosis- pinocytosis- endocytosis and exocy.docx
1) Define filtration- phagocytosis- pinocytosis- endocytosis and exocy.docx1) Define filtration- phagocytosis- pinocytosis- endocytosis and exocy.docx
1) Define filtration- phagocytosis- pinocytosis- endocytosis and exocy.docx
Adamq0DJonese
 
1) A pair of fair dice were tossed- Assuming X represents the sum of t.docx
1) A pair of fair dice were tossed- Assuming X represents the sum of t.docx1) A pair of fair dice were tossed- Assuming X represents the sum of t.docx
1) A pair of fair dice were tossed- Assuming X represents the sum of t.docx
Adamq0DJonese
 
1 What are the advantages and disadvantages of globalization- Give exa.docx
1 What are the advantages and disadvantages of globalization- Give exa.docx1 What are the advantages and disadvantages of globalization- Give exa.docx
1 What are the advantages and disadvantages of globalization- Give exa.docx
Adamq0DJonese
 
1 point- Regarding chronic disease- which of the following statements.docx
1 point- Regarding chronic disease- which of the following statements.docx1 point- Regarding chronic disease- which of the following statements.docx
1 point- Regarding chronic disease- which of the following statements.docx
Adamq0DJonese
 
1 point Which of the following is an example of a Type I error- An inn.docx
1 point Which of the following is an example of a Type I error- An inn.docx1 point Which of the following is an example of a Type I error- An inn.docx
1 point Which of the following is an example of a Type I error- An inn.docx
Adamq0DJonese
 
1 Elonis v- United States- is the main case on 875(c)- What is the men.docx
1 Elonis v- United States- is the main case on 875(c)- What is the men.docx1 Elonis v- United States- is the main case on 875(c)- What is the men.docx
1 Elonis v- United States- is the main case on 875(c)- What is the men.docx
Adamq0DJonese
 
1 1- A government wants to provide student loans to students in their.docx
1 1- A government wants to provide student loans to students in their.docx1 1- A government wants to provide student loans to students in their.docx
1 1- A government wants to provide student loans to students in their.docx
Adamq0DJonese
 
1 a- The analysis of sedimentary rock determines- The size and s.docx
1 a- The analysis of sedimentary rock determines-       The size and s.docx1 a- The analysis of sedimentary rock determines-       The size and s.docx
1 a- The analysis of sedimentary rock determines- The size and s.docx
Adamq0DJonese
 
0 points) Answer the questions on ListReferenceBased class (NOTE that.docx
0 points) Answer the questions on ListReferenceBased class (NOTE that.docx0 points) Answer the questions on ListReferenceBased class (NOTE that.docx
0 points) Answer the questions on ListReferenceBased class (NOTE that.docx
Adamq0DJonese
 
0 Conditional Format as Cell Cells Formatting - Table - Styles - Style.docx
0 Conditional Format as Cell Cells Formatting - Table - Styles - Style.docx0 Conditional Format as Cell Cells Formatting - Table - Styles - Style.docx
0 Conditional Format as Cell Cells Formatting - Table - Styles - Style.docx
Adamq0DJonese
 
-Pyro-Diversity- means the many species that grow back after a fire re.docx
-Pyro-Diversity- means the many species that grow back after a fire re.docx-Pyro-Diversity- means the many species that grow back after a fire re.docx
-Pyro-Diversity- means the many species that grow back after a fire re.docx
Adamq0DJonese
 

More from Adamq0DJonese (20)

1) What are the five tenets of wireless LAN (802-11) troubleshooting- (1).docx
1) What are the five tenets of wireless LAN (802-11) troubleshooting- (1).docx1) What are the five tenets of wireless LAN (802-11) troubleshooting- (1).docx
1) What are the five tenets of wireless LAN (802-11) troubleshooting- (1).docx
 
1) Water soluble compounds have lower bioconcentration factors than do.docx
1) Water soluble compounds have lower bioconcentration factors than do.docx1) Water soluble compounds have lower bioconcentration factors than do.docx
1) Water soluble compounds have lower bioconcentration factors than do.docx
 
1) Spatial Concepts of Location- Direction and Distance (absolute and.docx
1) Spatial Concepts of Location- Direction and Distance (absolute and.docx1) Spatial Concepts of Location- Direction and Distance (absolute and.docx
1) Spatial Concepts of Location- Direction and Distance (absolute and.docx
 
1) How are DNA and RNA similar and how are they different- 2) What are.docx
1) How are DNA and RNA similar and how are they different- 2) What are.docx1) How are DNA and RNA similar and how are they different- 2) What are.docx
1) How are DNA and RNA similar and how are they different- 2) What are.docx
 
1) Identify the following parts of a flower-2) Identify these flowers.docx
1) Identify the following parts of a flower-2) Identify these flowers.docx1) Identify the following parts of a flower-2) Identify these flowers.docx
1) Identify the following parts of a flower-2) Identify these flowers.docx
 
1) design a clocked latch version using NOR gates2) Design the version.docx
1) design a clocked latch version using NOR gates2) Design the version.docx1) design a clocked latch version using NOR gates2) Design the version.docx
1) design a clocked latch version using NOR gates2) Design the version.docx
 
1) Given the following program- Count -0 While (Count !- 5)- Count - C.docx
1) Given the following program- Count -0 While (Count !- 5)- Count - C.docx1) Given the following program- Count -0 While (Count !- 5)- Count - C.docx
1) Given the following program- Count -0 While (Count !- 5)- Count - C.docx
 
1) Explain at least two different things that can happen when a meteor.docx
1) Explain at least two different things that can happen when a meteor.docx1) Explain at least two different things that can happen when a meteor.docx
1) Explain at least two different things that can happen when a meteor.docx
 
1) Assume that you measure the OD of two E-coli cultures- culture A an.docx
1) Assume that you measure the OD of two E-coli cultures- culture A an.docx1) Assume that you measure the OD of two E-coli cultures- culture A an.docx
1) Assume that you measure the OD of two E-coli cultures- culture A an.docx
 
1) Define filtration- phagocytosis- pinocytosis- endocytosis and exocy.docx
1) Define filtration- phagocytosis- pinocytosis- endocytosis and exocy.docx1) Define filtration- phagocytosis- pinocytosis- endocytosis and exocy.docx
1) Define filtration- phagocytosis- pinocytosis- endocytosis and exocy.docx
 
1) A pair of fair dice were tossed- Assuming X represents the sum of t.docx
1) A pair of fair dice were tossed- Assuming X represents the sum of t.docx1) A pair of fair dice were tossed- Assuming X represents the sum of t.docx
1) A pair of fair dice were tossed- Assuming X represents the sum of t.docx
 
1 What are the advantages and disadvantages of globalization- Give exa.docx
1 What are the advantages and disadvantages of globalization- Give exa.docx1 What are the advantages and disadvantages of globalization- Give exa.docx
1 What are the advantages and disadvantages of globalization- Give exa.docx
 
1 point- Regarding chronic disease- which of the following statements.docx
1 point- Regarding chronic disease- which of the following statements.docx1 point- Regarding chronic disease- which of the following statements.docx
1 point- Regarding chronic disease- which of the following statements.docx
 
1 point Which of the following is an example of a Type I error- An inn.docx
1 point Which of the following is an example of a Type I error- An inn.docx1 point Which of the following is an example of a Type I error- An inn.docx
1 point Which of the following is an example of a Type I error- An inn.docx
 
1 Elonis v- United States- is the main case on 875(c)- What is the men.docx
1 Elonis v- United States- is the main case on 875(c)- What is the men.docx1 Elonis v- United States- is the main case on 875(c)- What is the men.docx
1 Elonis v- United States- is the main case on 875(c)- What is the men.docx
 
1 1- A government wants to provide student loans to students in their.docx
1 1- A government wants to provide student loans to students in their.docx1 1- A government wants to provide student loans to students in their.docx
1 1- A government wants to provide student loans to students in their.docx
 
1 a- The analysis of sedimentary rock determines- The size and s.docx
1 a- The analysis of sedimentary rock determines-       The size and s.docx1 a- The analysis of sedimentary rock determines-       The size and s.docx
1 a- The analysis of sedimentary rock determines- The size and s.docx
 
0 points) Answer the questions on ListReferenceBased class (NOTE that.docx
0 points) Answer the questions on ListReferenceBased class (NOTE that.docx0 points) Answer the questions on ListReferenceBased class (NOTE that.docx
0 points) Answer the questions on ListReferenceBased class (NOTE that.docx
 
0 Conditional Format as Cell Cells Formatting - Table - Styles - Style.docx
0 Conditional Format as Cell Cells Formatting - Table - Styles - Style.docx0 Conditional Format as Cell Cells Formatting - Table - Styles - Style.docx
0 Conditional Format as Cell Cells Formatting - Table - Styles - Style.docx
 
-Pyro-Diversity- means the many species that grow back after a fire re.docx
-Pyro-Diversity- means the many species that grow back after a fire re.docx-Pyro-Diversity- means the many species that grow back after a fire re.docx
-Pyro-Diversity- means the many species that grow back after a fire re.docx
 

Recently uploaded

PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
paigestewart1632
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 

Recently uploaded (20)

PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 

----------Evaluator-java---------------- package evaluator- import j.docx

  • 1. **********Evaluator.java**************** package evaluator; import java.util.*; import operand.Operand; import operator.Operator; public class Evaluator { private Stack<Operand> operandStack; private Stack<Operator> operatorStack; private StringTokenizer tokenizer; private static final String DELIMITERS = "+-*^/() "; public Evaluator() { operandStack = new Stack<Operand>(); operatorStack = new Stack<Operator>(); } public int eval(String expression) { int result = 0; String token; Operator hashOpr = Operator.operators.get("#"); oprStack.push(hashOpr); String delimiters = "+-*/#!"; // The 3rd argument is true to indicate that the delimiters should be used // as tokens, too. But, we'll need to remember to filter out spaces. this.tokenizer = new StringTokenizer(expression, DELIMITERS, true);
  • 2. while (this.tokenizer.hasMoreTokens()) { // filter out spaces if (!(token = this.tokenizer.nextToken()).equals(" ")) { // check if token is an operand if (Operand.check(token)) { operandStack.push(new Operand(token)); } else { if (!Operator.check(token)) { System.out.println("*****invalid token******"); System.exit(1); } // TODO Operator is abstract - this line will need to be fixed: // ( The Operator class should contain an instance of a HashMap, // and values will be instances of the Operators. See Operator class // skeleton for an example. ) Operator newOperator = null; // new Operator( token ); while (operatorStack.peek().priority() >= newOperator.priority()) { // note that when we eval the expression 1 - 2 we will // push the 1 then the 2 and then do the subtraction operation // This means that the first number to be popped is the // second operand, not the first operand - see the following code Operator oldOpr = operatorStack.pop(); Operand op2 = operandStack.pop();
  • 3. Operand op1 = operandStack.pop(); operandStack.push(oldOpr.execute(op1, op2)); } operatorStack.push(newOperator); } } } // Control gets here when we've picked up all of the tokens; you must add // code to complete the evaluation - consider how the code given here // will evaluate the expression 1+2*3 // When we have no more tokens to scan, the operand stack will contain 1 2 // and the operator stack will have + * with 2 and * on the top; // In order to complete the evaluation we must empty the stacks (except // the init operator on the operator stack); that is, we should keep // evaluating the operator stack until empty // Suggestion: create a method that takes an operator as argument and // then executes the while loop; also, move the stacks out of the main // method return 0; } /** * Class to help test your Evaluator: * javac EvaluatorTester
  • 4. * java EvaluatorTester "1+2" "3*5" */ public static void main(String[] args) { Evaluator evaluator = new Evaluator(); for (String arg : args) { System.out.format("%s = %dn", arg, evaluator.eval(arg)); } } } ************************************Operand.Java******************************* ******************* package operand; public class Operand { public Operand( String token ) { } public Operand( int value ) { } public int getValue() { return 0; } public static boolean check( String token ) { return false; } }
  • 5. *******************************************************EvaluatorTest.java******* **************************************** package tests; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import evaluator.Evaluator; public class EvaluatorTest { @Test void testSimpleAddition() { Evaluator evaluator = new Evaluator(); assertEquals(3, evaluator.eval("1 +2")); } @Test void testSimpleDivision() { Evaluator evaluator = new Evaluator(); assertEquals(0, evaluator.eval("1/2")); } @Test void testSimpleExpression() { Evaluator evaluator = new Evaluator(); assertEquals(7, evaluator.eval("1+2*3")); } @Test void testSimpleParenthesizedExpression() {
  • 6. Evaluator evaluator = new Evaluator(); assertEquals(9, evaluator.eval("(1+2)*3")); } @Test void testComplexExpressionWithNegativeResult() { Evaluator evaluator = new Evaluator(); assertEquals(7, evaluator.eval("2-(3/10)+2-5")); } @Test void testAnotherComplexExpressionWithNegativeResult() { Evaluator evaluator = new Evaluator(); assertEquals(-6, evaluator.eval("(6-12*2)/3")); } @Test void testSimpleExponentiation() { Evaluator evaluator = new Evaluator(); assertEquals(9, evaluator.eval("3^2")); } @Test void testSlightlyMoreComplexExponentiation() { Evaluator evaluator = new Evaluator(); assertEquals(4, evaluator.eval("3^2/2")); }
  • 7. @Test void testHardMode() { Evaluator evaluator = new Evaluator(); assertEquals(1176, evaluator.eval("2+3-5*((2-3)*2-5*2+3*(2-3-5-5*6)+4/2)*2-9")); } @Test void testProperStackUsage() { Evaluator evaluator = new Evaluator(); // Stacks should be emptied and in a valid state after the first evaluation occurs, // so the second evaluation should run without exception and provide assertEquals(6, evaluator.eval("1+2+3")); assertEquals(1, evaluator.eval("10-8-1")); } } ******************************************************OperandTest.java********* ********************************************************** package tests; import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.ArrayList; import java.util.Arrays; import org.junit.jupiter.api.Test; import operand.Operand;
  • 8. public class OperandTest { @Test void testCheck() { ArrayList<String> validOperands = new ArrayList<>(Arrays.asList( "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" )); validOperands.forEach(operand -> assertTrue(Operand.check(operand))); assertFalse(Operand.check("a")); } @Test void testGetValueFromOriginalString() { Operand operandOne = new Operand("3"); assertEquals(3, operandOne.getValue()); } @Test void testGetValueFromOriginalInt() { Operand operandTwo = new Operand(7); assertEquals(7, operandTwo.getValue()); } } *******************************************************OperatorTest.java******** ********************************************* package tests; import org.junit.jupiter.api.Test; import static org.junit.Assert.assertTrue;
  • 9. import static org.junit.jupiter.api.Assertions.assertFalse; import java.util.ArrayList; import java.util.Arrays; import operator.Operator; public class OperatorTest { @Test void testCheck() { ArrayList<String> validOperators = new ArrayList<>(Arrays.asList( "+", "-", "*", "/", "^" )); validOperators.forEach(operator -> assertTrue(Operator.check(operator))); assertFalse(Operator.check("1")); } } ****************************************************************************** **************** This is the readme [![Open in Visual Studio Code](https://classroom.github.com/assets/open-in-vscode- c66648af7eb3fe8bc4f294546bfd86ef473780cde1dea487d3c4ff354943c9ae.svg)](https://classroo m.github.com/online_ide?assignment_repo_id=10049933&assignment_repo_type=AssignmentR epo) # Assignment 1 Documentation Author: Eduardo Ruiz (please keep the Author: heading for my grading script) ## Overview of code skeleton The folders `.devcontainer`, `.vscode`, and `lib` contain configuration information that must not be deleted or modified. The remaining folders will be discussed in class. ## Scope of Work
  • 10. | Requirement | Completed? | Comments from student | | ------------------------- | ---------- | --------------------- | | 1 - Implement algorithm | [] | | | 2 - Tests | [] | | | 3 - Class implementations | [] | | ## Class diagrams REPLACE THIS TEXT: Include a diagram of all of the classes you worked with in this assignment, indicating their relationships. For each class, include a one line description of its responsibility. If you are looking for a tool to use to create the class diagram, check out [Mermaid](https://mermaid.js.org/syntax/classDiagram.html) - this allows you to write markdown in this file that will be rendered as class diagrams. ## Results and Conclusions ### What I Learned REPLACE THIS TEXT: Describe what you learned by completing this assignment ### Challenged I Encountered REPLACE THIS TEXT: Describe challenges you encountered completing this assignment, and how you overcame those challenges ******************************************************** ******************************************************** While the operator stack is not empty, pop the operator from the operator stack, create an operand object from the popped operator, and push it to the operand stack. While the operand stack has more than one operand, pop two operands from the operand stack and one operator from the operator stack, and apply the operator to the operands. Push the result back to the operand stack. The result of the expression is the single operand left on the operand stack. You are required to implement the missing parts of this algorithm in the eval method of the Evaluator class. Please help, thank you