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 words)

{

int lSize = 0;

for(String i : words)

{

lSize++;

}

return lSize;

}

public static boolean duplicateString(ArrayList words) {

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!