Python代写|Assignment2 Image matching and retrieval


Implementation and Grading

Download the attached file to your computer. DO NOT unzip it. Instead, follow the instructions on the Eclipse page under the section “Importing a Zipped Project into Eclipse” to get the entire project into your Eclipse workspace.

You will see a project called Expression Evaluation with the following classes in package app:

  • Variable
    This class represents a simple variable with a single value. Your implementation will create one Variable object for every simple variable in the expression (even if there are multiple occurrences of the same variable). You don’t have to implement anything in this class, so do not make any changes to it.
  • Array
    This class represents an array of integer values. Your implementation will create one Array object for every array in the expression (even if there are multiple occurrences of the same array). You don’t have to implement anything in this class, so do not make any changes to it.
  • Expression
    This class consists of methods for various steps of the evaluation process:

    1. 20 ptsmakeVariableLists – This method populates the vars and arrays lists with Variable and Array objects, respectively, for the simple variable and arrays that appear in the expression.
      You will fill in the implementation of this method. Make sure to read the comments above the method header to get more details.
    2. loadVariableValues – This method reads values for all simple variables and arrays arrays from a file, into the Variable and Array objects stored in the vars and arrays array lists. This method is already implemented, do not make any changes.
    3. 60 ptsevaluate – This method evaluates the expression.
      You will fill in the implementation of this method.
  • Evaluator, the application driver, which calls methods in Expression. You may use this to test your implementation. There are two sample test files etest1.txt and etest2.txt, appearing directly under the project folder.

You are also given the following class in package structures:

  • Stack, to be (optionally) used in the evaluation process

Do not add any other classes. In particular, if you wish to use stacks in your evaluation implementation do NOT use your own stack class, ONLY use the one you are given. The reason is, we will be using this same Stack class when we test your implementation.


Notes on tokenizing the expression

You will need to separate out (“tokenize”) the components of the expression in makeVariableLists and evaluate. Tokens include operands (variables and constants), operators ('+','-','*','/'), parentheses and square brackets.

It may be helpful (but you are not required) to use java.util.StringTokenizer to tokenize the expression. The delims field in the Expression class may be used in the tokenizing process.

The documentation of the StringTokenizer class says this:


    •  is a legacy class that is retained for compatibility reasons although its use is discouraged in new code. It is recommended that anyone seeking this functionality use the split method of


    •  or the


     package instead.”

For the purpose of this assignment, you may use StringTokenizer without issue. Alternatively, you may use the split method of the String class, or the Pattern and Matcher classes in the package java.util.regex.

Or, you may simply parse the expression by scanning it a character at a time.


Rules while working on

  • You may NOT add any import statements to the file.
    Note that the*java.util.*, and java.util.regex.* import statements at the top of the file allow for using ANY class in java.iojava.util, and java.util.regex without additional specification or qualification.
  • You may NOT add any fields to the Expression class.
  • You may NOT modify the headers of any of the given methods.
  • You may NOT delete any methods.
  • You MAY add helper methods if needed, as long as you make them private. (Including the recursive evaluate method discussed below.)


Guidelines and recommendations for implementing evaluate

  • Recursion (optional) for sub-expressions in parenthesesWhile recursion is optional for this assignment, using it to evaluate subexpressions will make it a LOT easier to write working code. (This is a great opportunity to learn how to use recursion in a realistic situation!!)There are a couple of coding options if you want to use recursion:
    • One option is to make the public evaluate method itself recursive.So, for instance, if the main expression is
      01234567891111111  (these are the positions of the characters in the expression)

      then, to recursively evaluate the subexpression in parentheses, you may call the recursive evaluate method like this:

        float res = evaluate(expr.substring(3,11), vars, arrays);
    • Another option is to write a separate private recursive evaluate method, with two indexes that mark the start and end of the subexpression in the main expression. Then, for the above example, you can call the recursive method like this:
         float res = evaluate(expr, 3, 11, vars, arrays);

      (The expr parameter is the original expression for every call.)And, to start with, you may call the recursive evaluate method from the public evaluate method like this:

         return evaluate(expr, 0, expr.length()-1, vars, arrays);

      which is the entire expression.You will need to use this second option if you want to include other parameters in your recursive evaluate.

    In either case, the auto grader will call the public evaluate method.

  • Recursion (optional) for array index expressions (within ‘[ and ‘]’), using the same approach as above.
  • A stack may be used to store the values of operands as well as the results from evaluating subexpressions – see next point.
  • Since * and / have precedence over + and -, it would help to store operators in another stack. (Think of how you would evaluate a+b*c with operands/intermediate results on one stack and operators on the other.)
  • When you implement the evaluate method, you may want to test as you go, implementing code for and testing simple expressions, then building up to more complex expressions. The following is an example sequence of the kinds of expressions you may want to build with:
    • 3
    • a
    • 3+4
    • a+b
    • 3+4*5
    • a+b*c
    • Then introduce parentheses
    • Then try nested parentheses
    • Then introduce array subscripts, but no parentheses
    • Then try nested subscripts, but no parentheses
    • Then try using parentheses as well as array subscripts
    • Then try mixing arrays within parentheses, parentheses within array subscripts, etc.


Correctness of expression and input files

  • All input expressions will be correctly formatted
  • All input files with values for variables and arrays will be correctly formatted, and will be guaranteed to have values for all variables in the expression that is being evaluated

So you don’t need to do any checking for correctness of inputs in any of the methods.