• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using class Iterable and sorting ArrayList

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have to write a method setOrder() which takes enumeration constant defined in Report so iterating over Bills is performed in the order specified by this constant and i have have no clue where to start.
this is what i have so far, let me know what i did wrong and what i should do next.

 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

mike karl wrote:i have to write a method setOrder() which takes enumeration constant defined in Report so iterating over Bills is performed in the order specified by this constant and i have have no clue where to start.
this is what i have so far, let me know what i did wrong and what i should do next.


What you did wrong was to start writing code without thinking about what you should do.

The single most important thing a programmer needs to do is NOT WRITE CODE. Before committing a single byte to file, you should think through the problem in very NON-java terms. you should pretend you are explaining to a child what needs to be done.

Only when you've done that, revised it and simplified it several times, should you write any actual code.

So I would say your next step is to delete what you have, turn off your computer, and put pencil to paper.
 
mike karl
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

fred rosenberger wrote:

mike karl wrote:i have to write a method setOrder() which takes enumeration constant defined in Report so iterating over Bills is performed in the order specified by this constant and i have have no clue where to start.
this is what i have so far, let me know what i did wrong and what i should do next.


What you did wrong was to start writing code without thinking about what you should do.

The single most important thing a programmer needs to do is NOT WRITE CODE. Before committing a single byte to file, you should think through the problem in very NON-java terms. you should pretend you are explaining to a child what needs to be done.

Only when you've done that, revised it and simplified it several times, should you write any actual code.

So I would say your next step is to delete what you have, turn off your computer, and put pencil to paper.



is it really that badly done, this is my second semester in programming and my teacher doesnt explain much, im not sure how i can revise this if im not even sure what this is, i never used iterators. i never set up a enumerator to perform sorting. i need some helpful advise
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

mike karl wrote:is it really that badly done,


Fraid so; although I think I understand what you were attempting to achieve.

this is my second semester in programming and my teacher doesnt explain much, im not sure how i can revise this if im not even sure what this is, i never used iterators. i never set up a enumerator to perform sorting. i need some helpful advise


And you've already received it. Most of us have BTDTGTTS, so unless you haven't shown any effort (which you plainly have), we're not trying to belittle you.

The fact is that Fred's absolutely right, you've decided on an implementation (your code) before you've understood the problem - and that's always a bad sign - and now you're in the position of trying to defend the indefensible.

My advice: StopCoding (←click) before you have too much invested in this to turn back.

There are plainly some good ideas in your attempt; it just happens to be wrong.

Here's a possibility for you: Have your enum (one of your good ideas) implement java.util.Comparator<Bill>. Have a think about it and see if it makes any sense.

Winston
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

mike karl wrote:


This certainly looks wrong; it's an unbounded recursive loop. The method iterator() calls itself, which calls itself, which calls itself, which calls itself, etcetera, until it crashes with a StackOverflowError.
 
mike karl
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Winston Gutkowski wrote:

mike karl wrote:is it really that badly done,


Fraid so; although I think I understand what you were attempting to achieve.

this is my second semester in programming and my teacher doesnt explain much, im not sure how i can revise this if im not even sure what this is, i never used iterators. i never set up a enumerator to perform sorting. i need some helpful advise


And you've already received it. Most of us have BTDTGTTS, so unless you haven't shown any effort (which you plainly have), we're not trying to belittle you.

The fact is that Fred's absolutely right, you've decided on an implementation (your code) before you've understood the problem - and that's always a bad sign - and now you're in the position of trying to defend the indefensible.

My advice: StopCoding (←click) before you have too much invested in this to turn back.

There are plainly some good ideas in your attempt; it just happens to be wrong.

Here's a possibility for you: Have your enum (one of your good ideas) implement java.util.Comparator<Bill>. Have a think about it and see if it makes any sense.

Winston



ok thanks ill see what i can do, just understand i am in Poland and they dont explain well enough, i feel like i am being rushed through alot of material but maybe its just me.
 
reply
    Bookmark Topic Watch Topic
  • New Topic