Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fundamentals of Software Development ISlide 1 Recap: Key ideas in WordGames ClassClass –versus instances –Defining –use of fields –Constructors E.g., to.

Similar presentations


Presentation on theme: "Fundamentals of Software Development ISlide 1 Recap: Key ideas in WordGames ClassClass –versus instances –Defining –use of fields –Constructors E.g., to."— Presentation transcript:

1 Fundamentals of Software Development ISlide 1 Recap: Key ideas in WordGames ClassClass –versus instances –Defining –use of fields –Constructors E.g., to initialize fieldsE.g., to initialize fields Extending a class versus implementing an interfaceExtending a class versus implementing an interface Methods, parameters and local variablesMethods, parameters and local variables We will review these ideas in the next several slides Blocks and scopeBlocks and scope Declaring variablesDeclaring variables ExpressionsExpressions StatementsStatements –Assignment –Conditionals –Blocks –Loops (later)

2 Fundamentals of Software Development ISlide 2 Declaring variables We use names (also called variables) to refer to things:We use names (also called variables) to refer to things: –myCheckBox homeURL mobyDick Use the names to ask objects to do things:Use the names to ask objects to do things: –myCheckBox.displayCheck() Every name has a type that must be declared:Every name has a type that must be declared: –CheckBox myCheckBox;Book mobyDick; –double temperature;int weight; Exercise: Declare a variable appropriate for: Storing a person’s age Indicating whether or not Sonia passed her test Referring to a JButton Storing an approximation to PI int age; boolean passed; JButton button1; double pi; Questions?

3 Fundamentals of Software Development ISlide 3 Expressions Every expression has aEvery expression has a –type and a value Simple expressionsSimple expressions –Names (variables) and literals are Expressions can be combined by using operators like:Expressions can be combined by using operators like: –Arithmetic operators: + – * / % –Comparison operators: >= == != –Logical operators: && || ! if ( (temperature > 101) && (bloodPressure > 140) ) { dosage = dosage + 30; } Exercise: Fill in the blanks. In the example below, there are: ___ literals ___ comparison expressions ___ boolean expressions ___ arithmetic expressions ___ assignment expressions 3 2 1 1 1 Questions?

4 Fundamentals of Software Development ISlide 4 Assignment statements Exercises: Given the declarations to the right, write statements that:Exercises: Given the declarations to the right, write statements that: –Give age the value 12 age = 12; –Make button1 refer to the same JButton as button2 button1 = button2; –Make button3 refer to a new JButton button3 = new JButton(); –Increment weight by 10 weight = weight + 10; or equivalently: weight += 10; –Sets force appropriately (given mass and acceleration) force = mass * acceleration; –Makes henry wiggle henry.wiggle(); assuming the method’s name is wiggle int age; JButton button1; JButton button2; JButton button3; int weight; double force; double mass; double acceleration; Worm henry; Questions?

5 Fundamentals of Software Development ISlide 5 Conditional statements The statements executed depend on a conditionThe statements executed depend on a condition –The condition is evaluated left- to-right and may be short- circuited if (x < y) { min = x; min = x; } else { min = y; min = y;} if (naomi.winsRace()) { ++ count; ++ count;} if ( (fido != null) && (fido.isAlive() ) { fido.bark(); fido.bark();} Note the indentation and curly- brace style in multiple cases if (score >= 90) { grade = ’A’; } else if (score >= 80) { grade = ’B’; } else { grade = ’C’; } Questions?

6 Fundamentals of Software Development ISlide 6 Blocks Use curly-braces to enclose blocks of codeUse curly-braces to enclose blocks of code –Note the code convention for where to place the curly braces if (x < y) { min = x; min = x; max = y; max = y; } else { min = y; min = y; max = x; max = x;} Questions?


Download ppt "Fundamentals of Software Development ISlide 1 Recap: Key ideas in WordGames ClassClass –versus instances –Defining –use of fields –Constructors E.g., to."

Similar presentations


Ads by Google