Question: . Mars Ticket.java Requirements: The purpose of this program is to accept coded ticket information as input that includes the price, discount, time, date, seat,



. Mars Ticket.java Requirements: The purpose of this program is to accept coded ticket information as input that includes the price, discount, time, date, seat, followed by the description of the ticket. Note that the nine digits for price and two digits for discount have an implied decimal point. The program should then print the ticket information including the actual cost, which is the price with discount applied. The last line of the ticket information should contain a random "prize number" between 1 and 999999 inclusive that should always be printed as six digits (e.g., 1 should be printed as 000001). The coded input is formatted as follows: 1250000002518300715204119ASpaceX-001 Earth to Mars date seat ticket description (goes through last character in the code) time discount [25 has an implied decimal point for 0.25 (or 25%] price [125000000 has an implied decimal point for 1250000.00] Whitespace before or after the coded information should be disregarded (e.g., if the user enters spaces or tabs before or after the coded information, these should be disregarded). Your program will need to print the ticket description, date, time, seat number, price, discount, and cost, and a random prize number in the range 1 to 999999 as shown in the examples below. If the user enters a code that does not have at least 27 characters, then an error message should be printed. [The 27th character of the code is part of the ticket description.] Design: Several examples of input/output for the program are shown below. Line # Program output Enter ticket code: War Eagle to all on Mars! BNMS *** Invalid Ticket Code *** Ticket code must have at least 27 characters, Note that the ticket code entered below results in the indicated output except for the prize number which is random. When more than one item is shown on the same line (e.g., ticket, date, and time on line 3), there are three spaces between them (do not use the tab escape sequence \t). Line # Program butput Enter ticket code: 12500000025183 007115204119ASpacex001 Earth to Mars 1 2 Ticket: SpaceX-001 Earth to Mars Seat: 19A Price: $1,250,000.00 Prize Number: 867318 Date! 07/15/2041 Time: 18:30 Discount: 25% Cast: $937,500.00 4 5 6 Note that the ticket code entered below includes a 50% discount. Line # Program output 1 Enter ticket code: 1250000005018300715204119ASpaceX-001 Earth to Mars 2 3 Ticket: SpaceX-001 Earth to Mars Date: 07/15/2041 Time: 18:30 4 Seat: 19A Price: $1,250,000.00 Discount: 50% Cost: $625,000.00 5 Prize Number: 479194 6 Note that the ticket code below has 10 leading spaces (be sure you are trimming the input code). It also includes a 75% discount. Line # Program output Enter ticket code: 1250000007518300715204119ASpaceX-001 Earth to Mars 1 2 3 Ticket: SpaceX-001 Earth to Mars Seat: 19A Price: $1,250,000.00 Prize Number: 432239 Date: 07/15/2041 Time: 18:30 Discount: 75% Cost: $312,500.00 4 5 6 Code: In order to receive full credit for this assignment, you must use the appropriate Java API classes and methods to trim the input string, to extract the substrings, conversion of substrings of digits to numeric values as appropriate, and formatting. These include the String methods trim, and substring, as well as wrapper class methods such Double.parseDouble which can be used to convert a String of digits into a numeric value for price and discount. The dollar amounts should be formatted so that both small and large amounts are displayed properly, and the prize number should be formatted so that seven digits are displayed including leading zeroes, if needed, as shown in the examples above. It is recommended as a practice that you not modify input values once they are stored. Test: You are responsible for testing your program, and it is important to not rely only on the examples above. Remember, when entering standard input in the Run 1/0 window, you can use the up-arrow on the keyboard to get the previous values you have entered. This will avoid having to retype the ticket code each time you run your program. Hints: 1. The ticket code should be read in all at once using the Scanner's nextLine method and stored in a variable of type String. Then the individual values should be extracted using the substring method. The String value for price and discount should be converted to type double (using Double.parseDouble) so that it can be used to calculate cost. When printing the values for price, discount, cost, and prize number, they should be formatted properly by creating an appropriate DecimalFormat object (see patterns below) and calling its format method. To format price and cost, use the pattern "S#,##000" when you create your DecimalFormat object. To format discount, use the pattern "09" when you create your DecimalFormat object. Project: Using Java API Classes Page 5 of 5 For prize number, use the pattern "000000" when you create your DecimalFormat object. 2. Since all items in the ticket code other than the price and discount will not be used in arithmetic expressions, they can and should be left as type String. 3. The time and date should have leading zeros as appropriate. Therefore, these can be printed as String values by concatenating their components with ":" in the time and "/" in the date as needed
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
