Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help with this code!! Event.java Requirements: The purpose of this program is to accept coded event information as input that includes the date, time,

Please help with this code!!

Event.java

Requirements: The purpose of this program is to accept coded event information as input that includes the date, time, price, discount, section, row, seat, followed by the description of the event. Note that the five digits for price and two digits for discount have an implied decimal point. The program should then print the event information including the actual cost, which is the price with discount applied. The last line of the event information should contain a random "prize number" between 1 and 9999 inclusive that should always be printed as seven digits (e.g., 1 should be printed as 0001). The coded input is formatted as follows:

 0214202019301250015011012The Lion King 

date

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 event description, date, time, section, row, seat number, price, discount, and cost, and a random prize number in the range 1 to 9999 as shown in the examples below. If the user enters a code that does not have at least 26 characters, then an error message should be printed. [The 26th character of the code is part of the event description.]

Design: Several examples of input/output for the program are shown below.

Note that the event 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., event, date, and time on line 3), there are three spaces between them (do not use the tab escape sequence \t).

seat description row (goes through last character on line)

section

time price [12500 has an implied decimal point before the last two digits

discount [15 has an implied decimal point for 0.15 (or 15%)] for 125.00]

Line #

Program output

1 2 3 4

Enter your event code: War Eagle

Invalid Event Code. Event code must have at least 26 characters.

Line #

Program output

1 2 3 4 5 6

Enter your event code: 0214202019301250015011012The Lion King

Event: The Lion King Date: 02/14/2020 Time: 19:30 Section: 01 Row: 10 Seat: 12 Price: $125.00 Discount: 15% Cost: $106.25 Prize Number: 3629

Page 3 of 5

Project: Using Java API Classes Page 4 of 5

Note that the event code entered below includes a 50% discount.

Note that the event code below has 10 leading spaces (be sure you are trimming the input code). It also includes a 75% discount.

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 I/O 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 event code each time you run your program.

Grading Web-CAT Submission: You must submit both completed programs to Web-CAT at the same time.

Prior to submitting, be sure that your programs are working correctly and that they have passed Checkstyle. If you do not submit both programs at once, Web-CAT will not be able to compile and run its test files with your programs which means the submission will receive zero points for correctness. I recommend that you create a jGRASP project and add the two files. Then you will be able to submit the project to Web-CAT from jGRASP. Activity 1 (pages 5 and 6) describes how to create a jGRASP project containing both of your files.

Line #

Program output

1 2 3 4 5 6

Enter your event code: 0214202019301250050011012The Lion King

Event: The Lion King Date: 02/14/2020 Time: 19:30 Section: 01 Row: 10 Seat: 12 Price: $125.00 Discount: 50% Cost: $62.50 Prize Number: 2534

Line #

Program output

1 2 3 4 5 6

Enter your event code:

0214202019301250075011012The Lion King

Event: The Lion King Section: 01 Row: 10 Price: $125.00 Discount: 75% Cost: $31.25 Prize Number: 8494

Date: 02/14/2020 Time: 19:30 Seat: 12

Page 4 of 5

Project: Using Java API Classes Page 5 of 5

Hints Event.java

  1. The event code should be read in all at once using the Scanners 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 "$#,##0.00" when you create your DecimalFormat object.

    To format discount, use the pattern "0%" when you create your DecimalFormat object.

    For prize number, use the pattern "0000" when you create your DecimalFormat object.

  2. Since all items in the event 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 ":" and "/" as needed.

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

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 19 21 2012 Proceedings Part 3 Lnai 7198

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284922, 978-3642284922

More Books

Students also viewed these Databases questions