Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I got the message when I submitted my code: Your code failed to compile correctly against the reference tests. This is most likely because you

I got the message when I submitted my code:

Your code failed to compile correctly against the reference tests.

This is most likely because you have not named your class(es) as required in the assignment, have failed to provide one or more required methods, or have failed to use the required signature for a method.

Failure to follow these constraints will prevent the proper assessment of your solution and your tests.

My code is below:

import java.util.*;

import java.text.DecimalFormat;

/** * Event program. * Version: 02/05/2023 * Author: Ronald Funes */

class Event {

/** * Determine value for code, event, date, time. * Determine value for section, row, seat, price. * Determine value for discount, cost and prize number. * @param args is not used. */ public static void main(String[] args) { // declaring all the variables String code, event, date, time, section, row, seat; double pricedouble, discountdouble, cost; int prizenumber; // using scanner class to take use input Scanner sc = new Scanner(System.in); // declaring decimalformatter to format numbers DecimalFormat df = new DecimalFormat("$#,##0.00"); // taking userinput using nextLine() System.out.println("Enter your event code:"); // trimming extra spaces code = sc.nextLine().trim(); // if lenth is less than 26 given error if (code.length() < 26) { System.out.println("Invalid Event Code." + " Event code musthave at least 26 Characters."); System.exit(0); } event = code.substring(25, code.length()); date = code.substring(0, 8); time = code.substring(8, 12); price_double = Double.parseDouble(code.substring(12, 15) + "." + code.substring(15, 17)); discount_double = Double.parseDouble(code.substring(17, 19)); section = code.substring(19, 21); row = code.substring(21, 23); seat = code.substring(23, 25); // calcuating cost after dicount cost = price_double - (price_double * (discount_double / 100)); // calculating random number between 1 to 9999 prize_number = (int) (Math.random() * 10000 + 1); // printing data as per the question System.out.print("Event: " + event); System.out.print("\tDate: " + date.substring(0, 2) + "/" + date.substring(2, 4) + "/" + date.substring(4, 8)); // printing time with : System.out.print("\tTime: " + time.substring(0, 2) + ":" + time.substring(2, 4)); System.out.print(" Section: " + section); System.out.print(" \tRow: " + row); System.out.print("\tSeat: " + seat); // using df to format the price System.out.print(" Price: " + df.format(price_double)); // applying new pattern to df df.applyPattern("#.#'%'"); // using df to format the discount System.out.print(" \tDiscount: " + df.format(discount_double)); df.applyPattern("$#,##0.00"); System.out.print("\tCost: " + df.format(cost)); df.applyPattern("0000"); System.out.println(" Price Number: " + prize_number); }

}

Expected output:

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 four digits (e.g., 1 should be printed as 0001). The coded input is formatted as follows: 0614202119301250015011012The Lion King

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.]

Enter your event code: 0614202119301250015011012The Lion King Event: The Lion King Date: 06/14/2021 Time: 19:30 Section: 01 Row: 10 Seat: 12 Price: $125.00 Discount: 15% Cost: $106.25 Prize Number: 3629

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

More Books

Students also viewed these Databases questions