Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. //Assignment 7 Herschel Wiseman Ana Zorlas
  2.  
  3.  
  4. //Interface to represent an IArith
  5. interface IArith {
  6.  
  7. //Accepts an IArithVisitor
  8. <R> R accept (IArithVisitor<R> visitor);
  9. }
  10.  
  11. //Object representing a constant double
  12. class Const implements IArithVisitor {
  13. double num;
  14.  
  15. //Constructor
  16. Const(double num) {
  17. this.num= num;
  18. }
  19.  
  20. //Accepts the IArithVisitor
  21. public <R> R accept(IArithVisitor<R> visitor) {
  22. return visitor.Const(this);
  23. }
  24. }
  25.  
  26. //Object representing a Formula
  27. class Formula implements IArith {
  28. IFunc2<Double, Double, Double> fun;
  29. String name;
  30. IArith left;
  31. IArith right;
  32.  
  33. //Constructor
  34. Formula(IFunc2<Double, Double, Double> fun, String name, IArith left, IArith right) {
  35. this.fun = fun;
  36. this.name = name;
  37. this.left = left;
  38. this.right = right;
  39. }
  40.  
  41. @Override
  42. public <R> R accept(IArithVisitor<R> visitor) {
  43. // TODO Auto-generated method stub
  44. return null;
  45. }
  46. }
  47.  
  48.  
  49. //Interface for three argument function-objects with signature [A1, A2, A3 -> R]
  50. interface IFunc2<A1, A2, A3, R> {
  51. R apply(A1 arg1, A2 arg2, A3 arg3);
  52. }
  53.  
  54. // Visitor thingy
  55. interface IArithVisitor<R> {
  56. R Formula(T t);
  57. R Const(T t);
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement