Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Microsoft Visual Basic 2005 For Windows Mobile Web Office And Database Applications Comprehensive

Authors: Gary B. Shelly, Thomas J. Cashman, Corinne Hoisington

1st Edition

0619254823, 978-0619254827

More Books

Students also viewed these Databases questions

Question

2. Describe why we form relationships

Answered: 1 week ago

Question

5. Outline the predictable stages of most relationships

Answered: 1 week ago