Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Project # 1 Implementation of DoubleArraySeq class Your task is to create the class that is discussed in chapter 3, section 3.3 of your textbook.

Project # 1Implementation of DoubleArraySeq class

Your task is to create the class that is discussed in chapter 3, section 3.3 of your textbook. The assigned project in the back of the chapter is #4 on page 169 in addition to these instructions. (READ THIS DOCUMENT BEFORE STARTING WORK!) The problem suggests the adding of additional methods. I would like you to add the six of them shown and described below, NOT the ones listed in book. Remember to add in the Javadoc comments for these new methods. Lastly you must create a Test class that allow the user to create sequences and manipulate them using your class. This is also described below.

Along with this document in the assignments folder should be a file called DoubleArraySeq.java which contains the template of the class along with all written specifications for the methods (except for these additional six). You should grab a copy of this file to begin work with.

The six additional methods that you need to add should be named the following:

void addFront( double )

A method to add a new element at the front of the sequence and make it the current element.

void removeFront( )

A method to remove the element at the front of the sequence.
If there is only one element, remove it and make the current index zero (equal to manyItems, which means no current element), otherwise make the current element the new front element.
Throw an IllegalStateException if the sequence is empty when the method is called.

void setCurrent ( int n )

A method that makes the nth element become the current element.
Note: This n value is not an index value. If n equals one, then the current element is at location zero.
Throw an IllegalStateException if the sequence is empty.
Throw an IllegalArgumentException if n does not represent a valid location in the array.

double getElement ( int n )

A method that returns the nth element of the sequence.
Make current element this nth element.
NOTE: n is not the index value. (if the value of n that is passed in is 4, that means index 3 in the array)
Throw an IllegalStateException if the sequence is empty.
Throw an IllegalArgumentException if n is greater than the sequence size, or if n is zero or negative.

boolean equals ( Object )

Method that returns true if sequence is the same length and order and data. (The current element could be different)
Use the proper format for the equals method shown in the book, we are overriding the equals method from the Object class.

String toString ( )

creates a string of all elements in order separated by a space.
Use start( ), advance( ) and getCurrent( ) to progress through data
Throw an IllegalStateException if the sequence is empty.
IMPORTANT: The methods above will change the value of the current element, but the current element should be changed by this method. Make sure to reset to its original value by the end of this method.
Remember : toString does not output to screen, it returns a string

As you add each of these methods you need to also add the specifications in the Javadoc comments for each new method.

SequenceTest program:

In order to test your class methods you are going to want a program that creates a sequence object with the ability to call any of the abstract data types (ADT) methods. The Test program that you will create will declare one emptysequence object. Use either of the constructors, setting capacity to 10. Then the program will have a menu output to the screen with the following choices:

1. Print out to screen the sequence (uses toString( ) )
2. Report the capacity of sequence (uses getCapacity( ) )
3. Set the current element location (uses setCurrent(int))
4. Add a number to the front of the sequence ( uses addFront(double) )
5. Add a number to the end of the sequence (uses size( ),setCurrent (int) and addAfter(double) )

Note: for choices 6 and 7 the location to add the new value is referenced to where the current element is. And you will need to ask the user for the number to add.

6. Add a number before the current element (uses addBefore(double) )
7. Add a number after the current element (uses addAfter(double) )
8. Delete the first number from the sequence (uses removeFront( ) )

Note: for choices 9 and 10 the location to display or delete is asked for. This is not an index value, the user will give you a location (the first location is index zero)

9. Delete a number at a location (uses setCurrent(int)and removeCurrent( ) )
10. Display the value at a certain location (uses getElement(int) )
11. Display the last element in the sequence(uses size( ),setCurrent(int) and getCurrent( ) )
12. Quit

NOTE: This test program should never crash due to an exception being thrown from the methods. If the method called from the SequenceTest program might throw an exception, it is your job to catch it in SequenceTest and output an appropriate message. The program should then continue by asking the user pick their next choice.

Exceptions summary: Using exceptions properly is often a point of confusion in this class. The general use of exceptions in this project is to throw them from within the methods of the DoubleArraySeq class, but you do not catch them there. (You catch them in the SequenceTestfile) The designer(you) is attempting to make the DoubleArraySeq class useful for many different projects, and since the many methods could be receiving poor inputs,we want to be able to warn future users of this class with an exception. But we also do not want to assume that we know what should be done in each case of an exception. The Driver class (SequenceTest) is using our class to make a project, this is where we catch and handle any exceptions that are thrown (We can make the assumptions here). There are many ways to program, but we want to make our classes as useful as we can so that there is a greater chance of reusing the ADT later. If you are unsure about this relationship of when to throw and catch exceptions, please ask. Final note: It almost never makes sense to throw and catch an exception in the same method (If that is really what we wish, a simple if statement does the same thing).

These choices will allow the user(me) and you to test your class well. After each choice is finished the menu should pop up again to reshow the choices. PLEASE NOTE: This test program does not check your equals, addAll, or clonemethods, so you will need to test these on your own. Please do not add these extra tests into your submittedversion as I would like to have all submissions working similar.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Filing And Computer Database Projects

Authors: Jeffrey Stewart

2nd Edition

007822781X, 9780078227813

More Books

Students also viewed these Databases questions

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago