Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at Troll_Machine.getTicketData(Troll_Machine.java:103)
Angelos Naoumis wrote:I need to say somehow that arraylist has 4 tickets inside. But i dont get how should i do that.
Do i need to add the following line in method aswell (Somehow?)
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Angelos Naoumis wrote:
Angelos Naoumis wrote:PS2: Open to suggestions and ways to improve my code >
Campbell Ritchie wrote:Don't know. Depends whether you need any more information to create tickets. Since you have a Ticket class which takes a no‑arguments constructor, that will create 4 tickets. But your ticket objects have −1 as their price; I think that is not what you want. I think you should require the three details in the constructor. Also where does availableq come from? Why are you setting it to −1?
You appear to have misread the instructions. It doesn't say anything about Lists, but arrays. I think you start with 200 motorcycle tickets at €1.25 each; whenever you sell one you reduce the available number by one.
Not quite totally pointless; it allows us to see where the code has been misunderstood, e.g. Troll_Machine (sic) line 105. That is not the end of a while loop.Junilu Lacar wrote:. . . Putting in comments like these is just "busy work" -- on the surface, it gives the feeling that you're doing something useful but in reality, it's totally pointless. . . .
Campbell Ritchie wrote:By the way: underscores _ are only allowed in constant names or package names. It isn't Troll machine ()
Junilu Lacar wrote:Read your instructions again very carefully. In particular, this one:
2) Create a Toll-Machine object, which consists of an ID and an array of 4 ticket objects
What does that tell you about where to keep your ticket objects?
All things are lawful, but not all things are profitable.
Campbell Ritchie wrote:It says so in our old JavaRanch style guide. I should have said I don't believe do loops are bad when I directed OP's attention to it. The style guide does however say it is hard to undertand because it is not obvious where it starts and ends, so an // end comment might be worthwhile.
I should have said convention doesn't allow underscores, shouldn't I? The Java Tutorials say you should add underscores to package names when your website might start with a number or look like a keyword. So a 7-zip package would be namedJunilu Lacar wrote:[. . . Technically, they are allowed. By convention they are only used in constant names. I don't think I've ever seen package names that use underscores.
I was more worried that we were discriminating against Rolls.And let's not start discriminating against Trolls now. . . .
I did say “might”. Making the structure of the code obvious is far better.Junilu Lacar wrote:[. . . I think if you do the above, you can pretty much invalidate any superfluous "// end do" comment
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |