Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranî)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
In this video, we're going to cover the solution for part one, like before each class that models
an object was placed inside the models folder and the main class is by itself.
We're going to start with task one, which is that all the necessary fields to the movie class.
Into the fields are private string name.
Private string format.
Private double orating.
Private double selling price.
Private double rental price.
And a private boolean field named is available is going to determine whether the movie is in stock or
rented.
And task to reminds us that if a class has failed and needs to apply the big three steps, the first
step is to create a constructor.
But once again, it's only going to receive three parameters.
String name, string format.
Double orating.
Here is where we set every field in that object equal to a parameter value.
The name.
This format.
This stock rating.
As I'm updating the selling price, first, I'll check if the format equals Blu ray.
If so, I'll set the value equal to four point twenty five, otherwise two point twenty five.
I'll do the same thing for the rental price, I'll check if the format is blue, right?
If so, I'll set the value to one ninety nine.
Otherwise, 99 cents.
And that first is available is going to be true for every movie.
Next thing we want to do is autocomplete, the gutters and setters.
Now, getas for bullion types are written differently, if you try to write get, you're not going to
get any results.
That's because the standard naming for Boolean getters is to preface the field with is followed by the
field name.
Here are some examples.
And in our case, the field already starts with and is so the gutter is just going to share the same
name.
Going back to the code if you write is.
This code recognizes that you want to autocomplete a getter for your boolean.
OK, now we can just autocomplete the suttas.
However, we're going to make selling price private, we need to hide this setar because the color shouldn't
be allowed to use it.
That's because the format they pass in should automatically determine the selling price.
So instead of set format, it needs to update the format and update the selling price, so we'll call
set selling price and the value we pass in into selling price will be based on a condition if it equals
Blu ray.
We're going to pass in 425.
Otherwise, we'll pass to 25.
And the beauty about the syntax is that it replaces six lines because otherwise you'd have to write
something like this.
It's totally fine if you want to use a false, but I just prefer keeping the code as short, as concise
as it can be.
Anyways, we'll do the same thing for Ronald Price will make it private.
And once again, we're going to check if format equals Blu ray.
In which case, we're going to pass 199.
Otherwise, 99 cents.
Now, I know that we're supposed to test our code and task five, but it doesn't hurt to test what we
have so far.
And an important movie from the model's package.
And now that I've imported the class, I can use it, first thing I'll do is create a new object of
the movie store costs.
The move is going to be The Shawshank Redemption.
It will have a Blu ray format.
In any case, we'll put a break point right here, I'll step into the constructor.
This points to the current object we just created.
It updates every field, it sets the selling price, the twenty five, because the format is blurry
and it sets the rental price to one ninety nine once again, because the format is Blu ray.
OK, now we can test the format setter.
We'll change the format to DVD.
Relaunch the debugger.
I'm going to step over creating the object.
And setting the format automatically determines the selling price as well as the rental price, great.
Now we can move on to tasks three and four, the next step is that a copy constructor, because at some
point we need a way to copy moving objects without falling into the reference trap.
So I'm simply going to copy this constructor.
And instead of parameters, we're going to be obtaining values from a source object.
Then I'm going to set every field in the current object equal to the field value from a source object,
nothing new here.
Let's visualize what's going on.
Back in Maine, I'm going to create a new movie object that copies every field value from this one.
Take out a breakpoint to visualize the runtime.
This points to the new contact object that we just created, Saurus points to the object that we passed
in, and one by one, we're copying every value from the source object into the current object.
And the next task tells us that every class that models an object should have a two string method,
dominate a two string method to our class public string to string.
And then you're going to copy over the format that I left you from the article.
And who replaced the placeholders where we need to?
Now, four is available here.
We're going to check if the movie object that's calling the two string method if it is available.
And if this ends up being true, we're going to return in stock.
Otherwise, we're going to return a rented.
All right, we're done creating the movie class.
And inside main, I'm going to print the object.
And everything works beautifully.
Notice that it shows in stock because the movie is available.
We can try setting the availability to false.
And this time it shows the movie is rented.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.