This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

java list with objects and methods  RSS feed

 
Sean Paulson
Ranch Hand
Posts: 87
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So im working on this website that teaches you and they use there own cmd line, but here is my problem.

The program lets the user print seats info on a plane and reserve seats. they want me to add a method to delete a reservation.

here is what i added.

here is the method it is calling in another file


the second file (class seats) does not have get functions only set functions. I deleted them and it didnt effect the program.

My question is how does the makeEmpty method know what seat to delete, if the method call in the first file does not pass any parameters to makeEmpty.

ps the list code if you need to see it is

 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
delete a reservation.

Where does the code keep track of  the reservations?
I wouldn't think a seat was the same as a reservation.  The use of a seat is reserved and that info keep as a reservation.  The seat stays, reserved or not.  A property of a seat would be that it was reserved.
To delete a reservation would be to change the seat's reserved property.

The method would need a reference to the seat to be able to change its contents.
 
Sean Paulson
Ranch Hand
Posts: 87
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
heres the code
this is the first class SeatReservation


here is the second file Class Seat


the code does work but i dont understand this one part

input is
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i dont understand this one part 

Which lines of what source file are you asking about?
 
Sean Paulson
Ranch Hand
Posts: 87
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
80 in the first one and 15 in the second one, how does the method makeEmpty know what seat to make empty when the call in 80 on the first file does not pass a value
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how does the method makeEmpty know what seat to make empty

The makeEmpty() method is in the Seat class.  It changes the values for the one instance of the Seat class.
The code on line 80 uses a reference to an instance of the Seat class to call its makeEmpty() method.
Here's an expansion of line 80:
 
Sean Paulson
Ranch Hand
Posts: 87
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok i think i get it, i think im just over thinking it
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!