SHARE
TWEET

Range class

a guest Mar 25th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. public class Range {
  3.     //fields
  4.     private int min;
  5.     private int max;
  6.    
  7.     //constructor
  8.     public Range(String inputString) {
  9.         if (inputString.contains("-")){
  10.             min = Integer.parseInt(inputString.substring(0, inputString.indexOf("-")));
  11.             max = Integer.parseInt(inputString.substring(inputString.indexOf("-") + 1));
  12.         } else {
  13.             min = Integer.parseInt(inputString);
  14.             max = min;
  15.         }
  16.     }
  17.    
  18.     //getters
  19.     public boolean contains(int n) {
  20.         return (n >= min && n <= max);
  21.     }
  22.    
  23.     public int getMax() {
  24.         return max;
  25.     }
  26.    
  27.     public int getMin() {
  28.         return min;
  29.     }
  30. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top