Class BalanceChecker

java.lang.Object
BalanceChecker
All Implemented Interfaces:
BalanceChecker_Interface

public class BalanceChecker extends Object implements BalanceChecker_Interface
Checks for balanced symbols. HW 09.
Author:
Dr. Lillis
  • Constructor Details

    • BalanceChecker

      public BalanceChecker()
      Default constructor for the BalancedChecker.
  • Method Details

    • addPair

      public void addPair(Character open, Character close)
      Adds a pair of open/close characters.
      Specified by:
      addPair in interface BalanceChecker_Interface
      Parameters:
      open - The opening character to add.
      close - The closing character to add.
      Throws:
      DuplicateCharacterException - if either character has already been added.
    • isBalanced

      public boolean isBalanced(String s)
      Checks the given parameter and returns true if it contains balanced symbols and returns false if the symbols are not balanced.
      Specified by:
      isBalanced in interface BalanceChecker_Interface
      Parameters:
      s - The string to check.
      Returns:
      true of the given string contains balanced symbols, returns false otherwise.
    • isOpening

      public boolean isOpening(Character c)
      Checks to see if the given character has already been added as an opening symbol.
      Specified by:
      isOpening in interface BalanceChecker_Interface
      Parameters:
      c - The character to look for.
      Returns:
      true if the given character has already been added as an opening symbol.
    • isClosing

      public boolean isClosing(Character c)
      Checks to see if the given character has already been added as a closing symbol.
      Specified by:
      isClosing in interface BalanceChecker_Interface
      Parameters:
      c - The character to look for.
      Returns:
      true if the given character has already been added as a closing symbol.
    • match

      public boolean match(Character c1, Character c2)
      Check of the two given characters are a match.
      Specified by:
      match in interface BalanceChecker_Interface
      Parameters:
      c1 - The first character to check.
      c2 - The second character to check.
      Returns:
      true of the two symbols match, false otherwise.