RU beehive logo ITEC dept promo banner
ITEC 120
2008spring
ibarland,
jdymacek

homeinfoarchiveexamslectureslabshws
RecipeLawsliessyntaxjava.lang docsjava.util docs

hw12
Finishing loops
loops calling loops

  1. The following loop is probably not at all what the author intended, for several reasons. What lines does the following print out?
        int ssf = 0;
        for ( int i = 2;  i < 10;  i = i+3 ) {
          int ssf = 0;
          ssf = ssf + i;
          System.out.println( "i=" + i + "; ssf=" + ssf );
          i = i + 3;
          }
      
    1. true or false?: According to campus policy, it is okay to tell your roommate your RU password so they can turn print out a class assignment for you.
    2. true or false?: Suppose a company offers a free-for-30-days shareware version of their program. Is it legal to re-download their program every month, without ever paying for it?
    3. true or false?: It is ethical to write a program which guesses random words and tries to log in to your friend's World of Warcraft account, since it's ridiculously unlikely that your program would successfully guess their password.
  2. In the following diagram, boxes indicate classes (types), and arrows represent “has-a”. For example, Every Lab has a Robot, every Robot has a Blender, etc.. If you have a particular object (say, a BioLab, which is of type Lab), it therefore makes sense to talk about the “BioLab's Robot” and even the “BioLab's Robot's Blender”, etc..

  3. Add to your class PlayList by writing the method numCoversOn, which takes in a single list of songs and returns how many Songs on the second list are cover versions of a song on the first. Alternately, you can have the method just take two LinkedList<Song>s.

      /* A method inside class PlayList: */
      /** Return how many songs on a List<Song>s are
       * cover versions of something in this PlayList.
       * (Note that a song might count several times, if it is a cover version
       *  of several songs on this PlayList.)
       * @param somesongs The list of songs to check for covers of. [If using this alternate approach)
       * @param othersongs The list of songs to look for covers on.
       * @return how many songs on othersongs are a cover version of
       *    something on this Playlist.
       */
      int numCoversOn( LinkedList<Song> othersongs )
        // or...
      static int numCoversOn( LinkedList<Song> somesongs, LinkedList<Song> othersongs )
    
    

    Hint: Call one of your methods from hw10, as a helper.

  4. Write a method songsInCommon which returns all Songs which appear on two different PlayLists. (That is, all songs which are equals, and not merely cover versions.)

    Hints:

homeinfoarchiveexamslectureslabshws
RecipeLawsliessyntaxjava.lang docsjava.util docs


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