Computer Science240Name: KEY
Section 01
EXAM 01
February01, 2008
This exam has 4 pages, including this cover page. Please make sure you have all 4 pages.
You have 55 minutes to complete this exam.
You must show your work for full credit.
[2 pts each] 1. Answer the following:
(a) Explain what we mean by software engineering.
Software engineering is a disciplined approach to the creation of maintenance of computer programs.
(b) Give an example of an abstraction (we discussed a couple in class).
A map. A computer program.
(c) Define ADT.
ADT = Abstract Data Type. A data type whose properties (domain and operations) are specified independently
Of any particular implementation. All Java built-in types are ADTs, and the Java class mechanism can be used to build ADTs.
(d) What are Agile Methods?
Today it is often important for software to be developed quickly so as to meet a pressing need or to provide leverage in a rapidly changing world. Classic software engineering methods don’t typically work under these conditions. A collection of “agile” or “lightweight” methods has recently been identified to help with quick software development.
2. [2 pts each] Describe the order of magnitude of each of the following functions using Big-O notation:
(a) N2+N3(b) N*logN+N2(c) N*(N+1)/2(d) N2*logN + N(e) 2N + N2
O(N3)O(N2)O(N2)O(N2logN)O(2N)
[3 pts each] Describe the order of magnitude of each of the following code sections, using Big-O notation:
(f)(g)
count = 0;count=0;
for (int i=0; iN; i=i+2)for (int i =0; i < N; i++) {
count++; value = N; O(N) while ( value > 1) {
value = value / 2;
count++;
}
}O(N*logN)
(h)
count = 0;
for (int i=0; iN; i++) {
for (int j=i; j<N; j++) {
count++;
O(N2)
[2 pts each] 3. Explain, or give the Unix commandfor the following(you only need to give onepossible solution):
(a) Give a command which would change your current directory
to your home directorycd or cd ~
(b) Briefly explain how is ls –Fdifferent thanlsls –F shows executables * and
directories with a /
(c) Displaya file Date.java one page at a timemore Date.java
(d) Output a file Date.java to the c102 printerenscript -2r –Pc102 Date.java
lpr –dc102 Date.java
(e) Create a subdirectory called prog04from whatever current
directory you are inmkdir prog04
(f) Move a file called assign02.java from your current directory
to an existing sub-directory called exam01mv assign02.java exam01
(g) Copy all *.java files from the /academic/cs2 directory to an existing
subdirectory of your current directory called prog04cp /academic/cs2/*.java prog04
(h) One command to find all files containing the string int in
your current directorygrep int *
(i) Delete a subdirectory of your current directory called prog04rmdir prog04
(j) Display the dates and protections of all files in your current
directory, one page at a timels -al
(k) Create a file, called dir, which contains the dates and
protections of all files in your current directory ls –al > dir
(l) Give an example of the alias commandalias lf ls -F
[1 pt each] 4. Explain, or give the vi command, or keystroke(s) to answer the following:
(a) Return to Command (or “travel”) mode from insert modeESC>
(b) While in Command (or “travel”) mode, move the cursor down
one linej
(c) While in Command (or “travel”) mode, delete the character the
cursor is overx
(d) While in Command (or “travel”) mode, delete the current linedd
(e) While in Command (or “travel”) mode, exit the file and save
all changesZZ
(f) While in Command (or “travel”) mode, begin inserting on the line
after the one the cursor is currently ono
(g) While in Command (or “travel”) mode, quit the file and do
not save the file:q!
5. Use the class definition at the right to answer the following questions. You will NOT need to modify the code at the right.
[3 pts] Give the output if the following segment of code was run:
Car acura = new Car();
System.out.println( acura.getColor() );
blue
[4 pts] Add line(s) below, if necessary, so the following code prints Yes!
Car CRV = new Car (2500,"silver");
Car Rav4 = new Car (2500,"silver");
CRV = Rav4
if (CRV == Rav4) {
System.out.println("Yes!");
} else {
System.out.println("No");
}
[4 pts] Add line(s) below, if necessary, so the following code prints No
No addl. code neccessary
Car CRV = new Car (2500,"silver");
Car Rav4 = new Car (2500,"silver");
if (CRV == Rav4) {
System.out.println("Yes!");
} else {
System.out.println("No");
}
[6 pts] Write the segment (NOT an entire program) of code which would declare and instantiate an array of n cars. You may assume that n is an integer and that you can use it in the code. All the new cars should be white and have initial mileage of 10.
Car[] carArray = new Car[n];
for (int i=0; i<n; i++) {
carArray[i] = new Car(10,"white");
}
1