Question

In: Computer Science

Meant to be written in Java JDK 14.0 In New York state, the vehicle plate number...

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

Solutions

Expert Solution

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");
        }
    }
}


Related Solutions

Meant to be written in Java JDK 14.0 A String object is called palindrome if it...
Meant to be written in Java JDK 14.0 A String object is called palindrome if it is same when read from the front and the end. For example, String “abcba” is palindrome, while “12322” is not. Write Java program to check a String object of 5 characters is palindrome or not: (a) The comparison is case sensitive (b) The comparison is case insensitive
Meant to be written in Java JDK 14.0 Write a program to display the conversion table...
Meant to be written in Java JDK 14.0 Write a program to display the conversion table from meter to feet using formatted output (printf()): 1 meter = 3.28084 feet; 1 foot = 12 inch When display the number, round the number to 2 decimal places. Set the number in the 1st the 2nd columns to the left align, set the 3rd column to the right align: meter(s) feet inch(es) 1 3.28 37.37 2 x.xx xx.xx 3 x.xx xxx.xx
Meant to be written in Java JDK 14.0 4. Define 2 String variables str1 and str2,...
Meant to be written in Java JDK 14.0 4. Define 2 String variables str1 and str2, get input from console and assign input to str1 and str2. (a) Display the length of str1 and str2 (b) Display the first and last characters in str1 and str2 (c) Compare str1 and str2 to check if they are equal or not: (1) The comparison is case sensitive (2) The comparison is case insensitive (d) Compare str1 with str2 to check which string...
Meant to be written in Java JDK 14.0 1. Define 2 double variables. (a) Use method(s)...
Meant to be written in Java JDK 14.0 1. Define 2 double variables. (a) Use method(s) define in Math class to check if these 2 numbers are equal or not. Display result (b) Write code (not to use Math method) check if these 2 numbers are equal or not. Display result
Explain the the role of the the New York State Government and the agencies that make...
Explain the the role of the the New York State Government and the agencies that make up his cabinet.
Review the fiscal monitoring program in New York State. State the strengths and how they can...
Review the fiscal monitoring program in New York State. State the strengths and how they can be improve and weaknesses and how they can be eradicated. After reviewing: 1) three things you have learned about assessing fiscal health in terms of why monito, how to measure, how to report fiscal stress, and 2) how changing social, political, economic and demographic factos impact fiscal health. Thanks!
Use the regression equation to predict the number of motor vehicle fatalities in a western state...
Use the regression equation to predict the number of motor vehicle fatalities in a western state with a population of 4 million people (40 hundred thousand people). Does this answer seem reasonable based on the given data? Why or why not? Population (hundreds of thousands) = 3.3277772 + 0.054110317 Motor Vehicle Fatalities Motor Vehicle Fatalities Population (hundreds of thousands) 87 7 1117 50 742 47 119 13 264 14 270 9 381 24 449 19 436 36 328 25 659...
The following are some of the financial statements required in the State of New York CAFR:...
The following are some of the financial statements required in the State of New York CAFR: Government-wide statement: statement of net position Government-wide statement: statement of activities Fund statement: balance sheet–governmental funds Fund statement: statement of revenues, expenditures and changes in fund balances—governmental funds Fund statement: statement of net position–proprietary funds Fund statement: statement of revenues, expenses and changes in net position–proprietary funds For each of the following balances related to the financial performance of the State of New York,...
The following are some of the financial statements required in the State of New York CAFR:...
The following are some of the financial statements required in the State of New York CAFR: 1. Government-wide statement: statement of net position 2. Government-wide statement: statement of activities 3. Fund statement: balance sheet—governmental funds 4. Fund statement: statement of revenues, expenditures and changes in fund balances—governmental funds 5. Fund statement: statement of net position–proprietary funds 6. Fund statement: statement of revenues, expenses and changes in net position—proprietary funds   For each of the following balances related to the financial performance...
A random sample of elementary school children in New York state is to be selected to...
A random sample of elementary school children in New York state is to be selected to estimate the proportion p p who have received a medical examination during the past year. It is desired that the sample proportion be within 0.045 of the true proportion with a 98 98 % level of confidence (a) Assuming no prior information about p p is available, approximately how large of a sample size is needed? If a planning study indicates that pp is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT