Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2012
    Posts
    2
    Rep Power
    0

    Default Using ArrayLists. Very Very new to Java.

    I'm very very new Java, I have no idea how to do anything but I have a project due so I really need some help!
    my project is to create an arraylist of favourite items(class) named favouriteshows(I'm doing my favourite shows).
    private ArrayList<FavouriteItems> myfavouriteshows;
    I need to be able to find items of rating and string description but so far this is what I have, if anyone could give me some help, that would be great. This is my code so far for finding an item with searched rating;
    /**
    * Count the number of Items with a given rating
    * @return The number of Items (Item objects)
    * whose rating is rating (could be 0).
    * If the rating parameter is outside the valid
    * range 1..5 then print an error message and return 0.
    */public int numberOfItemsOfRating(int rating)
    {
    if(rating <= 5 || rating >= 1 ){
    int index = 0;
    boolean searching = true;
    while(searching && index < myfavouriteshows.size()){
    FavouriteItems intrating = myfavouriteshows.get(index);
    if(myfavouriteshows.getRating() == rating){
    searching = false;
    }
    else{
    index++;
    }
    if(searching){
    return null;
    }
    }


    - Again, this may be very primitive code to some people but I'm a slow learning new starter!

  2. #2
    Twixmaster123 is offline Member
    Join Date
    Mar 2012
    Posts
    12
    Rep Power
    0

    Default Re: Using ArrayLists. Very Very new to Java.

    Well before you can do anything you have to set up your "favorite shows" as variables. (I think)

    Oh and you might want to use the /code tags because I can hardly read your code ^_^
    Last edited by Twixmaster123; 04-07-2012 at 08:55 AM.

  3. #3
    Join Date
    Apr 2012
    Posts
    2
    Rep Power
    0

    Default Re: Using ArrayLists. Very Very new to Java.

    Quote Originally Posted by Twixmaster123 View Post
    Well before you can do anything you have to set up your "favorite shows" as variables. (I think)

    Oh and you might want to use the /code tags because I can hardly read your code ^_^
    I think I did set them as variables, I forgot to add this part to the code


    Java Code:
    public FavouriteItems()
        {
            myfavouriteshows = new ArrayList<FavouriteItems>();
        }
    Is that what you were talking about?
    Thank you so much for your help, I'm so stuck!

  4. #4
    Twixmaster123 is offline Member
    Join Date
    Mar 2012
    Posts
    12
    Rep Power
    0

    Default Re: Using ArrayLists. Very Very new to Java.

    Yeah but now you have to SET your favorite items for the array list. 0, 1, 2, 3, 4, 5 is how an array list starts, so you would need to assign a favorite item to 0, 1, 2, 3, 4, and 5. I am unclear as to what you are actually trying to accomplish, or if I am telling you the correct way, I would wait for a more experienced user to help.

    Regards,

    Joe

Similar Threads

  1. Arraylists
    By talia in forum New To Java
    Replies: 5
    Last Post: 01-30-2012, 07:44 PM
  2. help with ArrayLists !
    By bigbreez21 in forum New To Java
    Replies: 3
    Last Post: 11-20-2011, 09:23 PM
  3. ArrayLists
    By Freakzoyd in forum New To Java
    Replies: 4
    Last Post: 11-12-2010, 05:27 AM
  4. Java - Comparator, sorting arrayLists
    By Kerrai in forum New To Java
    Replies: 15
    Last Post: 10-24-2010, 10:41 PM

Tags for this Thread

Posting Permissions

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