Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How do I change this line of code to make it fit with an ArrayList instead of a regular array? Here's my code: import java.util.ArrayList;

How do I change this line of code to make it fit with an ArrayList instead of a regular array?

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 with AI-Powered 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

Students also viewed these Databases questions

Question

1. Let a, b R, a Answered: 1 week ago

Answered: 1 week ago