Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: ArrayLinearList and its's sub class help

  1. #1
    Member
    Join Date
    Oct 2012
    Posts
    68
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Red face ArrayLinearList and its's sub class help

    I have a class called ArrayLinearList

    public class ArrayLinearList implements LinearList
    {
       protected Object [] element; 
       protected int size;

    I have made a subclass of ArrayLinearList

    public class ArrayEventsList extends ArrayLinearList
    {
    }

    A screen will come up asking the user what option they want.
    For example:

    Press 'A' to add an item to the list
    Press 'b' to remove item from the list

    When the user presses 'A' it calls my method addItem()

       public void addItem()
       {
         ArrayLinearList.add(item); //item is whatever string the user just entered from the scanner for example "mobile"
                                            //addItem is then supposed to add mobile to the list
       }

    How would I go about adding an item the user enters on screen and add it to the ArrayLinkedList?

    Thank you


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

    Default Re: ArrayLinearList and its's sub class help

    How would I go about adding an item the user enters on screen and add it to the ArrayLinkedList?
    How would you? Think about what steps are necessary and organize them into a plan. From there you can work on the code to make it happen. If you have trouble along the way ask more questions.

  3. #3
    Member
    Join Date
    Oct 2012
    Posts
    68
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: ArrayLinearList and its's sub class help

    I'm still really confused I have been going over it for a while now.

    Scanner scanner = Scanner(system.in)
    System.out.println("Choose option!") //User presses option 1
    option = scanner.next // option = 1

    My system now knows that option 1 was was selected and option 1 is addItem() so that method is called.

    Scanner scanner1 = new scanner(System.in)
    System.out.println("what item do you want to store!") //User enters text for example "phone"
    item.scanner.next // item = phone

    //Now I want to add this to the array.

    ArrayLinearList list = new ArrayLinearList();
    ArrayShoppingList.add(list); //This doesn't work as itsays string entered and it wants and object!

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

    Default Re: ArrayLinearList and its's sub class help

    Error messages are very specific in the wording and the information they contain. To get the best help with an error, post the message exactly as it is.

    Also post the relevant code (inside code tags) along with your question and error message. Showing a couple lines here and there is not always enough code to find the problem.

  5. #5
    Member
    Join Date
    Oct 2012
    Posts
    68
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: ArrayLinearList and its's sub class help

    Hi thanks for replying,

    I managed to get it working using the code:

    public void addItem()
        {
          Scanner scanner = new Scanner(System.in);
          System.out.println("What item would you like to add: ");
          item = scanner.next();
          super.add(0, item);
        }

    This adds the item to Array, but my problem now is when I call a method to get the position of it, it is always 0 because that's what I stated at super.add(0, item);

    If i remove the 0, the following error:

    method add in class ArrayLinearList cannot be applied to given types:
    required int,java.lang.String; found: java.lang.String

    Do you know how to add the object into the available slot without specifying the int '0' ?

    Thanks

    //Got it working now
    Last edited by sim18; October 11th, 2012 at 02:39 PM. Reason: Worknig now

Similar Threads

  1. Replies: 5
    Last Post: October 18th, 2012, 01:43 PM
  2. need to make basic class and implementation class (base class without void main)
    By javanewbie101 in forum Object Oriented Programming
    Replies: 1
    Last Post: September 19th, 2012, 08:03 PM
  3. create a test class (main method) to start(run) the class in Java
    By curious725 in forum Java Theory & Questions
    Replies: 5
    Last Post: August 1st, 2012, 03:21 AM
  4. Replies: 3
    Last Post: June 17th, 2012, 06:22 PM
  5. Replies: 3
    Last Post: April 13th, 2011, 03:30 PM