Record Class IfZero

All Implemented Interfaces:
Expr

public record IfZero(Expr test, Expr thenAns, Expr elseAns) extends Record implements Expr
Our internal representation of a IfZero expr in the OG0 language. See http://www.radford.edu/itec380/2024fall-ibarland/Project
  • Field Details

  • Constructor Details

    • IfZero

      public IfZero(Expr test, Expr thenAns, Expr elseAns)
      Creates an instance of a IfZero record class.
      Parameters:
      test - the value for the test record component
      thenAns - the value for the thenAns record component
      elseAns - the value for the elseAns record component
  • Method Details

    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in interface Expr
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • parse

      public static IfZero parse(Scanner s, String punctuation)
    • eval

      public Value eval()
      Description copied from interface: Expr
      Evaluate a given Expr.
      Specified by:
      eval in interface Expr
      Returns:
      the Value this Expr evaluates to. (In OG0, all values are numbers (doubles), but in OG3 that will change, which is why we have pre-emptively made the return type 'Value'.)
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • test

      public Expr test()
      Returns the value of the test record component.
      Returns:
      the value of the test record component
    • thenAns

      public Expr thenAns()
      Returns the value of the thenAns record component.
      Returns:
      the value of the thenAns record component
    • elseAns

      public Expr elseAns()
      Returns the value of the elseAns record component.
      Returns:
      the value of the elseAns record component