An example soda deal soft drinks are sold in cans and

Info icon This preview shows pages 2–5. Sign up to view the full content.

An Example: Soda Deal - Soft drinks are sold in cans and bottles. A store offers a six-pack of 12- ounce cans for the same price as a two-liter bottle. Which should you buy? (12 fluid ounces equal approcimately 0.355 liters.) - List of variables: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --------------------------------------------------------------------------- 10/11/2017 Midterm Topics - Making and Using Variables - Using Math Operators to Construct Complex Expressions - Asking the User for Input and Displaying Output Text - Control Statements - If Statements - Repeat Statements - Moving and Drawing with Sprites - Reading, Understanding, Planning, and Creating Your Own Algorithms - Pseudocode - Events - When Flag Clicked - Capturing Mouse and Keyboard Events - Parallel Actions and Broadcast Messages - Making Your Own Blocks - Be familiar with commands in all palettes -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- 10/16/2017 - The "Boolean" type has two values: true and false. These variables are also literals. - It is not a numeric type, like int and double - You can't do arithmetic with true and false values, you can't promote them to numeric types - You can have boolean variable: boolean isRaing = false; - What makes the boolean type (and values) important is that we will use them to make decisions in our programs
Image of page 2

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

- We will be able to choose between executing one pieve of code or another - A boolean expression is an expression that evaluates to one of the values TRUE or FALSE - To do this we need new operators: Equal (==) Cant compare two strings Not Equal (!=) Cant compare two strings Less Than (<) Less Than or Equal (<=) Greater Than (>) Greater Than or Equal (>=) - In math -> 0<x<100 - In java -> 0<x&&x<100 <- Both sides must be true, Evaluates the first equation first. - 3 Logical Operators AND && OR || NOT ! - All three expect boolean expressions as operands. - The OR (||) operator will evaluate to true if the value on the left or the value on the right is true, otherwise it will evaluate to false. For Example, a<b || c<d will evaluate to true if a is less than b OR c is less than d. a b a&&b a||b T T T T T F F T F T F T F F F F - The NOT (!) operator will evaluate to true if the value on its right is false, or will evaluate to false if the value on its right is true/ - The precedence levels, with these new operators: HIGHEST: ! cast *,/,% +,- (including + for concatenation) <,>,<=,>= ==, != && LOWEST: || - IF STATEMENTS - The general form is: if (boolean expression) { code executed if the bool. expr. is true } else { code executed if the bool. expr. is false } code executed after one or the other completes -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- ----------------------------------- 10/18/2017 What is an Algorithm? - Repeatable set of specific intructions designed to solve a problem. - *printf* is like *print* and *println*, except it gives you the ability to control the format (appearance) of the values - The format string contains format specifiers, one for each expression. A format specifier begins with a %, followed by some optional modifiers, followed by a character that indicated the type b = boolean
Image of page 3
d = int f = double s = string n = newline - Printf format specifiers *General form: %flag width.precision conversion *Flag: - (left justify), +(incl + sign), 0 (zero pad) *Width: the number of character positions -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- ----------------------------------------------- Loops 10/24/2017 - A loop is one or more statements that are executed repeatedly.
Image of page 4

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern