Class Interval


  • public class Interval
    extends java.lang.Object
    A class for an interval of numbers
    Author:
    Bhagat
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private double lowerBound
      the lower bound
      private boolean open
      whether it is open or not
      private double upperBound
      the upper bound
    • Constructor Summary

      Constructors 
      Constructor Description
      Interval​(double lowerBound, double upperBound)
      creates an interval with a lower and upper bound (defaults open to false)
      Interval​(double lowerBound, double upperBound, boolean open)
      creates an interval with a lower and upper bound and whether it is open or not
    • Field Detail

      • lowerBound

        private double lowerBound
        the lower bound
      • upperBound

        private double upperBound
        the upper bound
      • open

        private boolean open
        whether it is open or not
    • Constructor Detail

      • Interval

        public Interval​(double lowerBound,
                        double upperBound,
                        boolean open)
        creates an interval with a lower and upper bound and whether it is open or not
        Parameters:
        lowerBound - the lower bound
        upperBound - the upper bound
        open - whether it is open or not
      • Interval

        public Interval​(double lowerBound,
                        double upperBound)
        creates an interval with a lower and upper bound (defaults open to false)
        Parameters:
        lowerBound - the lower bound
        upperBound - the upper bound
    • Method Detail

      • inInterval

        public boolean inInterval​(double x)
        checks if a number is inside this interval
        Parameters:
        x - the number
        Returns:
        whether or not the number is inside the interval
      • range

        public double range()
        Returns:
        the range of the interval
      • midpoint

        public double midpoint()
        Returns:
        the midpoint of the interval
      • getLowerBound

        public double getLowerBound()
        Returns:
        the lowerBound
      • setLowerBound

        public void setLowerBound​(double lowerBound)
        Parameters:
        lowerBound - the lowerBound to set
      • getUpperBound

        public double getUpperBound()
        Returns:
        the upperBound
      • setUpperBound

        public void setUpperBound​(double upperBound)
        Parameters:
        upperBound - the upperBound to set
      • isOpen

        public boolean isOpen()
        Returns:
        the open
      • setOpen

        public void setOpen​(boolean open)
        Parameters:
        open - the open to set