 Hi, as nobody has showed up for this question and answer session so far, it looks like it's time for a quick mini lecture. And I'm going to start with chapter two talking about variables and arithmetic operators. Let's save this as age one dot Java. Let me get the upper and lower case correct here. Which means this is going to have to be called age one. And the purpose of this program, given an age in years, calculate and print the approximate age and days. So knowing what we know now, what we know from chapter one, we can do it as something like this. For example, I can say system dot out dot print. Your age. And let's just make up an age here like 47 years is about. And then I'll system dot out dot print. And I'll put 47 times 365 system. Not print LN days old notice these are print and not print LN which mean they're going, which means they're going to appear on the same line. And then after days old we go to the next line. And here because it's not in quote marks it's going to evaluate 47 times 365. Let me move this out of the way here so they can see my controls. Let's compile. And there it works. There's something a bit dissatisfying about this first of all the fact that we had to split all this stuff up into three separate statements. And second is well what happens when someone has a birthday and they become 48 and we have to rewrite this line and this line also. So let's attack these problems one after another. The first way that we're going to put these into one statements to three separate statements is by using the plus sign plus sign will not only add numbers it will add strings. Oh, something. I'm sorry, something positive sharing. Yeah. We have no idea why that happened, but let's go back to this. Let me go back and recompile and rerun the program. And you can see that it's working grand. Now, we need to put this into one print statements to three. The way we're going to do is we're going to use the plus sign plus sign adds numbers but also add strings together. We're going to put 47 times 365 here in parentheses and I'll show you in a minute why. So we're going to get rid of this and we're going to indent here. And then we're going to add on the words days old. So now we have one print line statement that will print out these words. Then it will tack on 47 times 365. And then it'll tack on days old. So that and we get the exact same answer. Now there's something you need to know when you're using plus sign with strings and numbers. And to show this I'm going to go into J shell because it's a little bit easier to demonstrate it there. And adding numbers we're okay with 3.7 plus 4.2. When I add strings together attacks them together. So door plus bell is doorbell again. No surprises here. Now, question what happens if I say three plus seven plus cars. What's going to happen here. The answer is when I have operations of equal priority, they go from left to right. So it'll take three plus seven which is 10, and then it'll add on the string cars and I'll get 10 cars, and it will be converted to a string that's going to convert to string. Now the next question what happens if I say cars plus three plus seven. In that case what I'm going to get is cars 37. Why did that happen, because I started with a string. When I have a string and add a number, the number gets promoted to string that gave me cars three a string. The seven got promoted to a string and that gave me cars 37. If I wanted cars 10, I would have to say cars plus three plus seven in parentheses because parentheses have the highest priority, and that means the addition of three plus seven, an integer addition will happen first. I want so be careful when you're using plus sign. We're going to learn about formatted printing at some point in the semester, and that's going to avoid having to use all this plus sign business. Okay, we've solved one problem. We've solved the problem of having three separate print statements to put a sentence together we can use plus sign to do that. Now our next problem and what the chapter two is really on about is variables we're going to use something called a variable that will let us make it easier to change the program when the person's age changes. And let's say this is age two still going to do the same thing. And this time we're going to create a variable. It's going to be an integer. This name will be years and we'll assign it the value 47. This is very important what I've just done here is called an assignment statement. Whenever you create a variable for the very first time and use it you must say what kind of value it holds. What kind of various values can you have, and these are called data types by the way, int, which is integers, whole numbers. There's double, which is numbers with decimal points, like 3.7 12.2 negative 4.8. Some of the other data types that we will be talking about this semester is string, which is characters within double quotes. There is the char data type which is a single character within single quotes, and then a very important one which we'll talk about later called Boolean. And that is a true or false value. We're going to be having some decisions that we're going to make in our programs. For example, if you give me a negative number I might want to print an error message, or if you give me a number that's less than 18, I have to tell you that you can't vote yet. Or if you give me a number that's greater than 65 I can tell you you're able to retire, making these decisions that have yes or no questions. Are you under 18. Are you over 65 dancers are yes or no or in Java terms, true and false. And we're going to be using these quite a bit when we get to the chapter on selection statements, which is which chapter, chapter five. So we get to chapter five we're going to be talking about that in grand and glorious detail. Let me save this here. And again I will upload this stuff when we're done. Now the way we read this again let's talk about this in years is 47. I'm going to be sort of building a diagram as I do this and this is always sort of difficult for me. I'll give it my best shot here. Let's put it into a monospace font. Looks better. Here's our variable it's called years, and you can think of a variable as a container. So we have a little box like an envelope or something. And there's a label on that envelope. So we're going to start over you can think of it as a mailbox. We know that it will hold an integer we have to get we have to say that the first time we declare it. We always start on the right hand side of the assignment operator, this symbol here. We work out what's on the right hand side of that symbol, and that's a 47. And that is what is going to be assigned into this container into this mailbox. The next thing I want to do is I am going to put in another variable it's going to be an integer, and it's going to be called days. And I'm going to make that the same as years times 365. So I misspoke there. I'm going to assign it the value years times 365. Whenever you see this symbol here, you're tempted think oh that's just like an algebra that needs those things are equal. It does not and the book makes a big point of it and I'm going to make a big point of it. This is the assignment operator. It means take whatever's on the right hand side and put it into the variable on the left hand side. So when I say something let's see something like this years becomes 47. There are many different ways I can read it years becomes 47 that's my favorite years is assigned 47. Or years gets the value 47 or years is set to 47. All of those things are great ways to read that. But no, I never read it that way because that makes me think I'm dealing with algebra, and I am not. In fact, I'm going to erase that so there doesn't show up inside of our file when I uploaded. So I'm going to take whatever's in years right now envelopes pop that in here. So what's happening here is, because this is my first declaration. I'm going to create a mailbox so to speak and I'm going to call it days. And now to figure out what goes into it I look at the right hand side first years has 47 in it. That means I'm going to take 47 times 365. And I think that came up to 17155. Hold on, let me get my calculator out here. My calculator calculator calculator or seven times 365 is 1755. Yes, thank you. And that number goes into days. This is what we call our memory diagram. This is what Java's memory looks like after we do these two statements. Now, I'm going to say split this up a little bit more. And then I don't have to say 47 times 365. I have it in this variable called days. And now we can compile it and run it and your age of 47 years is about that many days old. Hey, that's looking pretty good. And now when whoever this 47 year old person is has a birthday and they become 48. We have to change only one line and everything else will work just fine. So this is a quick introduction to the variables. Oh, there is something I definitely want to do here. Let's say I open up my template file again. Let's call this a purchase dot Java. So, given a price of an object of an item. We want to calculate 7.5% sales tax and add that to the price to get the total price. So that's that that's the purpose of this program. So prices can have decimal points. That means we're going to have to say double. And let's say we're going to make it. Fair. Let's make a one that we can figure out by hand so that we don't have to do a lot of extra calculation. I don't need to put the point zero zero here. I could just say 20.0, or I could even say 20 is an integer and it would be promoted to a double. In the interest of being very explicit about this. And again, this says, okay, I'm going to have the value 20.0 and it's going to go into a variable called price, which happens to be a double. Now what's my tax, my tax is going to be my price times 0.075. Oh, let's do something different here. There's something actually want to do a seven and a half. No, that's not going to work. Never mind. 7.5 divided by 100. And then our total will be the original price plus the tax. So now I can say system. Your item cost price. And then with tax of plus tax that comes out to plus total. There we go. And again, I'm using the same sort of thing that's happening here. And run it. Now you'll notice that unfortunately when Java displays it shows only one digit after the decimal point. So that is a little bit ugly. And we're going to have to learn something called formatting in order to fix that but I'm not going to go into that today. What I do want to talk about is something called constants though, this seven and a half divided by 100. So that's sort of an arbitrary number. What we would like to do is we would like to make some sort of a variable to hold our tax rate. Now, this is going to be a constant, which means it's never going to change. Whenever I have some of this and once I said it, I never want to change it. I'm going to call it a final. It's going to be double. And again, by convention, which means unwritten rule that everybody follows, we're going to name our constants in all uppercase, because I have two words, I'm going to separate them by underscores. I think I may have, I don't know if I've talked about this before so I better talk about this now. So what happens if we have multi word variable names. For example, let's say I want something. Oh, I don't like a double net weight. I can't put a space in there. That's not going to work. So the way to solve this and some languages solve it by having an underscore Python and by the way is one of those languages where if I wanted net weight which as one variable name I'd use an underscore to separate the words. That's not how Java prefers to do it. Again, by convention, we do it this way. We start with a lowercase letter, and then any subsequent words will start with an uppercase letter. So for example, I could have integer age in years. Choosing variable names. Make sure they're meaningful. For example, if I had to say double N and int a what in the world are those. Well that doesn't. It could be anything right. So these are too short. Don't go overboard. I mean we don't want to say net weight of package. Or sending. And integer age in years as of last birthday. We want something that's meaningful. But not too short, not too long. This is how we handle our multi word variable names. However, when I have a final a constant. So I can't do something like final double tax rate, which one is calculated capitalized. In this case, I'll have to put an underscore between words. And that's why this became tax rate. And I'm going to set it to 7.5 divided by 100. And now I can say price times tax rate. And that makes things a lot more readable. And also if I need to use the tax rate in several different calculations, I don't have to have 7.5, 7.5, 7.5 all over the place. Instead I can have it once. And if the tax rate goes up or down to 7.75 out of 100, then I change it in one place. And every place else that I use it is going to get the benefits of that. And that price, by the way, is something like $12.95. Let's compile that. And you'll notice I get some weird answer there. This is why we're going to need to learn about formatting, but we're not going to learn about that today. Maybe on my next lecture, I will do that. Now, one other thing that I need to tell you about this very, very important. Let's say I have something like this. Integer X becomes, and because I'm using X here because it's just a generic number. I'm not using it to symbolize anything except I just need a number. Well, okay. Number, why not? Let's call it number becomes 35. Number here and it's a 35. Now, this is what blows a lot of people's mind. So there's a person I work with at LinkedIn Learning. And also I used to work with him when he was a book editor. And he said he was put off from programming for many, many years because when he first learned to program, he saw a statement like this. He said, that's ridiculous. A number can't be equal to itself plus one. This doesn't make any sense. Programming is stupid. I'm not going to do it anymore. Now he finally tried again a couple of years later and said, okay, now I get it. Remember this symbol here is not algebra. In algebra, this is utterly meaningless. But in Java, it's totally meaningful. We're going to take the right hand side of the assignment first. What's in number right now? 35. 35 plus one works out to 36. The right hand side works out to 36 and we're going to assign it back into number, which means this number goes away and 36 replaces it. So this is called reassignment. I'm taking a variable. I'm updating its value and putting it back into the same variable. This is totally 100% legal in Java. Let's prove that in fact. Let's open up our template. Save this as reassignment.java. And the purpose of the program is show that you can reassign a variable using the assignment operator, which is this two parallel lines operator here, which is not the same as what that symbol means in algebra. Excuse me a moment here. I'm going to put my phone in another room so it doesn't bother me anymore here. Let me pause my recording from it. Okay, and we're going to have to call this reassignment. And here we'll have an integer number, which is assigned. I think I had 35 there. And then I'm going to say number becomes number plus one. And then we'll system.out.print line and we'll say the number is now. Let's number. And we'll put a period at the end of the sentence just because it makes me feel better. Let's compile that. And sure enough, the number is now 36. And this is called reassigning a variable. And the last thing I want to talk about today is more about arithmetic operators and a couple of operas that you may never have heard of, but one opera that you may never have heard of before. And integers versus floating point and to talk about this, I'm going to go back into J shell. I'm going to be typing some arithmetic expressions. Let's say three times 4.5. When we multiply an integer by a float, we get a float, a double. Now here's a question for you, what happens if I say 75 divided by 100, what do you think I'm going to get. Again, the easiest way to find out is to try it and see what happens. And we get zero. How did that happen. The answer is we are dividing an integer by an integer and when you divide integers by integer, the result is always, always, always an integer. For example, let's say I have something like 15 divided by four. That's three. The decimal part gets thrown away. This is very important to understand. It does not get rounded up by the way. I wanted to find out and keep my decimal points. At least one of them would have to be a floating point double. Now I get 3.75 notice it's not rounding it up to four. It's cutting off the decimal completely. If I say 15 divided by 4.0 because at least one of the operands is a float. So is the result. If I say 15.0 divided by integer four. I still get 3.75. It's only this one here that you got to be careful about. Now let's say I have something like Oh, I don't know 37 divided by five. And in fact, if we were doing this in arithmetic class, we would have something like if you remember this from your grade school days, you would have 37. Do I have the special character? Where is it here? There should be a division sign here someplace. If I can't find it right away, I'm going to just divided by seven is five with a remainder of two. I don't know if you ever did that in grade school, but that's one of the ways that we were taught that. I'm sorry, I was dividing by five there. It's seven with a remainder of two. So question is how do I get that remainder? I know how to get the quotient. When I say 37 divided by five, I get my quotient turns out this operator with a percent sign means give me the remainder after division. So 37 mod five gives me two. And I'll put that in the notes here for today. So percent sign is the modulo or mod operator, sometimes called remainder also. It gives the result of the remainder after division of its operands. That means 37 mod five is two. And if I do something like, oh, let's say 52 mod four, that gives me zero because there's nothing left over 52 is evenly divisible by four. And you may think, oh, I'm never going to need this operator. That's pretty sort of sort of silly one. But trust me, it comes up in a lot of calculations and it's an incredibly useful operator. So as you go through your programming career, you will see it pop up over and over again. You heard it here first. Let's see what other operations do I have? Oh, there is no such thing as exponentiation. If I try to say two to the third power. Java will complain. If I try doing it with up arrow, which is something that you can do in other languages, Java will do something, but it won't be what you want. And don't ask me to explain why that is. It's a long and complicated and very ugly story. So question is, gee, how do I raise something to a power? And the answer is just like we need a method for doing printing system.out.println. We need a method for doing numbers to a power. And we're going to learn about this a little bit later, but I'm just giving you a preview of coming attractions. Math.pow23 raises two to the third power. We can also do math.pow2 to the one-half power to get the square root. How cool is that? So again, we have our normal arithmetic operators, and I'm going to put them in the notes here. And I'm also going to put them in order of priority. Parentheses are our highest priority. After that comes multiplication, division, and mod. After that becomes plus and minus. That means if I say three plus four times five. Am I going to get 35? No. Because multiplication is more important than addition, which means that we're going to get 20. And then I'm going to add three and that will give me 23. And if you don't believe me, maybe you'll believe Java. If I did want 35 out of this, I'd have to say, okay, I want the addition to happen first and I'll force that to happen by using parentheses. Now I'll get 35. And in fact, three plus four times five gives me 35. In case you have not noticed in all of these arithmetic expressions, I am putting blanks around all my operators, even the assignment operator. I'm also putting a blanks around that. And the reason I do that is because it makes the code a lot more readable. If we have complicated expressions, the more complicated an arithmetic computation gets, the more you're going to need the spaces to make it readable. Take my word on that one. So what have we learned about so far today? We have learned about variables that they have to have a data type. And we assign them using the assignment operator, whatever's on the right hand side of the assignment goes into the variable on the left hand side. And double, which we're going to be using for values that might have a decimal point. And we've learned our arithmetic operators, plus minus times divide and mod. They're about, by the way, a lot of other operators that we're going to be talking about later on. But for right now, I'm going to give you this and we'll add to that. I think there's something in the book at the back of the book where they have a list of all the operators and all their priorities. And you can look, or you can find that online at your leisure. Okay, this should do it for today's mini lecture. So really slow start, but once I got going, I think I knew where I was headed. What's we're going to do tomorrow's mini lecture? Well, let's give it a thought here. There's only one thing that I don't like about this program. And that is, if I send this to my cousin George in Pennsylvania. And I say, Hey, George, take a look at this. It figures out your age and days. And they'll say, well, that's nice, but I'm not 48 years old. And I don't know how to write Java. So how do I do it for me? Because I'm 52. And so gee, wouldn't it be nice if we could have a program that would ask the user, Hey, how old are you? And they could type in 52 for my cousin George or 19 for some student at Evergreen Valley College. And that would do the calculation based on their input instead of the user having to know Java to change the 48 here to 52 to make my cousin George happy. And that's what we're going to find out about tomorrow. But if you absolutely cannot wait for tomorrow, then my strong suggestion is that you look at sections 3.1 and 3.2. By the way, here, they're talking about the remainder operator. Okay, they get to it in chapter 3. Wow, I went a little bit ahead, which is okay. And we're going to talk about typecasts. The other thing I forgot to talk about is error messages. There's that's my first error for the day isn't forgetting about errors. That happens tomorrow. You have enough information to keep you happy. So see you all tomorrow.