In: Computer Science
Meant to be written in Java JDK 14.0
In New York state, the vehicle plate number has the following format: xxx-yyyy, where x is a letter and y is a digit. Write a program to enter a string, verify if it is a valid plate number or not
import java.util.Scanner;
public class NewYorkPlateNumber {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter a plate number: ");
        String s = in.nextLine();
        boolean isValid = s.length() == 8
                && Character.isAlphabetic(s.charAt(0)) && Character.isAlphabetic(s.charAt(1))
                && Character.isAlphabetic(s.charAt(2)) && s.charAt(3) == '-'
                && Character.isDigit(s.charAt(4)) && Character.isDigit(s.charAt(5))
                && Character.isDigit(s.charAt(6)) && Character.isDigit(s.charAt(7));
        if (isValid) {
            System.out.println(s + " is a valid plate number");
        } else {
            System.out.println(s + " is not a valid plate number");
        }
    }
}
