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
You made it to part two, we got a bit sidetracked with delimiters, but let's continue building our
dealership up.
Here's what we have so far.
The application asks the user to choose between buying a car or selling one.
You chose option, in which case the princi boring message.
And in this lesson, we're going to add some logic for Case A and the final result should look like
this.
If the client wants to buy a car, the program will check if the client can afford it.
The client has insurance, the client has a license, and if the client has a good credit score and
if everything checks out, the user can buy a car from you.
First, we're going to be checking the client's budget.
We're going to start by removing the Yuko's option, a text and on a new line, we're going to ask the
user.
What is your budget?
Now, you might be thinking to use next double to pick up the value from the user, but honestly, you
could use next double if you want.
But when it comes to buying a car sensor kind of worthless, it's going to keep things as a whole numbers.
I'm going to set a variable int budget is equal to the next in value that the user inputs.
Great next into waits for the user to enter an integer and stores the value inside budget.
Now we're going to check of the headlines, budget is at least ten thousand dollars if budget is greater
than or equal to 10000, and if it is, the dealership will make them an offer will print.
Great, a Nissan Altima is available.
Otherwise, else, if the condition is false, the dealership will reply, we don't sell cars under
10000.
Rewriting my code.
We'll say in a.
Budget of 20000.
And nice, a car is available.
I expect this condition to be true so that the user is offered a Nissan Altima.
Now we're going to be checking for insurance, a driver's license and a credit score, the user must
have insurance and a driver's license in order to buy a car.
So we're going to print two messages.
The first message, we'll ask the user if they have insurance.
We're going to insert a new line of space first again, and then we'll say, do you have insurance?
Right, yes or no?
And we're going to pick up the input using scan next line and stored in the variable string insurance.
And the second message will ask the user if they have a driver's license.
Once again, insert a new line of space and we'll say, do you have a driver's license, yes or no?
And we'll pick up the input using scan next line and stored in the variable license.
Before we run the code, I really hope you caught the next line trap because there's a next event that
precedes your next line.
And remember that the trap can happen when you add next line ahead of any of the scanner delimited methods
in Long Doubler next, in which case your next line is going to get wasted on an empty line.
And the workaround is to add a throwaway scanner next line right before the real next line.
So let's run our code.
Option a budget 20000.
Yes, I do have insurance and yes, I do have a license.
And it all works out.
What happens is the proceeding next and only reads the value that it's interested in such that the throwaway
next line picks up the rest of the line, which ends up being empty.
And now the following next line is ready to read the user input.
So some of you might be asking why I never you scanned next.
And the reason is, as long as you can avoid this trap when it happens, you never really need to use
scan.
Next I like next line because it picks up the entire line.
And I find that to be more fitting when you're picking up text.
In any case, be careful not to fall into the scanner trap.
I left this table for you in the next cheat sheet as well, so take some time to process it.
And now finally, the client needs to have a good credit score to buy a car.
So we're going to ask them.
What is your credit score, and that's usually a whole number, so I'm going to pick up the credit score
using scan next at.
Now, a user can only buy a car if they have insurance and a license and a good credit score.
A good credit score tends to be higher than 660, but I hope what I just said made you think of the
end operator.
So in our code, we're going to check if insurance equals yes.
And if licence equals yes.
And if credit score is higher than 660.
We're going to print.
Sold.
Pleasure doing business with you.
We're sorry you're not eligible.
And that's really it.
Let's run our code.
We're going to choose option A 20000.
Do I have insurance?
Yes, a license?
Yes.
My credit score, let's call it seven hundred sold.
Pleasure doing business with you in the airport.
Looks very nice.
There's just one thing I want to insert is just a line of space right before asking what is your credit
score?
I'm going to rerun my code.
Seven hundred and perfect, it tells me a car, the output looks really nice.
Hope I didn't lose you.
Let's recap first.
And if statement checks, if the budget is greater than 10000, if the user enters a budget of less
than 10000.
The condition is false.
And Elsa runs.
The condition is true if the user enters a budget above ten thousand, in that case, the first if statement
runs.
Inside the statement, the code picks up three values to strong values and an innate value, then a
second, if statement checks for insurance, a license and a credit score above 660, since all the
comparisons are true.
The entire condition is true.
And Java sells them a car.
Now, try entering values that would cause one of the comparisons to be false and see what happens,
play around with the code.
In this lesson, you added the logic for buying a car, if the user chooses option, the program will
check if the client can afford it.
The client has insurance, the client has a license, and if the client has a good credit score.
In this leaves us with a very nice aput.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.