Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Assignment 7 Herschel Wiseman Ana Zorlas
- //Interface to represent an IArith
- interface IArith {
- //Accepts an IArithVisitor
- <R> R accept (IArithVisitor<R> visitor);
- }
- //Object representing a constant double
- class Const implements IArithVisitor {
- double num;
- //Constructor
- Const(double num) {
- this.num= num;
- }
- //Accepts the IArithVisitor
- public <R> R accept(IArithVisitor<R> visitor) {
- return visitor.Const(this);
- }
- }
- //Object representing a Formula
- class Formula implements IArith {
- IFunc2<Double, Double, Double> fun;
- String name;
- IArith left;
- IArith right;
- //Constructor
- Formula(IFunc2<Double, Double, Double> fun, String name, IArith left, IArith right) {
- this.fun = fun;
- this.name = name;
- this.left = left;
- this.right = right;
- }
- @Override
- public <R> R accept(IArithVisitor<R> visitor) {
- // TODO Auto-generated method stub
- return null;
- }
- }
- //Interface for three argument function-objects with signature [A1, A2, A3 -> R]
- interface IFunc2<A1, A2, A3, R> {
- R apply(A1 arg1, A2 arg2, A3 arg3);
- }
- // Visitor thingy
- interface IArithVisitor<R> {
- R Formula(T t);
- R Const(T t);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement