RU beehive logo ITEC dept promo banner
ITEC 120
2008fall
aaray,
ejderrick,
ibarland,
jmdymacek

homeinfolabshwsexams
textbookjava.lang docsjava.util docsarchive

hw07
booleans; loop drill

Due Oct.29 (Wed).

For the problems on the javabat web site: If your solution does not pass all the tests, clearly indicate how many tests your code doesn't pass.

  1. (6pts1) JavaBat: cigarParty2 (No loops required.)
  2. (6pts) JavaBat: luckySum (No loops required.)
  3. (6pts extra-credit) R6.2: What is printed by
    1. for (int i = 0; i < 10; i++)
    2. {
    3.    for (int j = 0; j < 10; j++)
    4.       System.out.print(i * j % 10);
    5.    System.out.println();
    6. }
    
  4. (6pts) R6.8
  5. (2pts) R6.9
  6. (6pts) Bertie the biologist was supposed to be out observing birds, but instead he went sunbathing at the beach. When the teacher asked him to turn in his log, he realized he quickly needed to forge one3. So, he wrote the following method.
    class Bio580 {
      static String birdWatchingLog( int numDays ) {
        int currentDay = 1;
        String messageSoFar = "Sightings:\n";
        while (currentDay <= numDays) {
          messageSoFar +=  "Day " + currentDay + ": saw " + (numDays-currentDay) + " bird(s)\n";
          currentDay = currentDay + 1;
          }
        return messageSoFar;
        }
      }
    
    Questions:
    1. What does birdWatchingLog return, when passed 3? (That is, exactly what value is returned.)
    2. What is one (or two) line(s) of code which you can type into BlueJ's Code Pad, so that a 30-day log is printed on the terminal window?
  7. (6pts) Modify the previous problem's code, so that it returns the same string plus one more line stating how many birds were seen altogether.
    Hint: you'll need to accumulate a second piece of information: the number of total birds seen so far.

1Point values are guidelines -- your section's professor might award points differently.      

2The ITEC department does not condone smoking cigars (neither by humans nor squirrels).      

3The ITEC department does not condone forging scientific data.      

homeinfolabshwsexams
textbookjava.lang docsjava.util docsarchive


©2008, Ian Barland, Radford University
Last modified 2008.Nov.03 (Mon)
Please mail any suggestions
(incl. typos, broken links)
to iba�rlandrad�ford.edu
Powered by PLT Scheme