I've created a class to receive an object with a date and verify by a method if the date is writen correctly. The problem is that my code doesn't work to verify the characters correctly.
Here I have the objects called at main function:
hoje.constructor("12/03/2023"); //right date
amanha.constructor("0//03/2003"); //wrong date
And here are the method construtor() at Date Class:
public void constructor(String dateInsert){
if (dateInsert.length() != 10){
this.date = "01/01/0001";
} else {
boolean isADate = true;
for(int i = 0 ; i < dateInsert.length() ; i++){
char c = dateInsert.charAt(i);
String letter = "" + c;
if(Character.isDigit(c) == false && letter == "/"){
if(i != 2 || i != 5){
isADate = false;
} else {
isADate = true;
}
} else {
isADate = true;
}
}
if(isADate == true){
this.data = dateInsert;
} else {
this.data = "01/01/0001";
}
}
}