CSE 114

Fall 2009 - FINAL CODING EXAM

Tuesday, December 15th


LOGGING IN

Student Name: ____________________________________________
Terminal Number: __________________________________________
login name: etest
password: Fall2009

Exam Setup:

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) - pythagoreanTheorem

Define the Question 1 class' pythagoreanTheorem method such that it takes two double arguments, x and y, and returns the value z in the pythagorean theorem. The pythagorean theorem is defined as:

x2 + y2 = z2

Note that you may use any method you like from the Math class in order to perform this calculation. If you do not know what methods are inside this class, simply type "Math." and eclipse will let you know.

EXAMPLE OUTPUT:

From running the Question1 main method:

3.0^2 + 4.0^2 = 5.0^2
30.0^2 + 40.0^2 = 50.0^2
300.0^2 + 400.0^2 = 500.0^2
3.0E30^2 + 4.0E30^2 = 5.0E30^2


Question 2 (12.5 Points) - extractHostName

Define the Question 2 class' extractHostName method such that it examines the method's url argument and extracts and returns the host name. You may assume that the url> argument will always be a valid URL and will always have a valid protocol followed by "://". Remove "www." from the front of any host.

EXAMPLE OUTPUT:

From running the main method:

The host name of http://www.cs.sunysb.edu/~cse114/schedule.html is cs.sunysb.edu
The host name of ftp://random.net/whoknows/file.zip is random.net
The host name of https://www.nytimes.com is nytimes.com
The host name of gopher://minnesota.edu/home/accts/a/b/ is minnesota.edu


Question 3 (12.5 Points) - toString

Change the Question3 class such that:

EXAMPLE OUTPUT:

From running the Question3 main method:

Joe Strummer (1 objects total)
Mick Jones (2 objects total)
Paul Simonon (3 objects total)



Question 4 (12.5 Points) - compareTo & toString

The Question4 class is very similar to the Employee class we used in lab. If we want to sort a Vector of these objects, we can use the Collections.sort method, but first we must tell this method how to sort our objects.

Define the Question4 class' compareTo method such that it can be used to sort Question4 objects in increasing order by salary. Also, define the toString method such that it spedifies the name, age, and salary of the object using the precise format displayed in the example below.

EXAMPLE OUTPUT:
From running the Question4 main method:

Matt, age 18 ($18000)
Ed, age 20 ($19000)
David, age 33 ($33000)
Cathy, age 38 ($48000)
Linda, age 29 ($59000)
Sue, age 40 ($61000)
Gene, age 30 ($70000)
Rachel, age 27 ($82000)
Mary, age 35 ($90000)
Pete, age 41 ($101000)


Question 5 (12.5 Points) - createArrayOfChars

Define the Question5 class' createArrayOfChars method such that it build an array of characters where the first character in the array is the minChar argument, and the last character in the array is the maxChar argument, and in between are all the ASCII characters between them.

NOTE: you may assume that the minChar argument will always be less than or equal to the maxChar argument.

EXAMPLE OUTPUT:
From running the Question5 main method:

A
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789
 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~


Question 6 (12.5 Points) - indexOfOldestPerson

Define the Question6 class' indexOfOldestPerson method such that it goes throught the people array, finds the oldest Person inside, and returns that index. Note that the array is not sorted in any way. DO NOT CHANGE THE ORDER OF THE ELEMENTS IN THE ARRAY.

EXAMPLE OUTPUT:
From running the Question6 main method:


ARRAY TO SEARCH:
	0: Don Mattingly, age 48
	1: Mariano Rivera, age 40
	2: Andy Pettitte, age 37
	3: Willie Randolph, age 55
	4: Reggie Jackson, age 63
Oldest person found at index 4: Reggie Jackson, age 63

ARRAY TO SEARCH:
	0: Don Mattingly, age 48
	1: Mariano Rivera, age 40
	2: Bernie Williams, age 41
	3: Graig Nettles, age 65
	4: Andy Pettitte, age 37
	5: Derek Jeter, age 35
	6: Reggie Jackson, age 63
Oldest person found at index 3: Graig Nettles, age 65

ARRAY TO SEARCH:
	0: Graig Nettles, age 65
	1: Don Mattingly, age 48
	2: Mariano Rivera, age 40
	3: Bernie Williams, age 41
	4: Andy Pettitte, age 37
	5: Derek Jeter, age 35
	6: Reggie Jackson, age 63
	7: Jorge Posada, age 38
	8: Willie Randolph, age 55
	9: Ron Guidry, age 59
Oldest person found at index 0: Graig Nettles, age 65


Question 7 (12.5 Points) - sort

Define the Question7 class' sort method such that it sorts the object's people instance variable in increasing order by age.

NOTE: you may not use Java API methods to do your sorting for you. You may use Selection Sort or Bubble Sort in your solution.

EXAMPLE OUTPUT:
From running the Question7 main method:

ORIGINAL ARRAY WITH 5 ELEMENTS:
	0: Don Mattingly, age 48
	1: Mariano Rivera, age 40
	2: Andy Pettitte, age 37
	3: Reggie Jackson, age 63
	4: Willie Randolph, age 55
AFTER SORT:
	0: Andy Pettitte, age 37
	1: Mariano Rivera, age 40
	2: Don Mattingly, age 48
	3: Willie Randolph, age 55
	4: Reggie Jackson, age 63

ORIGINAL ARRAY WITH 10 ELEMENTS:
	0: Don Mattingly, age 48
	1: Graig Nettles, age 65
	2: Mariano Rivera, age 40
	3: Bernie Williams, age 41
	4: Andy Pettitte, age 37
	5: Derek Jeter, age 35
	6: Reggie Jackson, age 63
	7: Jorge Posada, age 38
	8: Willie Randolph, age 55
	9: Ron Guidry, age 59
AFTER SORT:
	0: Derek Jeter, age 35
	1: Andy Pettitte, age 37
	2: Jorge Posada, age 38
	3: Mariano Rivera, age 40
	4: Bernie Williams, age 41
	5: Don Mattingly, age 48
	6: Willie Randolph, age 55
	7: Ron Guidry, age 59
	8: Reggie Jackson, age 63
	9: Graig Nettles, age 65


Question 8 (12.5 Points) - binaryToDecimal

Define the Question8 class' binaryToDecimal method such that it takes a String containing a sequence of 1s and 0s representing a binary number, converts that number into a decimal integer, and returns that value.

NOTE: we are only dealing with positive binary numbers the way we did it in the lab.

EXAMPLE OUTPUT:
From running the Question8 main method:

00000000 -> 0
00000001 -> 1
00000010 -> 2
00000011 -> 3
00000100 -> 4
00000101 -> 5
00000110 -> 6
00000111 -> 7
00001000 -> 8
00001001 -> 9
00001010 -> 10
...
11111010 -> 250
11111011 -> 251
11111100 -> 252
11111101 -> 253
11111110 -> 254
11111111 -> 255



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