I have put the condition for that case where phoneNumber is null, but still same error. I also have the right output for all the examples
Can anyone help me, please??
package com.codegym.task.task22.task2212;
/*
Phone number verification
*/
public class Solution {
public static boolean checkPhoneNumber(String phoneNumber) {
int leng = phoneNumber.replaceAll("[^0-9]","").length();
if ( phoneNumber.equals(null) ) return false;
if (phoneNumber.contains("[a-zA-Z]+")) return false;
if (!(leng == 12) && !(leng == 10)) return false;
String[] array = phoneNumber.split("");
if (array[0].equals("+")){
if (leng == 12 && hasParanteses(phoneNumber)) return true;
}
if (array[0].equals("+") && !(leng == 12) ) return false;
if ((leng == 10) && hasParanteses(phoneNumber)) return true;
return false;
}
public static boolean hasParanteses(String number){
int open = 0;
int closed = 0 ;
boolean isOpen = false;
boolean isClosed = false;
int firstLine = 0;
int secondLine = 0;
boolean isFirstLine = false;
boolean isSecondLine = false;
int countLines = 0;
int allLines = 0;
int countParantses = 0;
boolean areCorect = false;
String[] arr = number.split("");
for (int i = 0 ; i < arr.length; i++){
if (arr[i].equals("(") || arr[i].equals(")")) countParantses++;
if (arr[i].equals("(")){
open = i;
isOpen = true;
}
if (arr[i].equals("-")) allLines++;
if (arr[i].equals(")")){
closed = i;
isClosed = true;
}
if (countLines == 1 && arr[i].equals("-")){
isSecondLine = true;
secondLine = i;
countLines++;
}
if ((isFirstLine == false) && arr[i].equals("-")){
isFirstLine = true;
firstLine = i;
countLines++;
}
}
if (allLines > 2) return false;
if (open > closed) return false;
if(isFirstLine && (firstLine < closed) ) return false;
if (isSecondLine && secondLine < closed) return false;
if (secondLine - firstLine == 1) return false;
if (countParantses > 2) return false;
if (isClosed && isOpen) {
if (!((closed - open) == 4)) return false;
}
if ((closed - open) == 4) areCorect = true;
return true;
}
public static void main(String[] args) {
System.out.println(checkPhoneNumber("(0)501234567"));
//System.out.println(hasParanteses("+38(050)1234567"));
}
}