RU beehive logo ITEC dept promo banner
ITEC 120
2007fall
ibarland,
jdymacek

homeinfoexamslectureslabshws
RecipeLawsliessyntaxjava.lang docsjava.util docs

hw04
hw04

Part (a)

Due Sep.14 (Fri): Problems 1-9; only hardcopy is needed.

This week, part (a) will be accepted without penalty on Sep.17 (Mon).

Part (b)

Due Sep.17 (Mon): Problems 10-11, the html-documentation only (signatures, javadoc, and test cases). Turn in a hard-copy in class and also electronically submit (on WebCT) a copy of either the html file or the java file.

(Note that the javadoc has already been completed for you this week; although you can put a comment with an @author tag preceding the class declaration.)

Part (c)

Due Sep.19 (Wed): Problems 10-11, implementation (Java code). (If you turn it by Tuesday, it will be graded by Wednesday, in time for the exam.)

Note that you can consider this homework of studying for the exam.

  1. (2pts) Based on the following function-call, what is the signature for this function? (Make up any parameter names you like.)
                    
    2 + bob.gloopz( "Tuesday", false )
    Extra credit (1pt): what are all the possible return types this function might have?
  2. (2pts) Based on the following signature give a sample call to the function, and determine whether the result is bigger than zero. You can assume z is (a variable referring to) an object of the appropriate type.
    double roundTripTime( String url, int portNumber )
    
    
  3. (3pts) Give the signature of a function named startsWith, which takes in two Strings returns a boolean (indicating whether the first input begins with all the letters of the second input, if you're curious).                                         
  4. (1pt) Which one of the following is not a javadoc “@” keyword?
    1. @return
    2. @author
    3. @double
    4. @param
  5. (1pt) What does 22/5 evaluate to?
    What does 22.0/5.0 evaluate to?
  6. (2pts) Rewrite the following expression for clarity (without doing any arithmetic yourself):
    2*3-26/2/3*3+1                     
    What is the result of evaluating the expression?                 
  7. (3pts) For each of the following, does it describe a named constant (“nc”) or local variable (“lv”)?
    1.          must be declared and initialized in the same statement.
    2.          Its initial value depends on parameters.
    3.          Should be declared inside a class declaration, but before any functions.
    4.          Its first letter should be lower-case.
    5.          Written in ALL_CAPS.
  8. (2pts)
    1. Declare a local variable suitable for storing whether or not a store accepts credit cards.                     
    2. Initialize that variable to hold whatever value you prefer.                     
  9. (2pts) Without doing any arithmetic yourself…
    1. write a java expression for the remainder after dividing 579 by 100 (in this example, 79).           
    2. write a java expression for the quotient after dividing 579 by 100 (in this example, 5).           
  10. Consider the following:
      /** Given a number of cents, return a String for that amount in dollars,
       *        including a preceding dollar-sign,
       *        but using a (european-style) decimal-comma rather than a decimal-point.
       * @param cents An amount of money (in cents).
       * @return A String representing that amount, in dollars.  Use a comma
       *          for the decimal-separator.
       * Examples (assuming that `c` is a Cashier):
       *   c.centsToStringEuroStyle(579) = "$5,79"
       *   c.centsToStringEuroStyle( 43) = "$0,43"
       *   c.centsToStringEuroStyle(                ) =                 
       *   c.centsToStringEuroStyle(                ) =                 
       *   c.centsToStringEuroStyle(                ) =                 
       */
    
    Consider the following function. Hint: Form your answer by concatenating the string "$", an integer, the string ",", followed by whatever else is needed. (Thorough and careful testing is particularly suggested for this problem.)
  11. The fancy bread shop, Oh Bonnie Pain, wants to sell delicious Sugarbomb Donuts, for 85 cents each. In order to seem european, they will list their prices using a comma as the decimal-separator.
    /** Respond to a donut order, at Oh Bonnie Pain.
     * @param nombreDonuts The number of donuts ordered.  Non-negative.
     * @return A sophisticated-sounding message reporting the total price.
     * Tests (presuming `c` is a Cashier):
     *   c.donutOrderrier( 10 ) = "10 sucrebombe donuts will cost $8,50.  Merci!"
     *   c.donutOrderrier(     ) =                 
     *   c.donutOrderrier(     ) =                 
     */
    
  12. Extra Credit: (4pts test cases/docs; 4pts code; due with part (c))
    Write a function centsToString which is more flexible than our above centsToStringEuroStyle: It takes in two arguments: a number of cents, and a decimal separator (a String).
    Now, rewrite the body of centsToStringEuroStyle with just one short line:
                                                                                                        

homeinfoexamslectureslabshws
RecipeLawsliessyntaxjava.lang docsjava.util docs


©2007, Ian Barland, Radford University
Last modified 2007.Sep.19 (Wed)
Please mail any suggestions
(incl. typos, broken links)
to iba�rlandrad�ford.edu
Powered by PLT Scheme