Program to Generate Vehicle Number
In this article, we will be creating a simple java program to generate a unique number plate. for this let’s understand the format in which number plates can be generated.
The number plate for a vehicle consists of 4 parts:
- State code : first 2 letters represent the State or Union Territory to which the vehicle is registered.
- District code : a two-digit number allocated to a district within the respective state or Union Territory.
- Single or Multiple Alphabet : this represents unique alphabet for the number plate.
- Number between 1 to 9999 : it is assigned sequentially and unique for each registration.
Note: we will consider this standard way for generating a number plate it can have certain variations based on country.
so let’s start implementation:
Step 1: we will create a list which will have list of all state .
Step 2: based on selected state we will generate a number under the range of available all district.
Step 3: here we will generate an unique alphabet and a number between 1 to 9999.
Step 4: here we will combine all things in a single variable to print it.
let’s create a map that will have state names as keys and total available districts as values.
Elements to build number plate
state name+ district code(randomly generated according to state )+ unique generate alphabet+ random number
Gujarat has 33 districts so the key would be GJ and the value would be 37(generates any number from 1 to 37)
Let’s breakdown the format to understanding.
Example: GJ 01 BC 0000
Example: We have used 1-37 random numbers as district numbers in the state but if you want to apply you need to make another nested map where we will store names of all the districts with the district code associated with it.
Please Login to comment...