Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help me with a simple error in my code dealing with ArrayLists: Here's my code: import java.util.ArrayList; public class Checkout { private int size; private

Help me with a simple error in my code dealing with ArrayLists:

Here's my code:

import java.util.ArrayList;

public class Checkout { private int size; private int amount; private int sum; private double taxRate; private ArrayList dessertItems; public Checkout() { size = 100; amount = 0; sum = 0; dessertItems = new ArrayList (); taxRate = DessertShoppe.TAX_RATE; } public void enterItem(DessertItem item) { dessertItems.add (item); amount++; } public int numberOfItems() { return amount; } public int totalCost() { sum = 0; for (int i = 0 ; i < amount ; i++) { sum += dessertItems[i].getCost (); } return sum; } public int totalTax() { return (int) (Math.round(this.totalCost() * taxRate / 100)); } public void clear() { for (DessertItem item : dessertItems) { item = null; } amount = 0; sum = 0; } public String toString() { String receipt = "Thank You!"; receipt += DessertShoppe.STORE_NAME + " "; receipt += "Purchased: "; String totalPay = DessertShoppe.cents2dollarsAndCents(totalCost() + totalTax()); if (totalPay.length() > DessertShoppe.COST_WIDTH) { totalPay = totalPay.substring(0, DessertShoppe.COST_WIDTH); } receipt += "$" + totalPay; return receipt; } }

This is the error code I get for the bolded line of code:

The type of the expression must be an array type but it resolved to ArrayList

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

101 Database Exercises Text Workbook

Authors: McGraw-Hill

2nd Edition

0028007484, 978-0028007489

More Books

Students also viewed these Databases questions

Question

Find the length of the curve y = x t3 1 dt, 1 Answered: 1 week ago

Answered: 1 week ago