Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hints TimeTravel class 1. The ticket code should be read in all at once and stored in a variable of type String, after which the

image text in transcribed
image text in transcribed
Hints
TimeTravel class
1. The ticket code should be read in all at once and stored in a variable of type String, after
which the individual values should be extracted using the substring method. The String value
for price should be converted to type double (using Double.parseDouble) so that it can be
used to calculate cost. When printing the values for price and cost, they should be formatted
properly by creating an appropriate DecimalFormat object and calling its format method.
Since all items other than the price will not be used in arithmetic expressions, they can be left
as String values (or char value in the case of category).
2. Since char values are primitive types, == and != can be used to compare two values for
equality and inequality respectively. Thus, if the category is extracted from the input using
the String method charAt() which returns a char, then == and != can be used to compare char
values.
Otherwise, if category is a String, you should not use == and != to compare two String
values. String values should be compared for equality using the String equals method which
has a boolean return type. For example, if s1 and s2 are String objects, to check to see if their
respective character strings are equal you should use
s1.equals(s2)
rather than
s1 == s2
which is only true if s1 and s2 are aliases for the same String object.
The time and date should have leading zeros as appropriate. Therefore, these can be printed as String
values by concatenating their components with ":" and "/" as needed.
TimeTravel.java Requirements: The purpose of this program is to accept coded ticket information to another time and place (and back) as input that includes the date, time, category, price, and seat, followed by the description of the travel. Note that the nine digits for price have an implied decimal point. The program should then print the ticket information including the actual cost, which is the price with discount applied as appropriate: 50% for a student ticket (s), 25% for employee ticket(e), and none for regular tickets (i.e., anything other than s or e). The last line of the ticket should contain a "prize number" between I and 9999 inclusive that should always be printed as 4 digits (e.g., 7 should be printed as 0007). The coded input is formatted as follows: 153012152090s02498990018BTime Machine 7 to NYC 12/31/1880 time date ticket description (goes through last character in the code) category scat category [s, e, any other character is a regular ticket with no discount; store this as type char] "price [012479900 has an implied decimal point; the double value should be 124799.00] Whitespace (e.g., spaces or tabs) before or after the coded information should be disregarded. Hint: After the ticket code has been read in as a String, it should be trimmed using the trimO method.] Your program will need to print the date and time, seat, the itinerary (i.e, ticket description), the ticket price, the ticket category, the actual cost, and a random prize number in the range to 9999. If the user enters a code that does not have at least 26 characters, then an error message should be printed and the program should end. [The 26 character of the code is part of the ticket description.] Design: Several examples of input/output for the program are shown below Line # Enter ticket code: 123456789 Invalid ticket code Ticket code must have at least 26 characters Note that the ticket code 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., time, date, and seat on line 3), there are three spaces between them (do not use the tab escape sequence lt) Line # 1 Pro Enter ticket code: 153012152090s02498990018BTime Machine 7 to NYC 12/31/1880 Time: 15:30 Date: 12/15/2090 Seat: 18B Itinerary: Time Machine 7 to NYC 12/31/1880 Price: $249,899.00 Cost: $124,949.50 Category: s Prize Number: 9019

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Neo4j Data Modeling

Authors: Steve Hoberman ,David Fauth

1st Edition

1634621913, 978-1634621915

More Books

Students also viewed these Databases questions