Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need help on whay my code is not working, I tried to fix the issues but more pop up . Any corrections would be
I need help on whay my code is not working, I tried to fix the issues but more pop up Any corrections would be great.
import java.ioFileReader;import java.util.Scanner; private static final int MAXITEMS ; Maximum number of items private Item cart; Array to hold items in the current sale public OnlineSale cart new ItemMAXITEMS; readItemData; Read item data from CSV file Method to read item data from CSV file String csvFile "Items"; String cVsSplitBy ; int index ; String data line.splitcvsSplitBy; String itemCode datatrim; String itemDescription datatrim; itemsindex new ItemitemCode itemName, itemDescription, unitPrice; catch IOException e private void displayItems for Item item : items Method to handle a sale cart new ItemMAXITEMS; Reset cart for new sale System.out.printlnBeginning a new sale YN; public static void mainString args onlineSale.handleSale;Method to find an item by its code
private Item findItemByCodeString code if item null && item.getItemCodeequalsIgnoreCasecodereturn null;
Method to start and manage the sale process
private void handlesalescartIndex ;Scanner scanner new ScannerSystemin; System.out.printlnString productCode scanner.nextLinetrim;if productCodeequalsif item null continue;System.out.printlnItem name: item.getItemName;int quantity ; quantity Integer.parseIntscannernextLinetrim; throw new NumberFormatException; catch NumberFormatException e continue;double itemTotal item.getUnitPrice quantity;cartcartIndex item; Add item to cartSystem.out.println;choice scanner.nextLinetrim;
Print items in cart
System.out.printlnItems list:";
for int i ; i cartIndex; iSystemout.printfd s $f
i item.getItemName item.getUnitPrice;
Calculate and display totals
double taxRate ; tax rate
double totalTax subtotal taxRate;
double totalWithTax subtotal totalTax;
System.out.printfSubtotal: $f
subtotal;
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