Question
Module 08: Final - Debugging Assignment In this assignment you will demonstrate your knowledge of debugging by fixing the errors you find in the program
Module 08: Final - Debugging Assignment
In this assignment you will demonstrate your knowledge of debugging by fixing the errors you find in the program below. Fix the code, and paste it in this document, along with a list of the problems you fixed.
This example allows the user to create an ArrayList that contains a list of states. There should be only one entry per state in the list. There is another method to verify the uniqueness of the list.
import java.util.ArrayList;
import stringCollections.StoreStrings;
public class TestStoreStrings {
public static void main(String[] args) {
ArrayList<> states = new ArrayList
states.add("Virginia");
states.add("New York")
states.add("Michigan");
states.add("Indiana");
states.add("Missouri");
states.add("Indiana");
states.sort(null);
for(String state:states) {
System.out.println(state)
}
if (StoreStrings.duplicateString(states)) {
System.out.println("Error! Contains more than one entry of the same state in the list. Must have only one entry for the state in the list");
} else {
System.out.println(StoreStrings.count(states));
}
}
}
package stringCollections;
import java.util.ArrayList;
public class StoreStrings {
public static int count(ArrayList
{
int lSize = 0;
for(String i : words)
{
lSize++;
}
return lSize;
}
public static boolean duplicateString(ArrayList
boolean isDuplicateString = False;
ArrayList<> items = new ArrayList
for(String word : words)
{
if (items.contains(word)) {
isDuplicateString = True;
}else {
items.add(word);
}
}
return isDuplicateString;
}
}
CORRECTED CODE:
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