Results 1 to 6 of 6

Thread: Help

  1. #1
    wow300300 Guest

    Default Help

    Can someone help with the following needed program
    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.

  2. #2
    pawankumarom is offline Member
    Join Date
    Feb 2008
    Posts
    22
    Rep Power
    0

    Default

    I also want to know what are string and how we can use string in java

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,419
    Rep Power
    25

    Default

    help with the following needed program
    Show what you have so far and ask questions about how to fix the problems.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You've cross-posted the same assignment in many many fora without showing a lick of effort in any of these posts. Let's see a decent try by you towards a solution first. I've found that usually the more thought and effort posters put into creating and solving their questions, the better their chances are of a volunteer here taking the time and effort to consider it and give a helpful answer.

  5. #5
    Join Date
    Aug 2008
    Location
    Saint-Petersburg, Russia
    Posts
    66
    Rep Power
    0

    Default

    Quote Originally Posted by wow300300 View Post
    You are required to implement TWO classes based on the String List ADT.
    Looks like a quote from test job I give to candidates for new positions in my department :D

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Oh dear, asking to do home works again. As Norm says, what you have done up to now? Please be clever to ask questions here, no one here to do home works for you.

    Be specific your question. I think no one wants to read such a long post, I'm not even not look at too. At least try to move step by step.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •