Alice in real life with Java

0
0
2383 days ago, 822 views
PowerPoint PPT Presentation
Alice in real life with Java. 2. Goals. Utilize the Boolean sort and its fundamental operationsUse the if explanation to perform a few proclamations while skipping othersUse the for keeping in mind articulations to perform (other) proclamations more than onceUse Boolean variables and capacities to control if keeping in mind statementsUse the wait()message to briefly suspend program execution.

Presentation Transcript

Slide 1

Alice in real life with Java Chapter 4 Flow Control

Slide 2

Objectives Use the Boolean sort and its fundamental operations Use the if proclamation to play out a few articulations while skipping others Use the for and keeping in mind that announcements to perform (other) explanations more than once Use Boolean factors and capacities to control if and keeping in mind that announcements Use the hold up() message to incidentally suspend program execution Alice in real life with Java

Slide 3

Flow Control Flow: arrangement of ventures for playing out a client story Flow control explanation: structure for overseeing stream Flow control articulations utilized as a part of past parts doInOrder : produces a successive execution doTogether : produces a parallel execution Control proclamations presented in the present section if : coordinates program stream along one of two ways for : coordinates stream into a settled number of circles while : coordinates stream into a discretionary number of circles Alice in real life with Java

Slide 4

Flow Control (proceeded with) Alice in real life with Java

Slide 5

The Boolean Type An essential Alice sort used to characterize Boolean factors A Boolean variable holds an estimation of genuine or false Other essential sorts: Number and Object Condition (Boolean expression) Produces an estimation of genuine or false Basis for basic leadership in projects Alice in real life with Java

Slide 6

Boolean Functions Return an estimation of genuine or false Can go about as a condition in an if or while articulation Many allude to a protest's bouncing box Example: obj .isBehind( obj2 ) genuine , if obj 's position is past obj2 's raise edge false , generally Alice in real life with Java

Slide 7

Boolean Variables Used to store an estimation of genuine or false Can be utilized as a part of condition for if or while articulation How to make a Boolean variable Click make new factor (or parameter ) catch Specify Boolean as factor (or parameter) sort Alice in real life with Java

Slide 8

Relational Operators Produce genuine or false values Six social administrators: == , != , < , <= , > , >= Located in capacities sheet of world 's subtle elements region Most regularly used to look at Number qualities Example: hoursWorked > 40 hoursWorked is a Number variable genuine when over 40 hours have been worked Alice in real life with Java

Slide 9

Relational Operators (proceeded with) Alice in real life with Java

Slide 10

Boolean Operators Used to alter or join social operations Three Boolean administrators: AND , OR , NOT Located in capacities sheet of world 's points of interest territory Example: age > 12 && age < 20 age is a Number variable Teen number contrasted with condition returns genuine Alice in real life with Java

Slide 11

Boolean Operators (proceeded with) Alice in real life with Java

Slide 12

Introducing Selective Flow Control Summary of a scene with a princess and a mythical serpent Princess meets a quiet monster and makes inquiries Dragon shakes its make a beeline for react yes or no Objective: compose a shakeHead() technique Requirements for shakeHead() Parameter: yesOrNo, a String If yesOrNo == "yes", monster shakes head here and there If yesOrNo == "no", mythical serpent shakes head sideways Use an if explanation to create contingent conduct The if control structure is at base of altering region Alice in real life with Java

Slide 13

Introducing Selective Flow Control (proceeded with) Alice in real life with Java

Slide 14

if Statement Mechanics Value of a condition decides bearing of stream Structure of an if proclamation: if ( Condition ) { Statements 1 } else { Statements 2 } if explanation conduct is likewise called particular stream If Condition is genuine , Statements 1 are chosen If Condition is false , Statements 2 are chosen Alice in real life with Java

Slide 15

if Statement Mechanics (proceeded with) Alice in real life with Java

Slide 16

Building if Statement Conditions Coding the state of the if explanation Click on the yesOrNo parameter Drag parameter into the altering zone Drop the parameter onto the condition's placeholder Choose other and afterward sort " yes" Overview for coding the rest of shakeHead() Add headMovement variable for measure of turn Add turn() explanations for all over movement Add turn() articulations for sideways movement Alice in real life with Java

Slide 17

Building if Statement Conditions (proceeded with) Alice in real life with Java

Slide 18

Building if Statement Conditions (kept) Building a scene strategy that utilizations shakeHead() princess welcomes mythical serpent utilizing a say() message princess asks four inquiries shakeHead() is brought because of each question Click the Play catch to test the program Alice in real life with Java

Slide 19

Building if Statement Conditions (proceeded with) Alice in real life with Java

