Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.ArrayList; /** * This class keeps a set of unique strings, and lets the user * ask the total length of all Strings in

import java.util.ArrayList;

/**

* This class keeps a set of unique strings, and lets the user

* ask the total length of all Strings in the store.

*

*

*

*/

public class StrCharCounter {

private ArrayList store = new ArrayList<>();

private int size = 0;

public boolean add(String sToAdd) {

size++;

if (!store.contains(sToAdd))

return store.add(sToAdd);

else

return false;

}

public int calcTotalLength() {

int cnt = 0;

for (int i = 0; i < size; i++) {

cnt += store.get(i).length();

}

return cnt;

}

}

provide a screenshot using the debugger of the IDE of your choice showing all appropriate local and instance variables JUST BEFORE THE EXCEPTION.

identify the error, and how to fix it.

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