1 2 3 Previous Next 42 Replies Latest reply: Dec 10, 2008 10:13 PM by 843785 Go to original post RSS
      • 15. Re: ArrayList help
        843785
        I still need help without any methods that does it in one line
        • 16. Re: ArrayList help
          843785
          Choose 1
          1. Doesnt output anything
          2. Doesnt reverse the list
          3. Doesn't compile
          • 17. Re: ArrayList help
            843785
            Help with what?

            Try providing details. If you are getting an error then copy and paste it here. If it isn't doing what your expected then give detailed explanation of what it does and what you think it should do. What responses to "i need help" were you expecting?
            • 18. Re: ArrayList help
              843785
              Sinanju180 wrote:
              Choose 1
              1. Doesnt output anything
              2. Doesnt reverse the list
              3. Doesn't compile
              It outputs this error
              --------------------Configuration: <Default>--------------------
              Purse[Nickel,Dime,Penny]
              Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 3, Size: 3
              at java.util.ArrayList.RangeCheck(ArrayList.java:547)
              at java.util.ArrayList.get(ArrayList.java:322)
              at Purse.reverse(Purse.java:44)
              at PurseTest.main(PurseTest.java:13)

              Process completed.

              so I would have to say 2
              • 19. Re: ArrayList help
                843785
                In my honest opinion you should be given extra credit for using the collections method, shows that you can reduce the amount of code you write and researched an algorithm, buts that's my .02
                • 20. Re: ArrayList help
                  843785
                  From the API

                  IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size())
                  • 21. Re: ArrayList help
                    843785
                    flounder wrote:
                    Help with what?

                    Try providing details. If you are getting an error then copy and paste it here. If it isn't doing what your expected then give detailed explanation of what it does and what you think it should do. What responses to "i need help" were you expecting?
                    I am writing a method that reverses the Strings within an ArrayList, I wrote what I think is right and it compiles like there is nothing wrong then it gives me an error whenever I use the method in my tester (the error is in my previous comment)
                    • 22. Re: ArrayList help
                      843785
                      Thats true but all that shows is that I can search the API's or cry for help on the forums (btw I can do the latter) she wants to see if we can think without methods.
                      • 23. Re: ArrayList help
                        843785
                        Sinanju180 wrote:
                        In my honest opinion you should be given extra credit for using the collections method, shows that you can reduce the amount of code you write and researched an algorithm, buts that's my .02
                        IMHO students should be learning algorithms and not call built in methods. What happens when they graduate and get a job where the language used is not Java and doesn't have such a rich library. How are they going to implement their Lists then if they have no idea of what the algorithm is.
                        • 24. Re: ArrayList help
                          843785
                          flounder wrote:
                          From the API

                          IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size())
                          I tried the index < 0 || index >= size() but and it compiles and runs with no error but it doesn't reverse.
                          • 25. Re: ArrayList help
                            843785
                            tian314 wrote:
                            Thats true but all that shows is that I can search the API's or cry for help on the forums (btw I can do the latter) she wants to see if we can think without methods.
                            If you are referring to my reply #20 where I posted from the API, then did you read what it said? It explains exactly why you are getting that exception.
                            • 26. Re: ArrayList help
                              843785
                              tian314 wrote:
                              flounder wrote:
                              From the API

                              IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size())
                              I tried the index < 0 || index >= size() but and it compiles and runs with no error but it doesn't reverse.
                              Then you must have it in neutral. Want a more specific answer then ask a more specific question with a much more detailed explanation.
                              • 27. Re: ArrayList help
                                843785
                                I did read it and I changed the condition but it doesn't reverse the list, so I'm starting to think its the body.
                                • 28. Re: ArrayList help
                                  843785
                                  First off
                                  Delete, It is not needed
                                  public purse{
                                   // Some code
                                  }
                                  Declare Globally, so your whole program can use it, assuming you want it to use this object
                                  List<String> yourList = new ArrayList();
                                  Finally replace your for statement with this, takes the list size, then decrements i by 1, So you out print list[5], list[4], so on and so forth
                                  int a = purse.size();
                                            for(int i = a; i >= 0; i--)
                                            {
                                                 String temp = purse.get(i);
                                                 System.out.print(temp + " ");
                                            }
                                  hope that provides more info

                                  Edited by: Sinanju180 on Dec 10, 2008 11:21 PM

                                  Edited by: Sinanju180 on Dec 10, 2008 11:24 PM
                                  • 29. Re: ArrayList help
                                    843785
                                    Once again your post conveys ZERO information.