Answered step by step
Verified Expert Solution
Link Copied!

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.io.FileReader;import java.util.Scanner; private static final int MAX_ITEMS =15; // Maximum number of items private Item[] cart; // Array to hold items in the current sale public OnlineSale(){ cart = new Item[MAX_ITEMS]; readItemData(); // Read item data from CSV file // Method to read item data from CSV file String csvFile = "Items"; String cVsSplitBy =","; int index =0; String[] data = line.split(cvsSplitBy); String itemCode = data[0].trim(); String itemDescription = data[2].trim(); items[index]= new Item(itemCode, itemName, itemDescription, unitPrice); }} catch (IOException e){} private void displayItems(){ for (Item item : items){}}// Method to handle a sale cart = new Item[MAX_ITEMS]; // Reset cart for new sale System.out.println("Beginning a new sale (Y/N)"); //.. public static void main(String[] args){ onlineSale.handleSale();//Method to find an item by its code
private Item findItemByCode(String code){ if (item != null && item.getItemCode().equalsIgnoreCase(code)){}return null;
}
// Method to start and manage the sale process
private void handlesales(){cartIndex =0;Scanner scanner = new Scanner(System.in); System.out.println("----------------------------------String productCode = scanner.nextLine().trim();if (productCode.equals("-1")){}if (item == null){ continue;System.out.println("Item name: "+ item.getItemName());int quantity =0; quantity = Integer.parseInt(scanner.nextLine().trim()); throw new NumberFormatException();} catch (NumberFormatException e){ continue;double itemTotal = item.getUnitPrice()* quantity;cart[cartIndex++]= item; // Add item to cartSystem.out.println();choice = scanner.nextLine().trim();
}
// Print items in cart
System.out.println("Items list:");
for (int i =0; i cartIndex; i++){System.out.printf("%d %s $%.2f
", i+1, item.getItemName(), item.getUnitPrice());
}
// Calculate and display totals
double taxRate =0.06; //6% tax rate
double totalTax = subtotal * taxRate;
double totalWithTax = subtotal + totalTax;
System.out.printf("Subtotal: $%.2f
", subtotal);
image text in transcribed

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

DB2 Universal Database V7.1 Application Development Certification Guide

Authors: Steve Sanyal, David Martineau, Kevin Gashyna, Michael Kyprianou

1st Edition

0130913677, 978-0130913678

More Books

Students also viewed these Databases questions