Slide 20

Building if Statement Conditions (proceeded with) Alice in real life with Java

Slide 21

The hold up() Statement Pauses a program for determined number of seconds Form of hold up() proclamation: wait(numSecs); Use of hold up() scene with mythical beast and princess Inserted between princess' first and second lines Alice in real life with Java

Slide 22

Validating Parameter Values if explanation can be utilized to watch set of proclamations Flow enters just if parameter qualities are substantial Example: check remove esteem go to hop() Check for positive incentive with condition separate > 0 Check hop length with separation < MAX_DISTANCE Combine two conditions with the AND ( && ) administrator separate > 0 && remove <= MAX_DISTANCE How to consolidate approving rationale utilizing if structures Place unique hop() rationale onto genuine way (external if ) Place approving rationale in the false way (settled if ) Alice in real life with Java

Slide 23

Validating Parameter Values (proceeded with) Alice in real life with Java

Slide 24

Validating Parameter Values (proceeded with) Alice in real life with Java

Slide 25

Validating Parameter Values (proceeded with) Alice in real life with Java

Slide 26

Introducing Repetition Refer to flapWings() strategy from Figure 2-16 Enhancement: use for circle to fold wings numTimes Overview for actualizing the upgrade Open the flapWings() strategy Adjust the span values for the wing developments Drag circle control to the highest point of the strategy and drop Select numTimes for number of emphasess Drag the doInOrder articulation into the for articulation Alice in real life with Java

Slide 27

Introducing Repetition (proceeded with) Alice in real life with Java

Slide 28

Introducing Repetition (proceeded with) Alice in real life with Java

Slide 29

Mechanics of the for Statement Repeat articulation execution a settled number of times Example: pass 3 to flapWings() for 3 folds Structure of the basic for proclamation for(int file = 0;index < limit;index++){ Statements } The for proclamation is otherwise called an including circle First articulation in ( ) instates the file Second proclamation in ( ) checks list against breaking point Third proclamation in ( ) increases the file Alice in real life with Java

Slide 30

Mechanics of the for Statement (proceeded with) Alice in real life with Java

Slide 31

Mechanics of the for Statement (proceeded) To test a for circle, follow the conduct with qualities Statements are executed while file < numTimes Example: send flapWings(3) to the mythical serpent question Simple rendition of for gives you a chance as far as possible esteem Purpose of show confused adaptation catch Change beginning estimation of file or potentially refresh to record Example: change refresh to index+=2 Note: neither form of for permits you to include down Alice Action with Java

Slide 32

Mechanics of the for Statement (proceeded with) Alice in real life with Java

Slide 33

Mechanics of the for Statement (proceeded with) Alice in real life with Java

Slide 34

Nested Loops Three shots improving Scene 1 of mythical serpent activity Dragon flies toward a mansion in the wide open As monster nears manor, it circles the tower three circumstances Dragon then dives and grounds on the drawbridge One approach to fabricate the main shot Go to go into the Add Objects window Position the monster over the château's drawbridge Move mythical serpent up until it is even with the palace's tower Drop a sham and afterward drag the mythical serpent off-screen Use setPointOfView() to legitimately position winged serpent Alice in real life with Java

Slide 35

Nested Loops (proceeded with) One approach to manufacture the second shot Use for explanation to control other flying explanations Understanding the mechanics of Shot 2 Outer for controls internal (settled) for in flapWings() AsSeenBy() trait spins mythical serpent around stronghold Increase term of turn() to synchronize moves Set style to smooth the liveliness The third shot is examined in Section 4.4 Alice in real life with Java

Slide 36

Nested Loops (proceeded with) Alice in real life with Java

Slide 37

The while Statement confine an incentive in for circle must be set to a settled esteem Circumstance when the for circle is fitting Statements are to be executed a settled number of times Problem: circling when the farthest point esteem is obscure Solution: utilize a while explanation Alice in real life with Java

Slide 38

Introducing the while Statement Strategy for building third shot of monster activity Repeatedly have mythical beast fold its wings Move mythical serpent descending while it is above drawbridge Overview for building the third shot Place doTogether articulation in doInOrder articulation Use setPointOfView() to draw camera nearer Send flappingWings() message to the monster Drag the while articulation to the altering zone Drop the while proclamation beneath doInOrder Insert placeholder esteem into the while condition Alice in real life with Java

Slide 39

Introducing the while Statement (proceeded with) Alice in real life with Java

Slide 40

Introducing the while Statement (kept) Building the third shot (proceeded with) Drag mythical serpent's isAbove() over condition and drop Add castle.bridge argu

SPONSORS