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

Data Structures using java Your code must be well formatted and commented. While

ID: 671963 • Letter: D

Question

Data Structures using java

Your code must be well formatted and commented. While marks will not be assigned for properly formatting and commenting your code, All programs must include the “Essential Features of Program Documentation” (page 122). Details are included throughout Chapter 2 on best practices for documentation.

3. Chapter 4 describes the ADT Sorted List using an array implementation with a maximum of 20 items. The pseudocode for the ADT Sorted List Operations are provided on page 210. Use this information to create an ADT for handling a collection of license plate numbers, provided as a single String in the form “XXX 9999” where X is any capital letter A-Z and 9 is any digit 0-9. This implementation should allow for duplicate names. Make a test driver program to demonstrate this ADT by:

a) Adding 20 license plates containing at least one duplicate

b) Print the list of the plate numbers (the display method must be in the test driver class and use the sortedGet() method.)

c) Adding a 21st item results in a custom unchecked exception called ADTSortedListException (i.e. list is full).

d) Print the size of the SortedList, remove an item, show the size has changed and print the list again showing the item has been removed.

e) Demonstrate the locate method works by locating the duplicate item.

f) add another copy of the duplicate value (so there are now three) and print the list again.

Explanation / Answer

import java.util.Scanner; class stack { private final int size; private int top; private E[] elements; public stack() { this(10); } public stack(int s) { size=s>0?s:10; top=-1; elements=(E[])new Object[size]; } public void push(E x) { if(top==size-1) System.out.println("Overflow"); elements[++top]=x; } public E pop() { if(top==-1) System.out.println("Underflow"); return elements[top--]; } public void display() { if(top==-1) System.out.println("Stack is empty"); else { for(int i=0;i