RU beehive logo ITEC Department logo
ITEC 120
2007spring
ibarland,
jpittges

homeinfoexamslectureslabshws
RecipeLawsliessyntaxjava.lang docsjava.util docs

hw07
hw07
a list of questions

  1. (5pts)
    1. What is the full Java name for the type: a list of PizzaServers?                                         .
    2. Declare a variable of this type (without initializing it).                                                             .
    3. Initialize your variable from part (b) so that it contains a new, empty list.                                                             .
  2. (5pts)
    1. What is the signature for a method named “averageBalance”, which takes in a list of PizzaServers, and returns a double?                                                             
    2. What is the signature for a method named “allAlmaMaters”, which takes in a list of PizzaServers, and returns a list of Strings?                                                             
    3. What is the signature for a method named “createNewWorkforce”, which takes in an integer howManyWorkers, and returns a list of PizzaServers?                                                             
  3. (2pts) Just as 0 is often natural test-cases for functions which process ints, what is a natural test-case for functions which process a list?                 
  4. (3pts)
    Dog d1 = new Dog();
    Dog d2 = new Dog();
    Dog d3;
    d3 = d1;
    
    d1.ageOneYear();
    d1.getAge()
    d2.getAge()
    d3.getAge()
       
    Sketch a picture -- as we've been seeing in lecture1 -- showing what things look like after the above code fragment.
    If you were to typed this into Code Pad, what would the three results be from the last three expressions?                 
  5. (6pts)
    01. class Glumberpmp {
    03.   private java.util.List<String> aphorisms;
    04. 
    05. 
    06.   public java.util.List<String> getAphorisms() {
    07.     return this.aphorisms;
    08.     }
    09. 
    10.   public Glumberpmp( int n ) {
    12.     aphorisms = new java.util.List<String>();
    13. 
    14.     aphorisms.add( "Don't procrastinate now; wait 'til later." );
    15.     if (n > 99) {
    16.       aphorisms.add( "Absence makes the heart go wander." );
    17.       }
    18.     else {
    19.       aphorisms.add( "Familiarity breeds attempt." );
    20.       }
    21. 
    22.     }
    23. 
    24. 
    25.   String getAbbreviatedWisdom() {
    26.     String wisdom = "I think: ";
    27.     for ( String a : this.getAphorisms() ) {
    28.       if (! a.equals("")) {
    29.         wisdom = wisdom + a.charAt(0) + "...";
    30.         }
    31.       }
    32.     return wisdom;
    33.     }
    34. 
    35.   }
    
    For the above entirely uncommented code, give the line-numbers of …
    1. …the body of the loop                
    2. …the loop control                
    3. …loop-initialization (which occurred before the loop was called.)                 
    4. What does line 12 do?                
    5. What does line 14 do?                
    6. What does line 29 do?                
    The answers to each of (d)-(f) should be a list of roman numerals chosen from the below:
    1. “Declare a local variable”
    2. “initialize a local variable”
    3. “re-assign a local variable”
    4. “Declare a field”
    5. “initialize a field”
    6. “re-assign to a field”
    7. “access a field”
    8. “use a parameter's value”
    9. “use a local variable's value” (non-parameter)
    10. “declare a method” (give its signature)
    11. “call a constructor”
    12. “call a method” (besides a constructor)
    13. return statement”
    14. if statement” (including if-else)
  6. (1pt) What is the fewest number of times the body of a loop might be performed?                 
  7. (8pts) The following problem (and the next) are based on class PizzaServer; this will be a (static) method which we can write in that class. Recall that PizzaServers have a field which stores their high school.
      /** Look for whether a particular PizzaServer has a classmate
       *     in a list of PizzaServers.
       * @param p A particular PizzaServer.
       * @param employees A list of pizzaServers.
       * @return whether or not: a member of `employees' went to the same
       *    high school as `p', yet is not identically the same as `p'.
       */
       
    You are highly encouraged to make some test cases first on your own, and also to run your program after writing it. (But you only need to turn in written work; no test cases.)
  8. (3pts extra credit)
      /** Check whether a list has two PizzaServers which both went
       *     to the same high school.
       * @param workers A list of pizzaServers.
       * @return whether or not any two *different* members of `workers' both
       *     went to the same High School.
       */
       

1Near the left-hand-side, have your variables -- small labeled boxes, with the labels to the left of the box, and its value inside the box. On the right-hand-side, have large boxes for objects, with the name of the class above the object, and inside the box show each of its fields, just like BlueJ's inspection window for an object.      

homeinfoexamslectureslabshws
RecipeLawsliessyntaxjava.lang docsjava.util docs


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