Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Modify the ListTest class so that we can insert integer data values representing

ID: 3657083 • Letter: M

Question

Modify the ListTest class so that we can insert integer data values representing identification numbers (Ids). The link list should not store duplicate Ids. Stop inserting Ids when a value of 0 (zero) is input. import java.util.LinkedList; import java.util.Scanner; public class ListTest { private LinkedList< String > nameList; private Scanner scanner; public ListTest() { nameList = new LinkedList< String >(); scanner = new Scanner( System.in ); getNames(); searchNames(); } public void getNames() { System.out.println("Add a name to list, use end to terminate input:" ); String inputName = scanner.next(); while ( !inputName.equals( "end" ) ) { // insert name if ( foundName( inputName ) == false ) { insertName( inputName ); System.out.println( inputName + " inserted" ); } // end if else // name already exists in list System.out.println( inputName + " exists in list" ); System.out.println("Add a name to list, use end to terminate input:" ); inputName = scanner.next(); } // end while } // end method getNames public void searchNames() { System.out.println("Search a name, use end to terminate searching:" ); String inputName = scanner.next(); while ( !inputName.equals( "end" ) ) { if ( foundName( inputName ) ) System.out.println( inputName + " found in list" ); else // name not found System.out.println( inputName + " not found in list" ); System.out.println("Search a name, use end to terminate searching:" ); inputName = scanner.next(); } } public boolean foundName( String searchName ) { for ( String name : nameList ) { if ( searchName.equals( name ) ) return true; } return false; } public void insertName( String name ) { nameList.add( name ); }

Explanation / Answer

/*you may download the code from....http://www.2shared.com/file/yhigl9zs/ListTest.html*/ import java.util.Iterator; import java.util.LinkedList; import java.util.Scanner; public class ListTest { private LinkedList identificationNumList; private Scanner scanner; public ListTest() { identificationNumList = new LinkedList(); scanner = new Scanner(System.in); checkIdentificationNum(scanner.nextInt()); } public void checkIdentificationNum(int value) { int flag = 0; Iterator iIdsNum = identificationNumList.iterator(); while (iIdsNum.hasNext()) { if (value == iIdsNum.next()) { flag = 1; break; } } if (flag == 0 && value != 0) { insertIds(value); } } public void insertIds(int value) { identificationNumList.add(value); } } /*This is another code....use which ever you like....you may download the code from....http://www.2shared.com/file/k4oz3UET/ListTest.html*/ import java.util.Iterator; import java.util.LinkedList; import java.util.Scanner; public class ListTest { private LinkedList identificationNumList; public ListTest() { identificationNumList = new LinkedList(); } public boolean checkIdentificationNum(int value) { int flag = 0; Iterator iIdsNum = identificationNumList.iterator(); while (iIdsNum.hasNext()) { if (value == iIdsNum.next()) { flag = 1; break; } } if (flag == 1 || value == 0) { return true; } else { return false; } } public void insertIds(int value) { identificationNumList.add(value); } public void displayIds() { Iterator iIds = identificationNumList.iterator(); while (iIds.hasNext()) { System.out.println(iIds.next()); } } public static void main(String[] args) { ListTest lt = new ListTest(); boolean status; int intVal; for (int i = 0; i < 10; i++) { Scanner input = new Scanner(System.in); intVal = input.nextInt(); status = lt.checkIdentificationNum(intVal); if (status == false) { lt.insertIds(intVal); } } lt.displayIds(); } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote