RU beehive logo ITEC dept promo banner
ITEC 120
2012fall
dbraffitt
ibarland

homeinfolectslabsexamshws
tutor/PIsbreeze (snow day)
Object120 + its docsjava.lang docsjava.util docs

hw00
hw00
finger exercises

Due Date: Sep.03 (Mon.) in class.

Instructions:

  1. (learning style, 3pts) Take the Index of Learning Styles Questionnaire.
    What are your four scores? (e.g. “ACT 5, INT 2, …”. Be sure to include the name with each number; if you only write “5”, I can't tell if you mean “ACT 5” or “REF 5”.)
  2. (5pts) What do each of the following Java expressions evaluate to?
    Learning hint: Before typing them in, think to yourself what you think the answer should be; feel free to note if any surprising or puzzling results.
    You might find BlueJ's CodePad handy, for evaluating expressions.
    1. 2+3*4
    2. 2+(3*4)
    3. (2+3)*4
    4. 13.0 / 5.0
    5. 13 / 5
    6. 13 % 5
    7. Math.sqrt(25) (the built-in function Math.sqrt returns the square-root of a number)
    8. Math.PI
    9. 12 ^ 10 =                 
    10. Math.sqrt( 3*3 + 4*4 )
    11. Math.sqrt( Math.sqrt(16) )
    12. Math.sqrt( Math.abs(-16) ) (the built-in function Math.abs returns the absolute value of a number)
    Notice how, in the last three examples, you compute an intermediate result, and then pass that result as an input to another function (the (outermost) Math.sqrt).
  3. (5pts) What do each of the following Java expressions evaluate to?
    Before typing them in, think to yourself what you think the answer should be; feel free to note if any surprising or puzzling results. If the answer is a String, you should include double-quotes around it.
    1. "There are" + (1+2+3+4) + "bowling pins."
      hint:Pay attention to the spacing!
    2. "There are " + 1+2+3+4 + " bowling pins."
    3. 1+2+3+4 + " is the number of bowling pins."
    4. In the previous example, the result of 1+2+3+4 is a number, but Java implicitly2 converted that result into a string so that it could concatenate it to " is the number".

      Re-write the previous expression so that it explicitly3 calls Object120.intToString to convert the result of 1+2+3+4 into a String. Give the expression, not the result (which should be the same as before).

    5. Object120.length("hel" + "lo")
      (See lab01b—Strings: and setup: H: drive; Object120.java for how to add class Object120 to your project.)
    6. Object120.toUpperCase("HeLlO?")
    7. Object120.substring( Object120.toUpperCase("howdy"), 2, 4 ) + 40
  4. (2pts) Java has function (method) which raises one number to the power of another . Look at the documentation for class Math, and find it. (Hint: Alphabetically, it's between “max” and “signum”; the method summaries near to the top of the page are listed alphabetically.)
    Write a java expression4 computing 220 (a.k.a. 1 Meg — a bit over a million), using this function.

1You could even use BlueJ's editor, if you like.      

2implicit: without saying. So an implicit function-call is one that happens, even though you didn't actually write it in your program.      

3Explicity: with saying. So an explicit function-call is one that is written right there in your program.      

4I'm asking for the expression, not the numeric result.      

homeinfolectslabsexamshws
tutor/PIsbreeze (snow day)
Object120 + its docsjava.lang docsjava.util docs


©2012, Ian Barland, Radford University
Last modified 2012.Aug.31 (Fri)
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Powered by PLT Scheme