Docsity

Review Sheet for Introduction to Programming in Java | CSIS 110, Study notes of Javascript programming

Toggle sidebar
bg1
CSIS 110 โ€“ Lecture 7
Quiz: Wednesday. Material in Chapters 1 and 2.
Read: Chapter 3, section 3.1 to 3.11.
Partner assignment sheets
Quiz Review โ€“ Go over review questions that I handed out last time.
Last Time
We looked at the NumberDisplay class:
- Abstraction and modularization
- boolean operations: &&, ||, and !
Review boolean operations. Give some example boolean expressions and ask students to
evaluate.
So, what would happen if we replaced the && operator with || in the setValue
method?
The accessor method getDisplayValue
This method also gets the value, but as a String instead of an int. What is it doing?
if ( value < 10 )
return โ€œ0โ€ + value;
else
return โ€œโ€ + value;
Whatโ€™s going on here?
- What does the expression โ€œ0โ€ + value do?
- What does the expression โ€œโ€ + value do?
- Statements after return statement?
- Whatโ€™s the purpose of this if statement?
Does this method work correctly in all cases? Does it make any assumptions? What if the
value of limit is 500?
The increment method
The increment method adds 1 to the value, but has to reset it to 0 if the limit is reached.
This method uses the modulo operator:
value = ( value + 1 ) % limit;
pf3

Partial preview of the text

Download Review Sheet for Introduction to Programming in Java | CSIS 110 and more Study notes Javascript programming in PDF only on Docsity!

CSIS 110 โ€“ Lecture 7

Quiz: Wednesday. Material in Chapters 1 and 2. Read: Chapter 3, section 3.1 to 3.11. Partner assignment sheets Quiz Review โ€“ Go over review questions that I handed out last time. Last Time We looked at the NumberDisplay class:

  • Abstraction and modularization
  • boolean operations: &&, ||, and! Review boolean operations. Give some example boolean expressions and ask students to evaluate. So, what would happen if we replaced the && operator with || in the setValue method? The accessor method getDisplayValue This method also gets the value, but as a String instead of an int. What is it doing? if ( value < 10 ) return โ€œ0โ€ + value; else return โ€œโ€ + value; Whatโ€™s going on here?
  • What does the expression โ€œ0โ€ + value do?
  • What does the expression โ€œโ€ + value do?
  • Statements after return statement?
  • Whatโ€™s the purpose of this if statement? Does this method work correctly in all cases? Does it make any assumptions? What if the value of limit is 500? The increment method The increment method adds 1 to the value, but has to reset it to 0 if the limit is reached. This method uses the modulo operator: value = ( value + 1 ) % limit;

The % operator calculates the remainder of integer division. [Give an example โ€“ divide 53 by 4 using longhand]. Then ask what is the remainder of 17 / 4. What is the value of these expressions? 5 % 2 10 % 3 4 % 7 5 % 5 What possible values could this expression produce: x % 5? So, what is the above statement doing?