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 part two, your challenge was to code the logic to determine the winner so we can jump right into
task four, which tells us to write a function that compares your choice against the computer's choice
to determine the game results.
I already have the function defined for you.
It returns a string.
And it takes two parameters string your choice and string computer choice.
So it's going to use your choice and the computer's choice to determine who won.
Then it's going to return a string that represents the game results for now, the result being returned
as an empty string.
But we're going to update the result according to seven different scenarios that could occur here.
I outlined every scenario where the user wins or loses.
So all you have to do is rewrite each scenario as a condition.
So we're going to start by checking if your choice.
Equals rock.
And the computer's choice.
Equal scissors.
Then you win.
So we're going to set result equal to you win.
That's what's going to get returned.
Then in case that doesn't run, we'll check for the opposite scenario where the computer chooses rock.
In.
You, too.
Scissors.
In which case we're going to set the result equal to you would lose.
So there are five more conditions.
I'm going to leave the rest up to you.
And just fast forward from here.
So at this point, we coded every possible scenario and we're done task for.
So when we call this function, it's going to take your choice and the computer's choice, it's going
to evaluate both values against every single condition.
Then it's going to return a result based on which condition ends up being true.
So we can call this function for main.
And we're going to store the result of the game in a variable results.
All right, before we move to task five, I want to see if the function returns the right results.
So I'm going to print the result in main.
And test my code.
Hmm.
It's a tie.
Let me try again.
I feel like winning.
And I guess I'm just never going to win.
But I like that we now have a fully functional game.
Anyways onwards to Task five.
All right.
So Task five tells us to write a function that prints your choice, the computer's choice and the results.
So we're going to say public static.
The function is void because I don't see anything about a return value.
It's going to be called print result.
And as you can see, it takes three parameters.
String your choice.
Strange computer choice and strange results.
And inside the function, I'm going to print your choice, the computer's choice, and the results.
So I'll just move these.
Over here.
And we're all done.
Congratulations on making it this far and building your second interactive game in Java.
In the next section, we're going to add another skill to our Java toolbox.
The ability to run code in a loop.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.