Question
The attached class and its tester abort. You should analyze the situation and provide the following information: provide a screenshot using the debugger of Eclipse
The attached class and its tester abort. You should analyze the situation and provide the following information:
provide a screenshot using the debugger of Eclipse showing all appropriate local and instance variables JUST BEFORE THE EXCEPTION.
identify the error, and how to fix it.
This assignment requires no programming on your part, and you are not expected to submit any code. Just prove that you know exactly when the problem occurs, and how you would fix it.
import java.util.ArrayList;
public class Kaboom {
public static void main(String[] args) { String[] strs = { "aardvark", "show", "flower", "mantle", "table", "clock", "red", "show", "water" }; StrCharCounter k = new StrCharCounter(); for (String s: strs) { k.add(s); } System.out.println("length of all strings " + k.calcTotalLength()); }
}
...........................................................................................................
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. * * @author parks * */ public class StrCharCounter {
private ArrayList
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; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started