All language subtitles for 016 Scanner - part 1_en

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

We can use scanner to make our applications interactive.

We've already built many applications using the five main data types.

Br view they are int to store whole numbers long for large real numbers, double for decimals, car

for characters and string for text.

But there is a small issue with the apps you've built so far, and that is that they've been static.

In other words, you've been storing predefined values.

Now in the real world, you want to make a dynamic application where values come from, the user.

Like here, for example, the application is asking the user questions and the user answers by submitting

values through the terminal.

And once the user answers every question, the application responds, this application is fully interactive

because the application and the user are communicating with each other.

So in this lesson, you're going to use scanner to get values from the user.

First thing I need you to do is create in your class, so inside the Section two project to make a new

file named Survey Java and inside the survey class, make sure it has the main method.

Scanner waits for the user to enter a value in the terminal.

In the survey app, you will ask the user questions such as How old are you?

And now Scanner needs to wait for the user to enter an integer.

We do that with scanned next minute.

And now the user must go to the terminal type a number and press enter.

Once the user presses enter, scanned next and picks up the integer and stores it in the variable.

We need to import scanner in order to use it.

Scanner comes from a package called Java Util.

So from Java, you tell we can import scanner.

And notice that we import at the very top.

So back to our code, we're going to import scanner, to the survey class import and from Java, you

tell we're going to import scanner.

Now we can access scanner inside the survey class.

Simple as that.

And so the next step is to set up scanners so that it can receive input from the user.

So we need to make a scanner variable, and that involves three steps.

The variable must be F-Type's scanner, the variable name I usually call it scan, but you can call

it anything and you're going to set the variable equal to a new scanner such that this scanner can get

input from the system system not in.

Scanner.

Skin.

Is equal to a new scanner instance.

That's going to receive input from the system system in.

And now we're going to use scanner to get a values from the user.

Scanner has different methods that we can leverage to get values from the user.

And next line is one of them.

Next line waits for the user to enter a string.

So we're going to start by giving the user a warm welcome.

So system died out the bright line.

Welcome, thank you for taking the survey.

Then we'll say system.

Dot out dot print line.

What is your name?

All right.

Let's compile the code and run this.

As you can see, this only prints two messages, then the app terminates.

We need to cull Skin Dot next line so that it can wait for the user to enter a stream value.

All right, let's try it out.

Compile your code.

Run it.

And check it out, it waits for me to enter a string.

I'm going to right, Sam.

And there you go.

What's happening is that Scandal Next line waits for the user to enter a string.

The user being me and the user went to the terminal and typed, Sam.

And once the user presses enter scan, the next line picks up the value.

But to be able to use this value in the future, we have to store it inside a variable.

So what I'm going to do is say string name is equal to scandal.

Next line.

So now, when the user enters their answer, scanned, the next line gets the string of value and stores

it in the variable name.

Next, stubble is another method we can call from Skinner.

This one waits for the user to enter a double value.

So now we're going to ask the user how much money they would spend on coffee.

So System died out die print line.

Money, do you spend?

On coffee.

And now, Renee, you stand up next, double to wait for the user to enter a double.

So we'll say double.

Coffee price.

Is equal to scan next double.

All right, we're compiling our code.

And running it.

What is your name, Sam?

How much money do you spend on coffee?

Let's say a dollar fifty.

So what happens is it picks up the value and stores it in a variable coffee price.

First, the programs they use or how much money they spend on coffee scanned next level, wait for the

user to enter a decimal.

It picks it up and stores it in a variable.

All right.

For more practice, we're going to ask the user how much money they spend on fast food system dart out

dart line.

How much money?

Do you spend on fast food?

And you're going to store the user's answer in a variable double food price is equal to scan Dot next

double.

What is your name, Sam?

How much money do you spend on coffee?

A dollar fifty?

How much money do you spend on fast food will say four dollars and fifty cents.

And once again scanned next, I will wait for the user to enter a decimal.

It picks it up and stores it in a variable.

Next is another method you can call from scanner.

And this one, as you could probably guess, it waits for the user to enter an integer.

So to start ominous, these are how many times a week they buy coffee and how many times a week they

buy fast food.

So system dot out dot print line.

How many times a week?

Do you buy coffee?

And I'm going to store the user's answers in a variable coffee amount.

And we're going to set that equal to scan next.

It.

Then we'll do the same thing here, system dot out dot print line.

How many times a week do you buy fast food?

And we'll store the user's answer in a variable food amount.

And we're going to get the user's answer by waiting for the next it's.

All right.

Recompile the code and run it.

What is your name?

Sam?

How much money you spend on coffee, a dollar?

Fifty four dollars and fifty cents?

How many times a week do you buy coffee?

Five.

Fast food seven.

All right.

This app is shaping up pretty well.

The first scandal, an accident, waits for the user to answer the key question.

Then it picks up the value in stories that in the amount, the second scanned on and waits for the user

to answer the fast food question.

Then it picks up the value and stores it in food amounts.

And now every variable stories is one of the users answers.

You might be wondering what if the user puts a wrong value?

And the second question, for example, let me just rerun my code.

When I put in the first answer and now here, what if I put a string, when next they will expect a

decimal?

Let's try up.

And Java throws an error and it crashes.

Next, we'll expect to decimal notice drink, and so if you enter a string next double doesn't know

what to do with it.

So the application crashes.

You should close the scanner when you're done with it.

Keeping scanner open is a memory leak.

When you're done with it, you can close it with scanned clubs.

Scan Duclos.

Now, if you scroll up notice that the warning is gone.

Let's recap in this lesson, you learn to use scanner to get values from the user.

Next line waits for the user to enter a string value.

And once the user presses enter scanned, our next line picks up the string and stores it in the variable.

Next double waits for the user to enter a double value, and once the user presses enter scan, the

next double picks up the double and stores it in the variable.

Next in, wait for the user to enter an into value.

And once the user presses enter scanned next and picks up the end and stores it in the variable.

Restore it every value that the user entered.

So what do we do now?

Stick around for part two.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.