Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Elevator Final Result  RSS feed

 
Alex Munoz
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The program compiles but my final results give all the same values for each elevator. How could I translate the numerals for direction into words for the print-off?

There is obviously something hugely wrong. Please help

 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't looked at your code in great detail, but this jumped out at me:



You're passing a floor parameter, but completely ignoring it, doing nothing with it, and then you're declaring a local targetFloor variable, setting it to 1, and then doing nothing with it. That method is exactly the same as if you had written it like this:


Also, you're ignoring the num parameter you're passing to your Elevator constructor.

Your code looks like you just threw together a whole bunch of stuff that looked like it might work, without really thinking about what each piece is actually for, and without testing any of the smaller pieces individually, then compiled, ran, and hoped for the best. That's not a particularly effective way to program or to learn.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12541
48
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your constructor:

you are ignoring the num parameter. this is the same as having written:



My honest advice would be to throw all this code away, and start over. When you write code, the first thing you do is to forget about java, computers, programming...and just write down in English what you need to do. Write down the behavior of the things you are trying to model.

Once you have that figured out, in detail, start writing your code - But only write 2-3 lines at a time. compile and test each time you write those lines. Write a lot of code that you will throw away - System.out.println() statements that lets you see what your code is really doing. Only when you are sure that code is correct, should you move on.
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote:My honest advice would be to throw all this code away, and start over...
{lots of good advice}
...Only when you are sure that code is correct, should you move on.

Amen.

Alex Munoz wrote:There is obviously something hugely wrong...

There is; and the main reason is that you don't appear to be heeding any of the good advice you've been given. This is your 3rd thread on this subject, and I don't see much sign that your code has moved forward at all.

For more information about what both Fred and Jeff are saying, you might want to look at this page.

Winston
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!