DOC PREVIEW
UNF COP 2551 - Lecture Notes

This preview shows page 1-2-3-4-30-31-32-33-34-62-63-64-65 out of 65 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Chapter 2OutlineExpressionsDivision and RemainderArithmetic Expressions - continuedOperator PrecedenceSlide 7Expression TreesAssignment RevisitedSlide 10Increment and DecrementSlide 12Assignment OperatorsSlide 14Slide 15Slide 16Slide 17 Introduction to ObjectsIntroduction to ObjectsObjects and ClassesInheritanceUsing ObjectsThe print MethodAbstraction (continued)Slide 25Interactive Input (the ‘Return…’) BufferedReader Class; and its methods p. 753-754Prelude to Wrapper ClassesWrapper ClassesSlide 29Continuing…Example. (Includes Javadoc info.)Snippets from My ProgramSlide 33Slide 34Formatting Output (see Chap 3)More…Stated a little differently…Slide 37More on Formatting OutputSlide 39Slide 40Data ConversionSlide 42Assignment ConversionSlide 44CastingSlide 46Introduction to GraphicsCoordinate SystemsRepresenting ColorThe Color ClassSlide 51AppletsSlide 53Slide 54Slide 55Slide 56The HTML applet TagSlide 58Drawing ShapesDrawing a LineDrawing a RectangleDrawing an OvalSlide 63Slide 64SummaryChapter 2Data and ExpressionsPart Two© 2004 Pearson Addison-Wesley. All rights reserved 2-2OutlineCharacter StringsVariables and AssignmentPrimitive Data TypesExpressionsIntro to ObjectsInteractive ProgramsData ConversionGraphicsAppletsDrawing Shapes© 2004 Pearson Addison-Wesley. All rights reserved 2-3Expressions•An expression is a combination of one or more operators and operands•Arithmetic expressions compute numeric results and make use of the arithmetic operators:Addition +Subtraction -Multiplication *Division /Remainder %•If either or both operands used by an arithmetic operator are floating point, then the result is a floating point© 2004 Pearson Addison-Wesley. All rights reserved 2-4Division and Remainder•If both operands to the division operator (/) are integers, the result is an integer (the fractional part is discarded)•The remainder operator (%) returns the remainder after dividing the second operand into the first14 / 3 equals8 / 12 equals4014 % 3 equals8 % 12 equals28© 2004 Pearson Addison-Wesley. All rights reserved 2-5Arithmetic Expressions - continued•If operands are mixed, results are ‘promoted.’ 4.5 + 2 = 6.5 (double)Sometimes called “widened.”© 2004 Pearson Addison-Wesley. All rights reserved 2-6Operator Precedence•Operators can be combined into complex expressionsresult = total + count / max - offset;•Operators have a well-defined precedence which determines the order in which they are evaluated•Multiplication, division, and remainder are evaluated prior to addition, subtraction, and string concatenation•Arithmetic operators with the same precedence are evaluated from left to right, but parentheses can be used to force the evaluation order© 2004 Pearson Addison-Wesley. All rights reserved 2-7Operator Precedence•What is the order of evaluation in the following expressions?a + b + c + d + e1 432a + b * c - d / e3 241a / (b + c) - d % e2 341a / (b * (c + (d - e)))4 123© 2004 Pearson Addison-Wesley. All rights reserved 2-8Expression Trees•The evaluation of a particular expression can be shown using an expression tree•The operators lower in the tree have higher precedence for that expressiona + (b – c) / da+/- db c© 2004 Pearson Addison-Wesley. All rights reserved 2-9Assignment Revisited•The assignment operator has a lower precedence than the arithmetic operatorsFirst the expression on the right handside of the = operator is evaluatedThen the result is stored in thevariable on the left hand sideanswer = sum / 4 + MAX * lowest;14 3 2Then the result is stored in the variable on the left hand sideNOTE: the ‘assignment operator (again) IS an operator – (merelyhas lower precedence than arithmetic operators….)© 2004 Pearson Addison-Wesley. All rights reserved 2-10Assignment Revisited•The right and left hand sides of an assignment statement can contain the same variableFirst, one is added to theoriginal value of countThen the result is stored back into count(overwriting the original value)count = count + 1;KNOW THE OPERATOR PRECEDENCE TABLE ON PAGE 81. It will grow significantly!© 2004 Pearson Addison-Wesley. All rights reserved 2-11Increment and Decrement•The increment and decrement operators use only one operand•The increment operator (++) adds one to its operand•The decrement operator (--) subtracts one from its operand•The statementcount++;is functionally equivalent tocount = count + 1;© 2004 Pearson Addison-Wesley. All rights reserved 2-12Increment and Decrement•The increment and decrement operators can be applied in postfix form:count++•or prefix form:++count•When used as part of a larger expression, the two forms can have different effects•Because of their subtleties, the increment and decrement operators should be used with care© 2004 Pearson Addison-Wesley. All rights reserved 2-13Assignment Operators•Often we perform an operation on a variable, and then store the result back into that variable•Java provides assignment operators to simplify that process•For example, the statementnum += count;is equivalent tonum = num + count;© 2004 Pearson Addison-Wesley. All rights reserved 2-14Assignment Operators•There are many assignment operators in Java, including the following:Operator+=-=*=/=%=Examplex += yx -= yx *= yx /= yx %= yEquivalent Tox = x + yx = x - yx = x * yx = x / yx = x % y© 2004 Pearson Addison-Wesley. All rights reserved 2-15Assignment Operators•The right hand side of an assignment operator can be a complex expression•The entire right-hand expression is evaluated first, then the result is combined with the original variable•Thereforeresult /= (total-MIN) % num;is equivalent toresult = result / ((total-MIN) % num);© 2004 Pearson Addison-Wesley. All rights reserved 2-16Assignment Operators•The behavior of some assignment operators depends on the types of the operands•If the operands to the += operator are strings, the assignment operator performs string concatenation•The behavior of an assignment operator (+=) is always consistent with the behavior of the corresponding operator (+)© 2004 Pearson Addison-Wesley. All rights reserved 2-17OutlineCharacter StringsVariables and AssignmentPrimitive Data TypesExpressionsIntro to ObjectsInteractive ProgramsData ConversionGraphicsAppletsDrawing Shapes© 2004 Pearson Addison-Wesley. All rights reserved 2-18 Introduction to Objects•An object represents something with which we can interact in a


View Full Document

UNF COP 2551 - Lecture Notes

Download Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?