Below is the Java method that checks if a given string is a valid car plate number according to the specified conditions.
public class CarPlateValidator {
public static void main(String[] args) {
String s1 = "CGF12345";
boolean b1 = plateNumber(s1);
System.out.println(b1); // Output: true
String s2 = "aGR12345";
boolean b2 = plateNumber(s2);
System.out.println(b2); // Output: false
String s3 = "73145478";
boolean b3 = plateNumber(s3);
System.out.println(b3); // Output: false
String s4 = "ABC123DC";
boolean b4 = plateNumber(s4);
System.out.println(b4); // Output: false
}
public static boolean plateNumber(String s) {
// Check if the string has exactly 8 characters
if (s.length() != 8) {
return false;
}
// Check if the first three characters are uppercase letters
for (int i = 0; i < 3; i++) {
if (!Character.isUpperCase(s.charAt(i))) {
return false;
}
}