Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I Need to Write a Method Which Adds a Class Once Run

 
Charlie McCabe
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, This may be simple to use guys but im stuck.

i am writing a booking class once i create a booking i can add and remove tickets to it. my problem is when i want to confirm this booking i need it to be able to add 2 classes (customer & payment) to it for the booking to complete.

This is so i have a customer and payment class assosiated to my booking.

/**
* completeBooking
* creates a new Booking
* @param customer
* @param payment
*/
public Booking completeBooking(Customer aCustomer, Payment aPayment) {

Booking booking = new Booking( aCustomer, aPayment);
booking.setTickets(tickets);

return booking;

}

This is what i had prviously but this was creating a new booking rather than updating the one i have already created. i realise now that instead of a

public Booking completeBooking(Customer aCustomer, Payment aPayment)
i should have a type void like
public void completeBooking(Customer aCustomer, Payment aPayment)

if this is rubbbish tell me! or point me in the right direction to write this method
 
Nick George
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is not complete rubbish.


I assume this is a method of Booking. As such, you can directly access the member variables for customer and payment. Change them to the new value.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure I understand your question, but I'll offer a couple of comments.

It appears that there is no need for this method to return anything, since you really want the side effects of what it "does." However, if you declare your Booking object within the method, its scope will be limited to that method. It seems to me that you'll want to access that Booking object outside of the method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic