
Title:
And Or Not  Intro to Java Programming

Description:

Many times, when you have complicated conditions, you want to combine them. For

example, maybe you want to do something if one condition is true, or another

one. In Java, there are three operators that you can use to combine conditions.

They look like this. The two ampersands are an and these two vertical bars are

on or. And the exclamation mark somewhat is a not. You might find it useful to

remember that the not equal operator that you've seen a few units ago also has

the exclamation mark. Let me show you a few examples for using these operators.

And once again, we'll be looking at flags where the visual appearance should

help you. Let's start with this maritime flag for the letter d. Here, I made a

sketch of this flag. When you're in the middle, the pixel should be blue. And

otherwise, it should be yellow. So how do we express when you're in the middle?

When the yvalue is greater than this level. And less than this level, that's

where our and comes in, then we're in the middle. This here is 1 5th of the

total height. So, we have two conditions, namely y is at least height over 5,

and the other condition is y is at most height times 4 over 5. Both conditions

have to be fufilled for us to be in the middle, so we use the and operator.

Here it is. Let's just try this out. Here is the condition that you just saw

with the and operator here. And in this case, we return blue. Otherwise, we

return yellow. In this case, I will make a square flag and here it is. So, the

and operator worked out for us. Because we wanted y to be at least here at

most, here. Both conditions had to be true for the blue color. Now, let's look

at another flag. I've sketched up the flag here. And the question is, when

should a pixel be blue. In this case, there are four conditions. The xvalue

should be at least width over third. That means it's over here. The xvalue

should be at most, width times two thirds. That makes it over here. The yvalue

should be the height over 3, and the yvalue should be at most the height times

two third. All those four conditions need to be fulfilled for a pixel to be

built. Now, it's your turn. You'll get to write a program that draws this flag

here with a bit of blue on the inside and white on the outside.