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

homeinfoexamslectureslabshws
RecipeLawsliessyntaxjava.lang docsjava.util docs

hw01
Temperatures on the Moon
a first function

    Part (a), due Aug.24 (Fri):

    Instructions: Submit on paper, at start of class(lab).
  1. (0pts - nickname) What name do you prefer to go by?
  2. (1pt - major) What is your major, and how confident are you of this? (give a number in [0,1]—so 50% means you're giving even odds on whether you'll graduate with that as your major).
  3. (1pt - Blackboard) Go to the Discussion Board for this class (in Blackboard). There is a discussion thread for “hw01 question”; answer that question both on the paper you hand in, and on the discussion board.
  4. (3pts - learning style) 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”.)
  5. (0pts) In Blackboard, you'll find a passel of ITEC120 courses listed: a class and lab (L) entry for your particular section, plus a class and lab entry “ITEC120-Barland (All Sections)” or “ITEC120-Dymacek (All Sections)”. We will only use the All Sections class. The other three Blackboard entries will just clutter your Blackboard view for the semester, unless you click on the pencil icon in the upper-right of your list, and choose to "Hide Link" for other ITEC120 entries.
  6. (1pt) What is often the simplest test-input, for a numeric problem?                 
  7. (1pt) What is another exceedingly simple test-input for most numeric problems?                 
  8. (2pts) Fill in each of the blanks with either “argument” or “parameter”:
    1. A function declaration's                  is a name, like “x” or “frameNum”.
    2. A function-call's                  is a particular value, like 12.3, or 0.
  9. (1pt) Type the following into BlueJ's Code Pad, and report the results (a couple are probably not what you'd guess):
    1. 3 + 4 * 5 =                 
    2. (3 + 4) * 5 =                 
    3. 9.0 / 5.0 =                 
    4. 9 / 5 =                 
    5. 9 % 5 =                 
    6. 6 ^ 4 =                 
    7. Math.pow(2,3) =                 
  10. Part (b), due Aug.27 (Mon):

    Instructions: Type into a BlueJ file, and submit both a hardcopy in class, plus electronically via Blackboard: Blackboard > Assignments > hw01a > Add attachment.
    Clarification: The file you want to attach is TempConverter.java, which is inside the project folder (which in turn should be inside your itec120 folder inside your H drive).

    Windows users: Windows Explorer hides the “.java” suffix, so if you see a file TempConverter with no suffix, that's really the .java file. Do not submit files with other suffixes (no “.class” or “.ctxt” files).

    Do not submit any running code for part (b), though you will paste work from here into your part (c).

  11. (0 pts) Make a new BlueJ project (named something like hw01b, in the itec120 folder you made on your H-drive). Within the project, make a new class TempConverter, delete all BlueJ's provided text, and paste in the following:
    /** Itec120 hw01b.  
     * See http://www.radford.edu/itec120/2007fall-ibarland/Homeworks/hw01.html
     * @author your name here
     */
    class TempConverter {
    
    
    
      }
    
  12. In some odd countries (namely Canada, and most of the rest of the world), temperatures are measured in degrees Celcius, instead of degrees Fahrenheit. So when you are traveling and you look in the newspaper and see a forecast for 22°C, it might sound chilly until a friendly Canadian citizen tells you that this is a balmy 71.6°F.

    Some other notable temperatures1 are freezing (0°C, which is 32°F), and boiling (100°C, which is 212°F).

    The general case for converting degrees-Celcius into degrees-Fahrenheit is given by the arithmetic formula

    F(C) = 95 · C + 32

    Futurama: Fry and Leela chat with Moon farmer From Futurama The Series Has Landed:

    Fry: Ooh, nighttime on the moon!
    Old coot: It git down to minus one hundr'd, sev'nty-three.
    Fry, worriedly: Fahrenheit, or Celsius?
    Old coot: First one, then th' other.


  13. (3pts) Fill in the blanks below with test cases for a function celcToFahr. (The first one is given for you; the next couple should include simple cases as mentioned in the problem-description above.)
    /*
     * mo.celcToFahr(22) = 71.6
     * mo.celcToFahr(                ) =                 
     * mo.celcToFahr(                ) =                 
     * mo.celcToFahr(37) =                 
     */
    
    (We are assuming that mo is some object who knows the celcToFahr function, which is reasonable.)
  14. (3pts) Write the signature for celcToFahr -- that is, the first line of the function, which tells Java what the function's name is, what type of arguments it takes in, and what type it returns. (Do not include the body of the function with any actual code. If you want though, you can provide a dummy body — like { return 17; }, and then BlueJ will compile your program if you don't have any mistakes in the signature. This is called a stub function.)
  15. thermometer illustration

    You read in a science article that the surface of the sun is 5700K (“kelvins”2), and that absolute zero is (conveniently) 0 Kelvin. These numbers seem even more baffling, until that same cheerful Canadian tells you that to convert a temperature from Kelvins to °C, you simply subtract 273.15. So 0 K (absolute zero) is -273.15°C, which in turn is -459.67°F, brr. Similarly, 273.15K (freezing) is 0°C which (as we've seen earlier) is 32°F.

  16. (3pts) Fill in the blanks below with test cases for a function kelvToFahr. (The first one is given for you; the next couple should include simple cases as mentioned in the problem-description above.)
    /*
     * mo.kelvToFahr(5000) = 2608.25 8540.33 (± 0.001)
     * mo.kelvToFahr(    ) =            (± 0.001)
     * mo.kelvToFahr(          ) =        (± 0.001)
     * mo.kelvToFahr(310.15) =            (± 0.001)
     */
    
    (We are assuming that mo also knows the kelvToFahr function, which is still reasonable.)
  17. (3pts) Write the signature for kelvToFahr (and only the signature!, perhaps with a stub body, if you want to verify that your signature compiles).
  18. Part (c), due Aug.29 (Wed)

    Instructions: Type into a BlueJ file, and submit both a hardcopy in class(lab), plus electronically via Blackboard.

  19. (3pts) Now, go ahead and complete the function celcToFahr. That is, translate the arithmetic formula above into Java, and then use that as the function-body.

    Run the test cases you figured out in part (b).

    Careful: Because of how Java does arithmetic, 9/5 evaluates to 1. Instead, write 9.0/5.0. We'll discuss what's happening in a week or two.
  20. (3pts)

    Finally, go ahead and complete the function kelvToFahr.

    Hint: If somebody gives you a temperature in Kelvins, converting that temperature into degrees Celsius is pretty easy. How can you then leverage code from the preceding problem, to convert that many degrees Celsius amount into degrees Fahrenheit?

    Run the test cases you figured out in part (b).


1 One other intriguing test case is that -40°C = -40°F. Is it some mystical coincidence, that two scales exactly meet at such a nice round number, instead of some random number with a bajillion decimal places?

Well, it is a small bit of luck that the answer is an integer, but every integer celcius temperature corresponds to an even fifth-of-a-fahrenheit temperature, because of the 9/5 in the formula. Where does 9/5 come from?

The factor of 9/5 stems from the difference between freezing and boiling in the two systems: (212-32)/(100-0) = 180/100 = 9/5. Both scientists Fahrenheit and Celsius chose integers for the freezing and boiling of water, so that there'd be an integer number of notches on their thermometer between the two. This is the ultimate reason why conversions between the two systems use rational numbers, and not some long irrational real number arising randomly from nature.

If some martians came to Earth and (fascinated by all the ambient water) decided that they would invent a new temperature scale where the freezing point of water was declared as -27°Martian and the boiling point as 123°Martian, we'd still end up with a conversions which used fractions, not irrationals.

     

2Interestingly, you don't write or say “degrees” with the Kelvin scale; the unit of temperature has just a one-word name rather than a two-word name.      

homeinfoexamslectureslabshws
RecipeLawsliessyntaxjava.lang docsjava.util docs


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