Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

There is a file that contains 5148 items, on seperate lines in the file are: des

ID: 3566393 • Letter: T

Question

There is a file that contains 5148 items, on seperate lines in the file are: description, price, quantity in stock and UPC(universal product code) in that order for each item.

Write a JAVA program that reads the content of the file, creates instances of your retail item and stores them in the array. Prompt the user for the items they want to buy by UPC. If an item matching that UPC is found and available, display all data about the item, decrease quantity in stock by one in the list, and add the price to the total cost. If the user enters a UPC that does not exist, display an appropriate message. If the user enters a UPC and the item is out of stock, display an appropriate message. (Do not charge them for items that are not available.)

When the user is finished entering the UPCs for all the items they want to buy, display their total cost for all items selected and available.

Executions should have at least 5 items for each customer.

Explanation / Answer

public class ApacheLogTimestampInterceptor implements Interceptor { @Override public Event intercept(Event event) { Map headers = event.getHeaders(); long ts = extractTimestamp(event); headers.put(TIMESTAMP, ts + ""); return event; } protected long extractTimestamp(Event event) { byte[] body = event.getBody(); if (body != null) { String bodyString = new String(body); int index = bodyString.indexOf(" "); if (index > 0) { String timeToken = bodyString.substring(0, index); try { long ts = Long.parseLong(timeToken); // Check if we need to add milliseconds if (ts < 1300000000000l) { ts *= 1000; } return ts; } catch (NumberFormatException e) { log.warn(e.getMessage(), e); } } } // If we cannot determine the timestamp from the body, return current time return System.currentTimeMillis(); } @Override public List intercept(List events) { for (Event event : events) { intercept(event); } return events; } public static class Builder implements Interceptor.Builder { @Override public Interceptor build() { return new ApacheLogTimestampInterceptor(); } @Override public void configure(Context context) { } } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote