Help

Reply

Join Date: Aug 2008
Posts: 1
Reputation: warlock300300 is an unknown quantity at this point 
Solved Threads: 0
warlock300300 warlock300300 is offline Offline
Newbie Poster

Help

 
0
  #1
Aug 30th, 2008
I need helping writing the following code that does the following pls
Implement the following String List ADT:

A String List is a list (sequence) of strings with the following methods:
1. A constructor that initializes the list to be empty.
2. A boolean isEmpty() method that returns true if the list is empty. Otherwise it returns false.
3. A boolean isFull() method that returns true if the list is full. Otherwise it returns false.
4. An int size() method that returns the number of elements (strings) in the list.
5. A void clear() method that sets the list to be empty.
6. A void insert(String newStr, int position) method that throws a RuntimeException, if the position value is not valid in the list (i.e., beyond the current size of the list or being negative). It also throws a RuntimeException, if the list is full. Otherwise, it inserts newStr at position in the list. If position equals the current number of strings in the list, then newStr is simply appended to the list. Otherwise, newStr is inserted at position in the list, and the original string at position and the following strings in the list are moved to the next position in the list.
Note that position starts from 0. So if, say, the current number of strings in the list is 3, then a valid position value should be between 0 and 3. If the position value is 3, then newStr is appended to the end of the list. If, say, the position value is 0, then newStr is inserted at the beginning of the list, while the original strings at positions 0, 1 and 2 are moved to positions 1, 2 and 3, respectively. In either case, the number of strings in the list becomes 4 after the insertion.
7. A void remove(int position) method that throws a RuntimeException, if the position value is not valid in the list (i.e., beyond the current size of the list or being negative). It also throws a RuntimeException, if the list is empty. Otherwise, it removes the string at position in the list. After the removal, strings that follow the original string at position in the list, if any, are moved ahead by one position.
Note that position starts from 0. So if, say, the current number of strings in the list is 3, then a valid position value should be between 0 and 2. If the position value is 2, then the last string in the list is simply removed. If, say, the position value is 0, then the string at position 0 is removed and the original strings at positions 1 and 2 are moved to positions 0 and 1 respectively. In either case, the number of strings in the list becomes 2 after the removal.
8. A String retrieve(int position) method that throws a RuntimeException, if the position value is not valid in the list (i.e., beyond the current size of the list or being negative). Otherwise, it returns the string at position in the list.
9. A void replace(String newStr, int position) method that throws a RuntimeException, if the position value is not valid in the list (i.e., beyond the current size of the list or being negative). Otherwise, it replaces the string at position with newStr.

Note that certain methods (e.g., insert) in the ADT throw RuntimeException directly. This should NOT happen in a real implementation. You almost always need to implement your own exception type, which can be a subclass of Exception or RuntimeException depending on the situation. Since we have not covered how to define a new Exception type, we use RuntimeException here. In this programming assignment, you are allowed to use RuntimeException. Once we have learned how to defined user exception types, you should not use RuntimeException directly in your solution anymore.

You are required to implement TWO classes based on the String List ADT. The first class, named ContiguousStringList, should utilize a contiguous implementation, that is, the internal representation of the sequence of strings should be an array of strings. The second class, named LinkedStringList, should use a linked data structure to present the sequence of strings.

A separate class called StringListTester is provided to test the two classes that you create. The main method in StringListTester first prompts the user to choose between the two implementations of the string list. Then it lets the user enter strings into the list and then indicate the position at which the string should be inserted. The program will report an error message when the user specifies an invalid position for insertion and let the user to enter another position. Once the user finishes entering the strings, all strings in the list will be printed on the screen in order.

Sample programs in Java are provided as a reference. They are integer queues using contiguous and linked implementations, respectively. List implementations in C++ are also provided as a reference.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 790
Reputation: darkagn has a spectacular aura about darkagn has a spectacular aura about darkagn has a spectacular aura about 
Solved Threads: 109
darkagn's Avatar
darkagn darkagn is offline Offline
Master Poster

Re: Help

 
0
  #2
Aug 30th, 2008
What have you done so far? We are not allowed to just give you the answer, we need to see some effort. Sorry!
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 706
Reputation: stultuske is a jewel in the rough stultuske is a jewel in the rough stultuske is a jewel in the rough 
Solved Threads: 84
stultuske's Avatar
stultuske stultuske is offline Offline
Master Poster

Re: Help

 
0
  #3
Sep 1st, 2008
we're more than willing to help, but as both the rules of this forum and your question state, we are here to HELP, not create it for you.
the look of your question suggests that it is an assignment of a Java-course of some sort: you 'll not help yourself understanding it by asking other people to do it for you.

try for yourself, failing is allowed, then ask us for explanations
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,429
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 507
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is online now Online
Industrious Poster

Re: Help

 
0
  #4
Sep 2nd, 2008
And the assignment even says sample implementations are available - talk about lazy...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC