CSE 114

Fall 2010 - FINAL CODING EXAM

Tuesday, December 14th


\\files\exams\CSE114_Fall2010_FinalCodingExam.html

Student Name: ____________________________________________
login : finalexam
password: Fall2010
Terminal Number: __________________________________________

Exam Setup:

  1. Right-click on cse114_fall2010_final_exam.zip and Save Target to your Downloads directory. Do the same for the JUnit library.
  2. Note that in this exam, you will have to use the eclipse IDE. To start:
  3. You should now have a project with all the files necessary to code your solutions, but you will have compiler errors. To fix this, you need to tell the project where the JUnit library is:
  4. Verify that the project is setup properly. Are you able to open and edit the source code? Are you able to run the grading program (GradeCalculator)?

    NOTE: There should be no compiler errors at this time. If there are, please alert the instructor so that we may correct this problem ASAP.

  5. Now you must rename the project using the format LastName_FirstName_F10_Final, where you would substitute your own name. To do this:
    • Right click on your project and select Refactor
    • Then select Rename
    • Type in your new project name and click OK
  6. Exam Handin:

    When you are done with all of your work and you are ready to leave:

    NOTE: Please make sure you put your name at the top of all of the Question$ files


    Exam Rules:

    JUnit Testing and Exam Grading:





    Question 1 (12.5 Points) - extractLowByteFromIPAddress

    As we learned in HW 2, an IP address is really 4 bytes (0-255) strung together. Well, four bytes can be stored in an int, right? Define the Question1 class' extractLowByteFromIPAddress method such that it takes the ipAddressAsInt argument and extracts and returns the value stored int the lowest-order byte. You'll want to use masking for this, which we did in both the lab and in HW assignments.

    EXAMPLE OUTPUT:
    From running the Question1 main method:

    IP Address: 50.8.25.80
    IP Address in single int: 839391568
    Extracted Low Byte: 80
    
    IP Address: 150.129.75.17
    IP Address in single int: -1769911535
    Extracted Low Byte: 17
    
    IP Address: 250.211.253.38
    IP Address in single int: -86770394
    Extracted Low Byte: 38
    
    IP Address: 255.255.255.255
    IP Address in single int: -1
    Extracted Low Byte: 255
    
    IP Address: 0.0.0.0
    IP Address in single int: 0
    Extracted Low Byte: 0
    
    IP Address: 1.2.3.4
    IP Address in single int: 16909060
    Extracted Low Byte: 4
    



    Question 2 (12.5 Points) - calculateAverageAge

    The Question2 class maintains an instance variable that is an array of Person objects. Define the calculateAverageAge method such that it calculates and returns the average age of all the Person objects in the array. Note that this method should return an integer that is rounded to the nearest whole number, up if .5 or greater, down if .4 or smaller. Note that you may not assume that the array is full or packed. Person objects may be scattered at any index in the array with gaps in between.

    EXAMPLE OUTPUT:
    From running the Question2 main method:

    People: []
    	Average Age: 0
    
    People: [Geddy Lee, age 57,Alex Lifeson, age 57,Neil Peart, age 58,]
    	Average Age: 57
    
    People: [Roger Daltrey, age 66,Pete Townshend, age 65,Keith Moon, age 64,John Entwistle, age 66,]
    	Average Age: 65
    
    People: [Roger Waters, age 67,null,null,David Gilmour, age 64,null,null,Rick Wright, age 67,null,null,Nick Mason, age 66,]
    	Average Age: 66
    
    People: [null,null,John Lennon, age 70,null,null,Paul McCartney, age 68,George Harrison, age 67,Ringo Starr, age 70,]
    	Average Age: 69
    
    People: [Joe Strummer, age 58,Mick Jones, age 55,Paul Simonon, age 54,Topper Headon, age 55,null,null,null,null,null,null,]
    	Average Age: 56
    



    Question 3 (12.5 Points) - toString

    The Question3 class is a class similar to the Employee class we used this semester. Note that it extends Person and has a salary instance variable. Define the toString method such that it returns a textual representation of the object in the form of "John Doe ($50000)". Be careful to provide the spaces in their proper places otherwise the test will fail. You do not have to provide commas for large numbers.

    EXAMPLE OUTPUT:
    From running the Question3 main method:

    John Lennon ($12345)
    Paul McCartney ($54321)
    George Harrison ($90210)
    Ringo Starr ($8675309)
    




    Question 4 (12.5 Points) - getCapitalLetters

    Define the Question4 class' getCapitalLetters method such that it examines the text argument for capital letters. These letters should be extracted and returned as a single String. If no capital letters are found, an empty, but constructed, string object should be returned.

    EXAMPLE OUTPUT:
    From running the Question4 main method:

    the beatles gives us: 
    
    PINK FLOYD gives us: PINKFLOYD
    
    The wHO gives us: THO
    
    tHE roLLing stones gives us: HELL
    
    the kINKs gives us: INK
    
    the cLASH gives us: LASH
    
    Yes gives us: Y
    
    THE pOlice gives us: THEO
    
    tHe whITe Stripes gives us: HITS
    
    Zz tOP gives us: ZOP
    



    Question 5 (12.5 Points) - removeFirstAndLastWord

    Define the Question5 class' removeFirstAndLastWord method such that it removes the first and last word from the text argument and returns the resulting string. Note that you may assume that words are always separated by a space character and that all text arguments have at least two words.

    EXAMPLE OUTPUT:
    From running the Question5 main method:

    the quick brown fox jumped over the lazy dog
    becomes
    quick brown fox jumped over the lazy
    
    they're going to their house over there
    becomes
    going to their house over
    
    how much wood could a wood chuck chuck?
    becomes
    much wood could a wood chuck
    
    she sells sea shells by the sea shore
    becomes
    sells sea shells by the sea
    
    fuzzy wuzzy was a bear
    becomes
    wuzzy was a
    



    Question 6 (12.5 Points) - addData

    The Question6 class has an instance variable called nums, which is an array of ints. Define the Question6 class' addData method such that it increases the capacity of the nums array by one and then adds the data argument into the array at the highest index. Note that your nums array should always be full.

    EXAMPLE OUTPUT:
    From running the Question6 main method:

    [1]
    [1,2]
    [1,2,3]
    [1,2,3,5]
    [1,2,3,5,7]
    [1,2,3,5,7,11]
    [1,2,3,5,7,11,13]
    [1,2,3,5,7,11,13,17]
    [1,2,3,5,7,11,13,17,19]
    [1,2,3,5,7,11,13,17,19,23]
    




    Question 7 (12.5 Points) - sortCards

    Define the Question7 class' sortCards method such that it sorts the cards array argument such that cards are ordered in groups of Clubs, Diamonds, Hearts, and Spades, and then by rank within their suit. You may use any sorting algorithm you like, but you may not use API classes to do sorting for you.

    EXAMPLE OUTPUT:
    From running the Question7 main method:

    Original Cards: [8H,10H,QD,JD,4S]
    Sorted Cards:   [JD,QD,8H,10H,4S]
    
    Original Cards: [JD,2H,QS,JH,9S,AS,2C,KD,3S,AC]
    Sorted Cards:   [AC,2C,JD,KD,2H,JH,AS,3S,9S,QS]
    
    Original Cards: [3C,KC,4S,7C,QH,9S,4D,QS,KH,AC,KD,2S,5S,3D,5H]
    Sorted Cards:   [AC,3C,7C,KC,3D,4D,KD,5H,QH,KH,2S,4S,5S,9S,QS]
    
    Original Cards: [9D,9S,KS,4H,8D,7D,9H,8S,10S,6D,2C,6C,6H,3D,7S,9C,7C,10D,8C,QS]
    Sorted Cards:   [2C,6C,7C,8C,9C,3D,6D,7D,8D,9D,10D,4H,6H,9H,7S,8S,9S,10S,QS,KS]
    



    Question 8 (12.5 Points) - hexToDec

    In lab and in the HWs we learned about the Hex number system, a base 16 system with 16 different types of digits, 0-f. Define the Question8 class' hexToDec method such that it takes a String representing a Hexadecimal number and returns the decimal equivalent of that number. Note, you may assume there will be no negative numbers and that every hex number I give you will have a decimal equivalent that will fit into an int.

    EXAMPLE OUTPUT:
    From running the Question8 main method:

    9 in decimal is 9
    
    10 in decimal is 16
    
    dead in decimal is 57005
    
    f00d in decimal is 61453
    
    acdc in decimal is 44252
    
    face in decimal is 64206
    
    f001 in decimal is 61441
    
    cab1e in decimal is 830238
    
    cafe in decimal is 51966
    



    String Methods - here is a description of a number of methods from the String class you may consider using.