Due: Sunday Nov 08, 2020 before 11:59PM
The main goals of this lab are to:
There are six kinds of (binary) expressions: addition
, subtraction
, multiplications
, equality
, greater-than
, and less-than
. The first three kinds are arithmetic expressions which evaluate to integers. The last three kinds are relational expressions which evaluate to Booleans (i.e., true or false). These six expression classes both inherit a more general class Expression
, which maintains some basic attributes and methods that are common to all the six expressions (e.g., attributes to store operands and value, method to get value).
There are four kinds of expression collectors (each of which collecting a list of expressions):
add-all
collector adds up the evaluation results of its collected expressions. When there are no expressions collected, the default evaluation result is 0.
times-all
collector multiplies the evaluation results of its collected expressions. When there are no expressions collected, the default evaluation result is 1.
conjoin-all
collector takes the conjunction (logical AND) of the evaluation results of its collected expressions. When there are no expressions collected, the default evaluation result is true.
disjoin-all
collector takes the disjunction (logical OR) of the evaluation results of its collected expressions. When there are no expressions collected, the default evaluation result is false.
These four classes both inherit a more general class ExpressionCollector
, which maintains basic attributes and that are common to all the four collectors (e.g., the list to maintain the expression collectors, method to get result value).
The figure below shows the two inheritance hierarchies for expressions and expression collector which you are required to implement. They are also hinted in the JUnit tests given to you. Each arrow in the diagram corresponds to the extends
keywords in Java.
You can assume that an expression collector only evaluates its collected expressions when it is type-correct: the collected expressions are either all arithmetic expressions (for add-all
and times-all
collectors) or all relational expressions (for conjoin-all
and disjoin-all
collections). We define that two expression collectors are equal if they are both type-correct and their evaluation results are the same.
Download the shell project from the following zip file. DO NOT DOUBLE CLICK TO OPEN THIS ZIP FILE! You should import the project from the archive into your workspace as outlined in Lab 1.
Implement the given inheritance hierarchies, by
Expression.java
and creating subclasses of it. As hinted in the JUnit test class, they should be named
Addition.java
, Subtraction.java
, Multiplication.java
, GreaterThan.java
, LessThan.java
and Equal.java
ExpressionList.java
and creating subclasses of it, namely ConjoinAll.java
, DisjoinAll.java
, TimesAll.java
and AddAll.java
Given a JUnit test class (which relies on certain API of methods) and its expected outputs, complete the base classes, and implement the hinted subclasses such that all tests pass. Study the JUnit test class carefully to see what the expected outputs are for the various methods to be implemented. You may want to complete the Expression
class and its subclasses (and pass the first 7 test cases), and then do the ExpressionCollectors
and its subclasses.
You may also find wrapper classes useful for manipulating results of evaluations. A wrapper class example is provided to you, which may help you understand how wrapper classes work.
A local copy of the Java API can be found here.
You should submit files Expression.java
and its 6 subclasses, as well as ExpressionCollector.java
and its 4 subclasses .
To submit your solution via the terminal (assuming you have used remotelab to build your code and complete the lab), first navigating to your the src directory for your project, and then issue the submit
command into the terminal window to submit fiels one by one:
submit 2030 lab6 Expression.java submit 2030 lab6 Addition.java submit 2030 lab6 Subtraction.java ...
or, submit some or all file together, for example,
submit 2030 lab6 Expression.java ExpressionList.java submit 2030 lab6 Addition.java Subtraction.java Multiplication.java submit 2030 lab6 GreaterThan.java LessThan.java Equal.java ...
At any time, you can issue submit -l 2030 lab6
into the terminal to check the files that you have submitted for lab6.
Alternatively, if you are using Eclipse on your own machine, you can upload your files through web submit .
Make sure you choose 2030 for the course, and lab6 for the assignment. Upload java files only, DO NOT SUBMIT the ZIP file of your project!