CS56—Midterm Exam 1
E01, S13, Phill Conrad, UC Santa Barbara
04/25/2013

Name: ___________________________________________________


Umail Address: ______________________________@ umail.ucsb.edu



Circle one:       10am        11am 



Please write your name only on this page.
That allows me to grade your exams without knowing whose exam I am grading.

This exam is closed book, closed notes, closed mouth, cell phone off,
except for:

There are 100 points worth of questions on the exam, and you have 75 minutes to complete the exam.

A hint for allocating your time—on your first pass through the exam:

If you do that, after you complete your first pass through the exam in 50 minutes, you'll still have 25 minutes to:


  1. (50 pts) In the space below (and on the next page if needed) write the code for the TeamMember class according to the instructions on the separate handout provided.

    There is more room on the next page for your answer if you run out of room here.

    Extra space for your answer to question 1

  2. The next five questions give you an opportunity to demonstrate that you understand some of what you are doing in lab (i.e. that you are reading in detail, and reflecting on what you are doing—not just "going through the motions").

    They should be answered briefly (i.e in the space provied) but with just enough detail that if you were asked the question in a job interview, and you gave your answer to the interviewer, she or he would be reasonably convinced that you know what you are talking about. So, think before you write.

    1. (6 pts) Briefly distinguish between targets and tasks in an Ant build.xml file.










    2. (6 pts) Briefly describe what a stub is in the context of Test-Driven Development.











    3. (6 pts) Briefly describe why writing stubs before writing correct methods can be helpful in increasing confidence in the testing process.











    4. (6 pts) Briefly describe the purpose of git.













    5. (6 pts) Briefly distinguish between what happens in a "git add", and "git commit" and a "git push".








  3. (20 pts) For this question, you may find the following fragments of the Javadoc for the java.util.ArrayList<E> class helpful.

    ArrayList<E>
    Constructor: ArrayList<E>(int initialCapacity) Constructs an empty list with the specified initial capacity.
    Methods: int size() Returns the number of elements in this list.
      E get(int index)
    Returns the element at the specified position in this list.
      boolean add(E e)
    Appends the specified element to the end of this list, and returns true


    Your job: Assume that you are writing the class TeamRoster, the first line of which is:
    public class TeamRoster extends ArrayList<TeamMember> { 

    The TeamMember class is the same one you wrote for question 1 of this exam, and the same one described on the additional handout you got with this exam.

    The TeamRoster class has no data members defined (other than the ones inherited from ArrayList<TeamMember>, which are all private.

    Inside the TeamMember class, you need to write two public methods.

    • The first is called jerseyToName that takes one parameter, jerseyNum of type int, and returns a value of type String. The String returned is the name of the player that wears the Jersey indicated by the number passed in. If that Jersey number is not found, the method should return the value null. An example call:
      TeamRoster bballTeam = new TeamRoster();
      ... // code here adds TeamMember objects to bballTeam
      String name=bballTeam.jerseyToName(22);
      
    • The second method is called subroster, and it takes an array of int (i.e. a plain old java array of int primitives) as its parameter. The array of int values represents a set of jersey numbers. What is returned is a new TeamRoster object containing only the TeamMember objects whose jersey numbers appeared in the array. Jersey numbers that are not found are ignored—that is, if an array of three Jersey numbers is passed in, and none of the are actually jersey numbers of members on the team, an empty TeamRoster is returned. If an array of 5 jersey numbers is passed in, but only three are on the team, then a TeamRoster with those three is returned, but no error is printed, and no exception is thrown.An example call:
      TeamRoster soccerTeam = new TeamRoster();
      ... // code here adds TeamMember objects to soccerTeam
      TeamRoster defenders=soccerTeam.subroster(new int [] {2,4,12,13,16,31});
      

    Write ONLY the implementation of the jerseyToName and subroster methods of TeamRoster in the space below.
    Hint: your answers will likely contain either
    • a traditional for loop, e.g. for (int i=0; i<something; i++) {...}
    • or a Java style for each loop, e.g. for (Dog d: dogs) {...}





















    More space on the next page if you need it

    Extra space for your answer to previous question in case you need it.


End of Exam

Total points: ?