Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Chapter 4 describes the ADT Sorted List using an array implementation with a maximum of 25 items. The pseudocode for the ADT Sorted List Operations

Chapter 4 describes the ADT Sorted List using an array implementation with a maximum of 25 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 Person objects, where each object will contain a Social Insurance Number (validate this), a first name, a last name, a gender and a data of birth. This implementation should prevent duplicate entries that is, the Social Insurance numbers must be unique. Write a test program (separate class) that will demonstrate the following: a) Read from a binary file: SIN (an integer), first name (a UTF string), last name (a UTF string), gender (a character), and date of birth (a java.util.Date object). You will need to create your own test data for this part and there should be at least 25 different people of which two must have the same SIN and one must be an invalid SIN. b) If the form of the SIN is not valid, an exception should be thrown with an appropriate message. Demonstrate this requirement. c) Print the list of the people (the display method must be in the test driver class and use the getSortedList() method.) [Remember that an ADT cannot return its data structure.] d) Add a 3 more unique people using user supplied input whereby the 26th item results in an PeopleException with a message like The list is full. Print the list again. e) Print the size of the SortedList, remove an item (any one), show the size has changed by printing the size again. Print the list again showing the item has been removed. f) Demonstrate the locate method works by locating an item in the list and then attempting to locate one that is not in the list.

3) Modified ADT Sorted List Application [15 marks] Modify a copy of Question #3 to make the ADT resizable when it is full, the ADT will increase its physical capacity rather than throw an exception. For this ADT, the MAX_SIZE will not be final, but rather will be increased whenever a new item needs to be added and the array is full (ie. size==MAX_SIZE). Whenever the array needs to grow, add the greater of: a. 25% of the current size, or; b. 20 additional spaces. Have your ADT report its old and new maximum size whenever the resize operation is called by printing ADT resized from xxx to yyy where xxx is the old size and yyy is the new size. Modify the test driver from Question 2 to randomly generate SIN numbers, validate each, and add 300 people (any names, gender and dates of birth will do). Use the size() method to determine once the limited has been reached. If duplicates are generated, add another element so that the total will be 326.

The answer is supposed to be in JAVA using the following interface: public interface ADTSortedList> {

boolean isEmpty(); int size(); void add(T item) throws SortedListException; void remove(T item) throws SortedListException;

void remove(int pos) throws SortedListException; T get(int pos) throws SortedListException; int locate(T item); void removeAll(); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions