18- Solution- Getting a Quote

Jul 04, 2026 01:26 · 4:15 · English · Whisper Turbo · 2 वक्ता
यो प्रतिलिपि आज म्याद समाप्त हुन्छ । स्थायी भण्डारणका लागि स्तरबृद्धि गर्नुहोस् →
देखाउँदै मात्र
0:03
S… Speaker 2 (18- Solution- Getting a Quote)
Alright, the first thing we need to do is to add a class called quote In
0:08
S… Speaker 2 (18- Solution- Getting a Quote)
this class we need two fields the name of the website
0:12
S… Speaker 2 (18- Solution- Getting a Quote)
and the price they're offering so private string
0:16
S… Speaker 2 (18- Solution- Getting a Quote)
site and private Let's use an integer for
0:20
S… Speaker 2 (18- Solution- Getting a Quote)
simplicity, but in a real -world scenario the price should be a float Now
0:25
S… Speaker 2 (18- Solution- Getting a Quote)
I would prefer to make both these fields final
0:29
S… Speaker 2 (18- Solution- Getting a Quote)
So we don't accidentally change their value in our program
0:33
S… Speaker 2 (18- Solution- Getting a Quote)
Now, because they're final,
0:34
S… Speaker 2 (18- Solution- Getting a Quote)
we should initialize them through a constructor.
0:36
S… Speaker 1 (18- Solution- Getting a Quote)
So,
0:37
S… Speaker 2 (18- Solution- Getting a Quote)
let's generate a constructor.
0:39
S… Speaker 2 (18- Solution- Getting a Quote)
I'm going to select the site field first,
0:42
S… Speaker 2 (18- Solution- Getting a Quote)
and then the price.
0:43
S… Speaker 2 (18- Solution- Getting a Quote)
So now we have a constructor with these two parameters,
0:47
S… Speaker 2 (18- Solution- Getting a Quote)
pretty straightforward.
0:48
S… Speaker 2 (18- Solution- Getting a Quote)
We also need getters for these fields.
0:50
S… Speaker 1 (18- Solution- Getting a Quote)
So,
0:51
S… Speaker 2 (18- Solution- Getting a Quote)
alt and enter,
0:52
S… Speaker 2 (18- Solution- Getting a Quote)
create getter for site,
0:53
S… Speaker 2 (18- Solution- Getting a Quote)
and then create getter for price.
0:56
S… Speaker 2 (18- Solution- Getting a Quote)
We're done with this class.
0:58
S… Speaker 1 (18- Solution- Getting a Quote)
Now,
0:58
S… Speaker 1 (18- Solution- Getting a Quote)
let's add a new class called
1:03
S… Speaker 2 (18- Solution- Getting a Quote)
flight service.
1:05
S… Speaker 2 (18- Solution- Getting a Quote)
With this class,
1:06
S… Speaker 2 (18- Solution- Getting a Quote)
we're going to get a quote from a given flight agency.
1:09
S… Speaker 2 (18- Solution- Getting a Quote)
So here we need a method called get quote public quote
1:13
S… Speaker 2 (18- Solution- Getting a Quote)
get quote from this website.
1:17
S… Speaker 2 (18- Solution- Getting a Quote)
There's a problem here.
1:19
S… Speaker 2 (18- Solution- Getting a Quote)
Can you tell I'm returning a quote object?
1:22
S… Speaker 2 (18- Solution- Getting a Quote)
This is a synchronous method.
1:23
S… Speaker 2 (18- Solution- Getting a Quote)
We don't want our methods to run synchronously.
1:26
S… Speaker 2 (18- Solution- Getting a Quote)
So instead of a quote,
1:28
S… Speaker 2 (18- Solution- Getting a Quote)
we should return a completable future of quote and
1:33
S… Speaker 2 (18- Solution- Getting a Quote)
here you return
1:34
S… Speaker 2 (18- Solution- Getting a Quote)
completable future dot supply async.
1:38
S… Speaker 1 (18- Solution- Getting a Quote)
Now,
1:41
S… Speaker 2 (18- Solution- Getting a Quote)
here we're going to simulate calling a remote service.
1:43
S… Speaker 2 (18- Solution- Getting a Quote)
So I'm going to use long task dot simulate.
1:47
S… Speaker 2 (18- Solution- Getting a Quote)
And then we should return a quote object.
1:50
S… Speaker 1 (18- Solution- Getting a Quote)
So,
1:51
S… Speaker 2 (18- Solution- Getting a Quote)
return new quote.
1:52
S… Speaker 2 (18- Solution- Getting a Quote)
Now we should pass the name of the site as well
1:57
S… Speaker 2 (18- Solution- Getting a Quote)
as the price.
1:57
S… Speaker 2 (18- Solution- Getting a Quote)
We're going to calculate the price randomly.
1:59
S… Speaker 1 (18- Solution- Getting a Quote)
So,
2:00
S… Speaker 2 (18- Solution- Getting a Quote)
let's create a random object.
2:02
S… Speaker 1 (18- Solution- Getting a Quote)
New random.
2:06
S… Speaker 2 (18- Solution- Getting a Quote)
Now let's say the price is going to be somewhere between 100 and 110
2:10
S… Speaker 1 (18- Solution- Getting a Quote)
dollars.
2:11
S… Speaker 1 (18- Solution- Getting a Quote)
So,
2:11
S… Speaker 2 (18- Solution- Getting a Quote)
we set price to 100 plus,
2:15
S… Speaker 2 (18- Solution- Getting a Quote)
then here we use a random object to generate a random
2:19
S… Speaker 2 (18- Solution- Getting a Quote)
integer between 0 and 10.
2:21
S… Speaker 1 (18- Solution- Getting a Quote)
Okay?
2:22
S… Speaker 2 (18- Solution- Getting a Quote)
Now we pass it over here.
2:24
S… Speaker 2 (18- Solution- Getting a Quote)
Also for clarity,
2:26
S… Speaker 2 (18- Solution- Getting a Quote)
I would prefer to add a message here.
2:28
S… Speaker 2 (18- Solution- Getting a Quote)
Getting a quote from this
2:32
S… Speaker 1 (18- Solution- Getting a Quote)
website.
2:34
S… Speaker 2 (18- Solution- Getting a Quote)
Now I forgot to put a semicolon over here.
2:37
S… Speaker 1 (18- Solution- Getting a Quote)
Good.
2:38
S… Speaker 2 (18- Solution- Getting a Quote)
Now let's test this.
2:39
S… Speaker 2 (18- Solution- Getting a Quote)
So we go to our demo class and create
2:43
S… Speaker 2 (18- Solution- Getting a Quote)
a flight service object.
2:45
S… Speaker 2 (18- Solution- Getting a Quote)
New flight service.
2:47
S… Speaker 2 (18- Solution- Getting a Quote)
Then we call service .git quote.
2:50
S… Speaker 2 (18- Solution- Getting a Quote)
Let's pass site1.
2:52
S… Speaker 2 (18- Solution- Getting a Quote)
This returns a completable feature.
2:54
S… Speaker 2 (18- Solution- Getting a Quote)
So we can call then accept.
2:57
S… Speaker 2 (18- Solution- Getting a Quote)
Here we pass a consumer.
3:00
S… Speaker 2 (18- Solution- Getting a Quote)
This is where we get the quote.
3:01
S… Speaker 1 (18- Solution- Getting a Quote)
And
3:03
S… Speaker 2 (18- Solution- Getting a Quote)
we can print it on the terminal.
3:04
S… Speaker 1 (18- Solution- Getting a Quote)
Now,
3:05
S… Speaker 2 (18- Solution- Getting a Quote)
for simplicity,
3:06
S… Speaker 2 (18- Solution- Getting a Quote)
I'm going to go to the quote class and overwrite the toString method.
3:10
S… Speaker 1 (18- Solution- Getting a Quote)
So,
3:11
S… Speaker 2 (18- Solution- Getting a Quote)
we put the caret over here,
3:12
S… Speaker 1 (18- Solution- Getting a Quote)
generate toString,
3:16
S… Speaker 2 (18- Solution- Getting a Quote)
I'm going to go with the default implementation,
3:19
S… Speaker 2 (18- Solution- Getting a Quote)
so this is going to give us something like quote site equals price.
3:23
S… Speaker 1 (18- Solution- Getting a Quote)
Okay?
3:24
S… Speaker 1 (18- Solution- Getting a Quote)
Now,
3:25
S… Speaker 2 (18- Solution- Getting a Quote)
back to our demo class,
3:26
S… Speaker 2 (18- Solution- Getting a Quote)
here we get the quote and simply print it on the terminal.
3:31
S… Speaker 2 (18- Solution- Getting a Quote)
Now, this lambda expression is simply calling a method.
3:34
S… Speaker 2 (18- Solution- Getting a Quote)
So we can use a method reference here.
3:36
S… Speaker 2 (18- Solution- Getting a Quote)
Alt and enter,
3:37
S… Speaker 2 (18- Solution- Getting a Quote)
replace with method reference.
3:39
S… Speaker 2 (18- Solution- Getting a Quote)
It's pretty straightforward.
3:40
S… Speaker 2 (18- Solution- Getting a Quote)
So we get a quote and then print it.
3:43
S… Speaker 1 (18- Solution- Getting a Quote)
Now if we run our program,
3:45
S… Speaker 2 (18- Solution- Getting a Quote)
our program is going to terminate immediately because we're not waiting for the result of
3:50
S… Speaker 2 (18- Solution- Getting a Quote)
this asynchronous operation.
3:51
S… Speaker 1 (18- Solution- Getting a Quote)
So I'm going to put a delay
3:55
S… Speaker 2 (18- Solution- Getting a Quote)
of let's say 10 seconds.
3:57
S… Speaker 2 (18- Solution- Getting a Quote)
That's way too much,
3:59
S… Speaker 2 (18- Solution- Getting a Quote)
but that's fine for now.
4:00
S… Speaker 2 (18- Solution- Getting a Quote)
Now let's wrap this inside a try catch block.
4:04
S… Speaker 2 (18- Solution- Getting a Quote)
And run our program.
4:06
S… Speaker 1 (18- Solution- Getting a Quote)
So we're getting a quote.
4:09
S… Speaker 2 (18- Solution- Getting a Quote)
After three seconds,
4:11
S… Speaker 2 (18- Solution- Getting a Quote)
the quote is ready.
4:12
S… Speaker 2 (18- Solution- Getting a Quote)
Beautiful.

यो प्रतिलिपि AI (स्वचालित वक्तव्य पहिचान) द्वारा उत्पन्न गरिएको थियो । त्रुटि समावेश गर्न सक्छ - महत्वपूर्ण प्रयोगका लागि मौलिक अडियोसँग रुजु गर्नुहोस् । AI नीति

❤️ प्रेम STT.ai? आफ्नो साथीहरूलाई भन्नुहोस्!
सारांश
यो लिखितको AI सारांश उत्पन्न गर्न सारांश गर्नुहोस् क्लिक गर्नुहोस् ।
सारांश गर्दैछ...
यो प्रतिलिपि बारे AI सोध्नुहोस्
यो transcript बारेमा केही सोध्नुहोस् - एआई सम्बन्धित खण्डहरू र जवाफ पाउनुहुनेछ.