Answered step by step
Verified Expert Solution
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
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.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started