Advertisement
English transcript
Now that you've modified your first line of Java code,
lets see what else we can do.
We can actually do some math expressions.
And if you don't like that thought of math,
well the good news is that Android actually does the math for you.
You just have to come up with the problem.
Say you have two people and
each of those two people wants two cups of coffee.
Now this will display the total amount of coffee that you need to get them.
We run it on our device and then we hit Order and then we see four.
So you see how we can type in math expressions and
it will automatically solve it for us.
We can also do even harder math expressions like
things we wouldn't even want to calculate in our head.
For example, say there's a whole group of Android developers and
they're really thirsty.
Say they each want to drink three cups of coffee each,
because they're not morning people.
And then we also want to throw in some extra cups as well.
That's a lot of coffee.
Let's see how much that actually turns out to be.
You hit the Order button and it says 59.
Interesting.
I guess developers do write better code when they have a lot of
caffeine in them.
In a moment I'm going to have you type in your own math expressions here.
As a heads up, if you run into any errors, for example,
if you type a letter accidentally,
then you will see a red error show up on the right hand side here.
The error says it cannot resolve the symbol a because
a is not a valid number.
Here's another possible error if you accidentally type the multiplication
symbol multiple times you would get an error here.
In this case it would be more helpful to to hit undo and
then your code would work again.
As we mentioned in lesson one, you can try to read the error message first.
Sometimes, the error message doesn't exactly pinpoint the problem.
You can also compare it to working code.
We just showed you an example of a math expression that worked.
You can also try to hit undo to retrace your steps.
Or, you can always ask for help.
Okay, now it's your turn to try to come up with a really hard coffee order for
the device to try to calculate.
You can experiment with different math expressions.
Here's an example of one.
As you can see, you can use different symbols here or addition, subtraction,
multiplication and division.
These are what we call arithmetic operators.
If you ever need to refer to this later, you can alway search for
arithmetic operators java.
This page lists the summary of all the different operators in Java.
And here are the arithmetic operators listed.
If you want you can always learn about other operators as well.
For this quiz though, we are just going to focus on the arithmetic operators.
The reason why we call this an expression is because it's
a bunch of symbols and numbers that eventually evaluate to a single value.
And this expression is evaluated according to order of operations
which you might have learned in math class.
If there's anything in parentheses, it evaluates that first to be four.
And then it does the multiplication and division parts from left to right.
I don't actually know what this evaluates to, but
you can try it in your app.
Once you've become comfortable with trying different math expressions,
try this problem.
I want you to display the number of coffees that you would need
If there are 77 Android developers who drink two cups of coffee each and
then one straggler walks in late and needs a cup of coffee, too
lets see what else we can do.
We can actually do some math expressions.
And if you don't like that thought of math,
well the good news is that Android actually does the math for you.
You just have to come up with the problem.
Say you have two people and
each of those two people wants two cups of coffee.
Now this will display the total amount of coffee that you need to get them.
We run it on our device and then we hit Order and then we see four.
So you see how we can type in math expressions and
it will automatically solve it for us.
We can also do even harder math expressions like
things we wouldn't even want to calculate in our head.
For example, say there's a whole group of Android developers and
they're really thirsty.
Say they each want to drink three cups of coffee each,
because they're not morning people.
And then we also want to throw in some extra cups as well.
That's a lot of coffee.
Let's see how much that actually turns out to be.
You hit the Order button and it says 59.
Interesting.
I guess developers do write better code when they have a lot of
caffeine in them.
In a moment I'm going to have you type in your own math expressions here.
As a heads up, if you run into any errors, for example,
if you type a letter accidentally,
then you will see a red error show up on the right hand side here.
The error says it cannot resolve the symbol a because
a is not a valid number.
Here's another possible error if you accidentally type the multiplication
symbol multiple times you would get an error here.
In this case it would be more helpful to to hit undo and
then your code would work again.
As we mentioned in lesson one, you can try to read the error message first.
Sometimes, the error message doesn't exactly pinpoint the problem.
You can also compare it to working code.
We just showed you an example of a math expression that worked.
You can also try to hit undo to retrace your steps.
Or, you can always ask for help.
Okay, now it's your turn to try to come up with a really hard coffee order for
the device to try to calculate.
You can experiment with different math expressions.
Here's an example of one.
As you can see, you can use different symbols here or addition, subtraction,
multiplication and division.
These are what we call arithmetic operators.
If you ever need to refer to this later, you can alway search for
arithmetic operators java.
This page lists the summary of all the different operators in Java.
And here are the arithmetic operators listed.
If you want you can always learn about other operators as well.
For this quiz though, we are just going to focus on the arithmetic operators.
The reason why we call this an expression is because it's
a bunch of symbols and numbers that eventually evaluate to a single value.
And this expression is evaluated according to order of operations
which you might have learned in math class.
If there's anything in parentheses, it evaluates that first to be four.
And then it does the multiplication and division parts from left to right.
I don't actually know what this evaluates to, but
you can try it in your app.
Once you've become comfortable with trying different math expressions,
try this problem.
I want you to display the number of coffees that you would need
If there are 77 Android developers who drink two cups of coffee each and
then one straggler walks in late and needs a cup of coffee, too