Question: can someone please help me solve this error here is my code import import java.util.Scanner; public class ReceiptMaker { public static final String SENTINEL =

can someone please help me solve this error here is my code import import java.util.Scanner;
public class ReceiptMaker {
public static final String SENTINEL = "checkout";
public final int MAX_NUM_ITEMS;
public final int TAX_RATE;
private String itemNames;
private double [] itemPrices;
private int numItemsPurchased;
public ReceiptMaker(){
MAX_NUM_ITEMS =10;
TAX_RATE =.0875;
itemNames = new String[MAX_NUM_ITEMS];
itemPrices = new double[MIN_NUM_ITEMS];
numItemsPurchased =0;
}
public ReceiptMaker(int maxNumItems, double taxRate){
if(isValid(maxNumItems)){
MAX_NUM_ITEMS = maxNumItems;
}
else{
MAX_NUM_ITEMS=10;
}
if(isValid(taxRate)){
TAX_RATE = taxRate;
}
else{
TAX_RATE =.0875;
}
itemNames = new String[MAX_NUM_ITEMS];
itemPrices = new double[MAX_NUM_ITEMS];
numItemsPurchased =0;
}
public void greetUser(){
System.out.println("Welcome to the "+MAX_NUM_ITEMS+" items or less checkout line");
}
public void promptUserForProductEntry(){
System.out.println("Enter item #"+(numItemsPurchased+1)+"'s name and price separated by a space, or enter ""+SENTINEL+"\" to end transaction early");
}
public void addNextPurchaseItemFromUser(String itemName, double itemPrice){
itemNames[numItemsPurchased]= itemName;
itemPrices[numItemsPurchased]= itemPrice;
numItemsPurchased++;
}
public double getSubtotal(){
double subTotal =0;
for(int i=0; i maxPrice){
maxPrice = itemPrices[i];
}
}
return maxPrice;
}
public int getIndexOfMaxPrice(){
int indexOfMax =0;
for(int i=1; i itemPrices[indexOfMax]){
indexOfMax = numItemsPurchased;
}
}
return indexOfMax;
}
public double getMeanPrice(){
return getSubtotal()/numItemsPurchased;
}
public double getTaxOnSubtotal(){
return getSubtotal()* TAX_RATE;
}
public double getTotal(){
return getSubtotal()+ getTaxOnSubtotal();
}
public void displayReceipt(){
System.out.println("-------------------------------------------------");
System.out.printf("Subtotal: $ %04.2f | # of Items %02d
", getSubtotal(),numItemsPurchased);
System.out.printf(" Tax: $ %05.2f
",getTaxOnSubtotal());
System.out.printf(" Total: $ %04.2f
", getTotal());
System.out.println("--------------------THANK YOU--------------------");
}
public void displayReceiptStats(){
System.out.println("
-----------------RECEIPT STATS-----------------");
System.out.printf("Min Item Name: %12s | Price: $ %04.2f
"+ itemNames[getIndexOfMinPrice()], getMinPrice());
System.out.print("Max Item Name: %12s | Price: $ %04.2f
", itemNames[getIndexOfMaxPrice()], getMaxPrice());
System.out.printf("Mean price of %02d items purchased: $ %04.2f
", numItemsPurchased, getMeanPrice());
}
public void displayAllItemsWithPrices(){
System.out.println("
---------------RECEIPT BREAKDOWN---------------");
for(int i=0; i=0);
}
private boolean isValid(double a){
return (a >=0);
}
public static void main(String [] args){
Scanner scanner = new Scanner(System.in);
ReceiptMaker rm = new ReceiptMaker();
rm.greetUser();
rm.scanCartItems(scanner);
rm.displayReceipt();
rm.displayReceiptStats();
rm.displayAllItemsWithPrices();
scanner.close();
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!