Afrikaans
Akan
Albanian
Amharic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
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
This video is going to cover the solution for part five based on the requirements we can define for
fields private.
Long time stamp.
Private string ID, by the way, the reason this is a long is because time stamp values can get really
large and then we'll say private double amounts.
And now the type field can be one of two values, withdraw and deposit.
So what I'm going to do is create an enum named type.
With two constants withdraw and deposit.
And Harold, declare a private field.
Of type, type, named type.
Now, a lot of constructor public transaction they receives for parameters.
On second thought we can just auto generate this.
All right.
We'll add a copy constructor by copying this one.
And instead of receiving values from four different parameters, we're going to receive values from
a source object transaction source.
This duct tape equals sauce, duct tape, source timestamp, source that I.D. and sauce that amounts.
OK, now we're going to auto generate the getters and setters.
Pretty easy.
And now back on learn the parts you go here.
Task number six was to convert the time stem field into a debt.
Accordingly, if we scroll back to the requirements.
Remember, you should always write unit tests for logic that is considered meaningful.
So inside of the test folder, we're going to create a file named transaction.
Tests.
And I believe there was something on there in the part we had to import.
Let me just have a look.
And indeed, we did will import the following snippet.
We'll use autocomplete to get rid of these errors.
OK.
We should be good.
OK, now what we want to do is unit test our capability of converting this long value into a date.
So I'm going to create a unit test.
Public void.
Correct date test.
And now, if we go to any Web site that converts long values into a date, we can convert this one time
stamp to human dates and we get back January 7th, 2019.
So that means that we need to assert assert equals.
We're expecting a value of, oh, seven.
01 2019.
When we call transaction date return dates.
A method that does not exist yet, so back here inside of transaction Java.
We're going to write code to make the test fail.
So I'm going to write public string return dates.
For now, just return high.
And if you go back here.
Figured the test fails now we just got to write code to make it pass.
I left you a lot of hands on during the part, so if you were to look at the documentation, the date
constructor returns a date based on the number of milliseconds since 1970, but our long value represents
the number of seconds since 1970, so all we got to do is say.
Dates date will create a new object of the debt class.
For now will pass in the time stamp, which is the number of seconds since 1970.
But remember, it's expecting the number of milliseconds.
So what we're going to have to do is multiply by a thousand.
So now we have our data object, we just got to format it into a string and we've already done this
like two sections ago.
So I'm going to skip the explanation and we'll go ahead and just create a new object of the simple date
format class.
And we're going to format our date to be in the form day, month, year.
And using this format, we can format our date into a string.
Perfect.
Let's run our unit test.
Go back to transactional tests, run the test.
And we get an error.
Expected.
Negative 2013, but was.
Oh, seven, oh, this is seven minus the one minus 2019.
This should be a string.
Well, we run our tests.
And we're good.
OK, now Task nine was to override equals and hash code, you can just generate them.
Calls and hash code.
OK.
Import the object class.
And now we want to make sure our objects are sortable from lowest time stamp to highest timestamp.
And in order to sort our objects, they need to be comparable.
That is, every transaction needs to implement the comparable interface implements comparable.
And because we implemented the interface, we're signing a contract of behavior that forces us to override
every method inside this interface.
There is only one method, you know it very well, it's compared to.
Compared to expect an integer, that integer is the result from comparing double dot compare.
From comparing the timestamp of the current object, this timestamp against the timestamp of the one
being passed in.
This is going to be useful once we have hundreds of transactions inside of an array, the array is going
to use this method to compare it to transaction objects at a time and based on each comparison, it's
just going to know how to sort from lowest to highest anyways.
Final task is to override to string.
So we'll just generate it.
But we're not going to use this format.
Just copy the one from lowering the parts.
Copy this over.
And here will say.
Return dates that start return date.
OK, the final step is to always apply quality control in case the data being entered is faulty.
You just never know.
There's three hundred rows.
One of the lines could be bad.
We want to throw an unchecked exception, which basically forces the caller to fix their code and anticipate
such a scenario instead of just passing it in that way, they're not sending over bad data.
So we'll go back here.
Now, time stamp is always valid because positive timestamp means seconds since 1970, and a negative
timestamp is the time that comes before 1970.
So that's fine.
No matter what value we get, it shouldn't be null or blank.
So our quality control that will say if ID is equal to known or indeed is blank.
And also, the amount can't be negative, because the type, whether it's withdrawal or the opposite,
it's going to determine whether we subtract or reduce the amount from the account balance.
So we need to quality control that as well.
Amount cannot be negative.
In such a case, we need to throw a new illegal argument exception.
Invalid params.
We'll do the same thing inside the centres inside of it.
We're going to make sure that the ID.
It's not equal to no.
Or if it's blank.
In that case, we want to throw a new illegal argument exception.
Invalid I.D..
And we'll do the same thing inside of amounts, if amount is smaller than zero.
There are new.
A legal argument exception.
Invalid amount.
That's it.
Moving on to part six.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.