isPrime method

bool isPrime()

Determine if the number is prime

Implementation

bool isPrime(){
  if(this == 2 || this == 3){
    //2 and 3 are prime
    return true;
  }else if(this < 2){
    //Primes are positive integers greater than or equal to 2
    return false;
  }else if(this == 4){
    //Have this condition for 4 because using int maxIterations = (this / 4).ceil(); makes 4 look like its prime and int maxIterations = (this / 2).ceil(); makes creates more iteration than necessary on number greater than 4
    return false;
  }else if(_meetsDivisibilityCriteria(this)){
    return false;
  }else{
    int maxIterations = (this / 4).ceil();
    bool canBeDivided = false;
    int i = 2;
    while(canBeDivided == false && i <= maxIterations){
      if(this % i == 0){
        canBeDivided = true;
      }
      i++;
    }
    if(canBeDivided){
      //Prime numbers shouldn't be divisible
      return false;
    }else{
      //If cannot be divided it is prime
      return true;
    }
  }
}