This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Transfer Learning for Natural Language Processing (MEAP) and have Paul Azunre on-line!
See this thread for details.
Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

How can I retain integers?

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not have a code just yet, only planning it. It will be about a plane route. The airports are basically numbers from 0-10.
If the plane finishes a route, I want to loop the whole main method again, with a newly generated random destination, however I also want to retain it's position from the previous fly and not reset it.
How can I do it?
 
Marshal
Posts: 68917
275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Aron Gaspar wrote:I do not have a code just yet . . . loop the whole main method again . . .

I am afraid that is the wrong way to design an application. Don't talk about implementation details until you have explained (to yourself, if not to us) what you are going to do.

Do you know how to make an object retain information?
 
Aron Gaspar
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reading through what you linked, alright, I will not plan ahead how will I do it until I get there.
However I also have a different code, that has the same problem (I wanted to start this flying one, so I can build it up a bit more clearly).
Should I insert that code here?
 
Campbell Ritchie
Marshal
Posts: 68917
275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Aron Gaspar wrote:. . . However I also have a different code . . .

Yes, please show us the code. But you will probably get murther if you explain the design of your aeroplane class.
 
Aron Gaspar
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

So far this is the code. I also made two classes for generating random numbers for destination floor and passenger floor.
However I can not figure out how to use the elevator's position from the previous run.
 
Campbell Ritchie
Marshal
Posts: 68917
275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please don't write such long llines, which are illegible. Please have a look at the old Sun Style Guide, which makes suggestions about how to shorten lines.
I can't see anything about airports and planes there, but the principle is the same. You have some design which I think should be improved, like having a .floor field simewhere which doesn't have private access. Why are you moving elevators randomly? Where does your elevator record which floor it is at, and which direction it is travelling?
 
Aron Gaspar
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Makes sense, sorry about that.
It's not the aeroplane one, a bit different, but very similar.
The elevators are moving randomly because it moves to the randomly generated passenger, and then moves to the randomly generated destination.
We did not study objects yet, so I could not make the elevators' own object, so I could only do the floors and directions this way.
 
Campbell Ritchie
Marshal
Posts: 68917
275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for delay; I was taken aback by being told you didn't know about objects. This is one way you can record such a number:-
 
WARNING! Do not activate jet boots indoors or you will see a tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic