• Post Reply Bookmark Topic Watch Topic
  • New Topic

Boolean status  RSS feed

 
juan barrios
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there I am new to java, i have some questions. I am writing a program about a race. I have created 2 hierarquies (car) ( race)

Car --------- f1Car, nascarCar
Track -------- f1Track, ovalTrack

my question is
i have two methods

Track class
Start race
Finish race

Car class

my idea is to create a boolean variable: Boolean isRacing = true ( only valid when car is racing)
when i call finish race the boolean changes: set Boolean isRacing = false
but i dont know how to implement.

Can you help me???
 
Joe carco
Ranch Hand
Posts: 82
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
give your Track class a reference to Car, in other words:

Tack t = new F1Track();
Car c = new F1Car();
t.setCar(c);
t.startRace();

the method startRace() calls this.c.setRacing(true);
the method finishRace () calls setRaching(false);
 
juan barrios
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you

 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
juan barrios wrote:Thank you


Welcome to JavaRanch Please avoid excessive spaces between the lines, that way the reader need not scroll down. Also please use CodeTags to post your code, so that it doenst get mixed with the other text. This FAQ should help you get started on these issues
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please don't use that much whitespace. I've cleaned up your post a bit.
 
karthik Suryanarayanan
Ranch Hand
Posts: 121
Java Opera Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First define classes needed(Ex CAR) . In the respective classes ,identify what are its variables & methods . ex).startRace . Now create objects for particular classes & define the boolean variable as false first.
Then when startRace is called set the variable to true. Again when it calls finishRace set it to False .
 
Campbell Ritchie
Marshal
Posts: 56545
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might do well to have a List<Car>, in which case you can have several cars racing and start them all together.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!