Computer Science II - Juniata College



Computer Science IISpring 2010, Wednesday, 2/10/10100 pointsName _____________________________Explain or give the UNIX or vi commands/keystrokes to do the following tasks. A single command should suffice.[28 pts]Display all filenames and information including their modification dates, sizes and protections that are in your current directory. ______________________[2]Display only the .java filenames found in your home directory, assuming it’s not the working directory _______________________________ [2]Delete all .class files in your current directory ____________________[2]Create a subdirectory in your current directory called projArray. ___________________________[2]Move all .class files in your current directory to this subdirectory projArray ________________________[2]Change your current working directory to its parent directory ________________________[2]Display only the last 10 lines of the file log . ______________________[2]Begin capturing the screen display to a file for printing later. ____________________ [1]Print your typescript file, 2 pages per sheet. ___________________________________ [2]Start the visual editor on file exam.java ______________________[2]Compile the source file exam.java _______________________________[2]Run the Java program exam using two input strings mydata and yourdata as a command line arguments. __________________________________________________________ [2] True/false on Unix commands [5]_______The ctrl-Z key combination designates end of input in Unix._______The ctrl-S key combination stops and cancels a program in Unix._______The command options prefixed with - can be entered in any order._______In the command wc aesop.txt > words the file aesop.txt captures the output of the wc command._______All directories, disk drives, file storage structures are unified into one directory tree.Give the alphabetic or punctuation character(s) in vi to perform the following actions[7 pts]_____ move the cursor down 1 character (1 character)_____redo the previous action (1 char)_____ delete the current character (1 char)_____ start insertion mode (1 char)_____ end insert mode (1non standard character)_____ delete the current word (2 chars)_____ exit and save the file or its changes (2 chars)Arrays.[12 pts] a. Give a Java code segment to 1) define an integer array sizes with args.length elements and 2) use a for loop to initialize each element of sizes to the lengths of the strings in the args array (the command line arguments array). [6]b. Give a Java code segment to determine and print the position of the longest string. [6]Object-oriented programming design principles. (True/False)[8 pts]____ An Abstract Data Type exposes its data structure organization and hides operations.____ Reusability is a quality software goal in object-oriented class design.____ An abstract class can be used to define shared methods and instance variables inheritable by related subclasses.____ An interface defines abstract methods that must be implemented by a class that then may be used by other classes.____ ADT specifications depend on the implementation language, e.g. Java.____ The information hiding principle prevents the user from seeing the implementation but the implementer knows how it will be used in all cases.____ A pre-condition specifies what must be true about the inputs at the end of a method.Miscellaneous Java concepts (True/False)[10 pts]_____ Each Java class should be defined in its own separate file with the extension .java and the file name must match the class name._____ The contents of the .class file called bytecodes can be executed on any machine that has a Java Virtual Machine._____ The class that extends an existing class is called a superclass._____ All Java classes ultimately inherit from the Object class._____ Garbage collection in Java is the automatic recovery of memory from objects not used recently._____ The types of int and double are not true classes for performance purposes._____ Two strings are compared by the <, <=, ==, =>, > and != operations._____ The toString method must be defined uniquely for each class._____ An iterator provides a method so that all elements of a collection can be accessed in some order._____ The equals method is an example of a method that is inherited but can be overridden.Number the steps of the software development cycle (Waterfall method) from 1 to 6 in correct order.[5 pts]_____ Analysis_____ Implementation _____ Testing_____ Maintenance_____ Requirements identification_____ DesignRank the algorithm complexities from "fastest" to "slowest" (increasing dominance). 1 is fastest (good, low cost) and 6 is slowest (bad, high cost).[10 pts]O(n log n)O(n)O(n2)O(log n)O(1)O(2n)For each of the cost functions below give the “best” big-O equivalence where n is the data set size and k is some constant not related to the size of data. Best means the smallest dominance function, so O(n!) is not an acceptable answer. [8 pts]_______ f(n) = 7n2+ 4n + 2000_______ f(n) = n3 + 95n2 + 500n + 100_______ f(n) = 8n2 + 16n log n _______ f(n) = n8 +4n Estimate the running times using the big-O notation for each of these code segments. The size of the data set is n. Assume all variables are integer.[12 pts] ____________for(j=1; j<=n; j++){ sum += j;} ____________for (i=0; i<n; i++) for(j=0; j<100; j++) for(k=j; k<100; k++){ // 4 assignments // 2 square root function calls } ____________for (i=0; i<n; i++) for(j=0; j<n; j++) for(k=j; k<n; k++){ // 3 assignments } ____________i = n;while(i>0){ for(j=i; j<=n; j=j+2){ foo(j,n); //foo executes in linear time } // 3 assignment statements i = i-1;} ____________for (k=n; k>0; k--){ j=0; while (j<10){ bar(j,n); //bar executes in log n time j=j+1; }} ____________i=0;while(i<n){ j = 1; while(j<n){ //3 assignments j=j*2; } i++;} ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download