Assignment title: Information
Q
Q
Write a Java program called calcTickets that prompts (asks) the user to enter a ticket number. The format of a valid ticket is CDDD[C][C][C] where D = a digit and C = a character and [C] means that the character at this position is optional. The only valid characters at the start of the ticket are 'A', 'C', or 'T' If there is only one optional character at the end of the ticket String, then that character may only be 'X', 'B' or 'K' If there are two optional characters at the end of the ticket String, then the characters can only be 'B' and 'X', or 'K' and 'X', in that order. If there are three optional characters at the end of the ticket String, then the characters can only be 'X', 'B' and 'K', in that order. So an example of a valid ticket could be: T876BX The user may enter a ticket String of any length. The valid length of a ticket is between 4 and 7 depending on the conditions above. Any ticket that is not in this length range is automatically invalid. A ticket that is invalid for any reason will result in a message being displayed to the screen saying that the ticket is invalid, and no processing will be done with that ticket. Every effort should be made to give the exact reason why the ticket is invalid. For example, wrong length, starts with an invalid character, or ends with an invalid character. These are not the only reasons why a ticket is invalid, part of your task is to list all the conditions that make a ticket invalid and write code to cover those cases. If a ticket is a valid length, you may assume that the digit part of the ticket is entered correctly. That is, it is exactly 3 digits and follows the character at the start of the ticket String. Note that this means that the first character can be anything on the keyboard including a digit or a punctuation mark. You do not have to check that the contents in the 2nd, 3rd and 4th positions in the ticket String are digits. You do, however, need to convert the 3 character/digits into a base 10 integer. Hint: consider that when we enter 0 at the keyboard we are entering the character '0' which has an ASCII/Unicode of 48. So what we are really storing is the base 10 number 48. We need to convert this from character 0 to integer 0. 1 is actually character '1' with ASCII/Unicode value 49 and so on