Hey, welcome back.
In this video, we will work on the reservation ticket method.
So so far we have implemented the methods up to here.
So the book method, the available method of the hotel class.
Now we go and implement the methods which are called from now on.
So first we create a reservation ticket instance out of the reservation ticket class, which gets a
name and a hotel.
Argument.
So customer name and hotel object.
So basically you could say a customer name is equal to name.
So name is this name in here.
And then hotel objects is equal to hotel.
So hotel is this object.
So no, that name is a string, right?
An instance of a string class.
So even Python has classes.
So STR is a class, right.
Similarly, when you say class.
Reservation ticket.
Just pass or wherever.
If you add some methods, that's fine too.
And if you say reservation ticket, this is also a class.
You see class here, class there.
And so then you have instances of strings such as audit that is an instance of of the string class.
And then you have instances of the reservation ticket class.
So that's here is an instance of that class.
Now, you don't get any beautiful thing printed out, because that is that is the nature of this class.
It's not supposed to look like a string, right?
But it's still an instance.
Now, you could also create string string instances like this.
So that is the equivalent of.
This bored python.
The interpreter allows us to write the instances by just mentioning this for strings.
So this is like some magic.
It's called syntactic sugar.
So basically some magic around the syntax so that you don't have to write the instance like that.
So that was some more lecturing about instances, right?
So a hotel is a hotel instance.
String is a string instance.
And so then we generate the ticket.
So let's add some codes in here.
You can say content is equal to F.
Let's have this like a multi line string.
Thank you for your reservation.
Here are your booking data.
So you can see then name that you have a placeholder.
So this would be the customer name again.
Can you write it like customer name like that?
Well, no, because this is a local variable of the init function.
So in that case we make this an attribute of a reservation ticket instance.
We do that using self.
So self is an instance and then we add customer name to that instance.
So customer name now is an attribute of that instance and the value of this attribute is equal to whatever
the user
passes in here, right?
So name.
If the user enters ordered, then the attribute this will be equal to audit or another John wherever
it is.
And then we use here self that customer name, right?
So that's one hotel name.
Perhaps we should include the hotel name in the ticket as well.
So that would be self dot, hotel, dot.
Now this is interesting here.
So we should be able to get the name from the hotel, but the hotel doesn't have a name attribute,
so perhaps we should add a name attribute here for the hotel.
Right.
Which would be equal to default lock.
It's the same syntax as this mostly.
So I can write that in here.
And we want the name.
So what I'm getting here is this value to Estonia apartment or snow palace or city break in.
So that is the name column.
And that code will give us that.
And also we need squeeze to extract the actual string.
And then we extract the name out of that hotel.
So hotel now is not recognized yet because we need to create that as an attribute of the reservation
ticket instance.
So self hotel is equal to hotel object, right?
So you see we have an a hierarchy of objects and attributes, right?
So we have the reservation ticket instance and the reservation ticket instance has as an attribute,
a hotel instance and a hotel instance has as an attribute a string instance right here, self that name
self, that hotel, you see that that's a hierarchy of attributes.
And this makes the code more robust and more readable and also more extensible.
You can easily extend it later.
As you'll see, we will add more classes later on.
So we extract the name of the hotel.
Similarly, you could also get the city.
From the hotel, but I'll just leave it as it is.
So just the customer name and the hotel name as well.
So that is a constant variable and of course you need to return that content variable and then this
will print out that content variable in here.
So let's try to run this.
We get the lease of hotels?
Oh, no.
Hotel is available now.
So if you try to say 188, you'll get this hotel is not free.
So what I'll do is I'll go to hotels and make the second hotel available.
So.
Right.
Yes.
There.
Save the seals file with control S don't forget.
And then run main dot P again.
So let's try 188 which is available 188 Press enter.
Enter your name or date and then that is our ticket reservation confirmation.
So thank you for your reservation.
Here are booking data.
Name or dates?
Hotel name Snow Palace.
We can go with this ticket to the checking desk and we can check in for that room.
Of course, there are more details to this.
You need like a PDF perhaps to go to the hotel with that printed PDF.
And you also need perhaps a credit card.
You need to have paid that hotel at some point, but that is a feature we will add tomorrow a credit
card payment feature.
For now.
This is the complete code for today.
So that is how you create programs using o p object oriented programming.
So your program is oriented around objects, a hotel object, a reservation ticket object.
This keeps the code some more manageable.
So perhaps you can also add later a method here which cancels the ticket like def cancel.
Right.
That is also possible.
It is easy to add.
And yeah.
With that.
Thanks a lot for following and I'll talk to you later.