Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
CS 240 Exam 1 Computer Science II Spring 2002 2/6/02 Page 1 Name _____________________________ Explain or give the UNIX or vi commands or keystrokes to do the following tasks. [27 pts] 1. Display only filenames that have the .java extension. _______________________[2] 2. Display all filenames (including the special ones starting with a period) found in /academic/cs2 ________________________ [2] 3. Delete all files with extension .class in the current directory. ____________________________[2] 4. Create a subdirectory called classes. ___________________________[2] 5. Move all .class files in your current directory to the new subdirectory classes ____________________________________ [2] 6. Set your current working directory to the new classes subdirectory ________________________[2] 7. Display the contents of the file program.java one screen at a time ______________________[2] 8. Begin capturing the screen display to a file for printing later ____________________ [1] 9. Print the file typescript to the local printer using the enscript formatter ____________________________[2] 10. Start the visual editor on file program.java ______________________[2] 11. What keystroke terminates a program in Unix?____ What keystroke designates end of input in Unix?____[2] 12. Define a symbol dir as a synonym (same meaning) as ls _________________________ [3] 13. Run the program filter using the file data for input and pipe the output stream through more. __________________________________________________[3] 14. Give the keystroke(s) in vi to perform the following actions [8 pts] _____undo the previous action (1 character) _____exit and save the file (2 chars) _____ start insertion mode (1 char) _____ move the cursor down 10 lines (3 chars) _____ delete the current line (2 chars) _____ end insert mode (1 char) _____ repeat the previous editing operation (1 char) _____ exit and do not save the file (3 chars) CS 240 Exam 1 Page 2 15. Collections. [10 pts] a. Connect the four elements below into a purely linear collection with arrows starting at element A and ending at element D [3]. A D B C b. Connect the four elements below into a hierarchical structure with the root (start) as B with C as an intermediate node. [3] A D B C c. Name three general operations that we can perform on collections. ___________________ ___________________ ___________________ 16. Abstract Control Structures. (True/False) [5 pts] a. ____ The if-then-else statement is a form of a selection control structure. b. ____ The switch statement is a form of an iterative control structure. c. ____ A void function is one that should not have a return value. d. ____ The for loop can always be transformed into a while loop. e. ____ The break statement is used only in the switch statement. 17. Programming principles. Fill in the blank. [10 pts] a. The Information Hiding Principle specifies that the user of a module is provided only the necessary information to _________ the module and that the ___________________________ is provided only the necessary information to ______________________ the module. b. A ________-condition specifies what must be true at the beginning of a function and a ____________________ specifies what must be true at the end of a function. These assertions provide a form of a contract between the ____________ and the implementer. c. Testing a module knowing its function but not necessarily its implementation is called ___________- box testing while ___________ -box testing ensures each control path is tested in the implementation. d. The part of speech (noun, verb, adjective) that should be used for an instance variable is a/an __________ and the part of speech that should be used for a void function is a/an _____________. CS 240 Exam 1 Page 3 18. Java concepts (True/False) [10 pts] a. _____ Each Java class should defined in its own separate file and that file name must match the class name. b _____ To execute the bytecodes of a Java program you must use a Java Virtual Machine. c. _____ Garbage collection must be explicitly invoked by the user to recover unreferenced objects. d. _____ The toString function that can be defined for each class is an example of polymorphism. e. _____ Strings in Java are immutable. f. _____ A class that is inherited from an existing class is the superclass. g. _____A protected instance variable is an inheritable public variable. h. _____Every class ultimately is a subclass of Object. i. _____ Two strings can be compared with == j. _____ The import statement is a reference to one or more supporting class files. 19. Number the steps of the software development cycle (Waterfall method) from 1 to 6 in correct order. [5 pts] _____ Design _____ User request _____ Analysis _____ Integration _____ Integration _____ Maintenance 20. What is meant and gained by separating the view of a GUI solution from the model of its solution? [5 pts] CS 240 Exam 1 Page 4 21. Below is a segment of code similar from class and your project. Assume classes Circle and Rectangle are subclasses of Shape. [20 pts] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Circle [] circles; circles = new Circle[10]; circles[0] = new Circle (1,1,2);//(x,y,radius) circles[1] = new Circle (2,2,3); Shape shapes[] = new Shape[10]; shapes[0] = new Circle(1,2,3); shapes[1] = circles[1]; shapes[2] = new Rectangle(2,3,4,4);//(x,y,length,width) shapes[3] = circles[0]; shapes[4] = new Rectangle(3,4,5,1); double totalArea = 0; for(i=0; i<5; i++){ System.out.println(shape[i]); if shapes[i] instanceof Rectangle){ totalArea += shape[i].area(); } } System.out.println(totalArea); a. Describe what lines 1 and 2 accomplish. b. What is being called in lines 3 and 4? c. Draw a picture of the memory layout as a result of lines 6-11. d. Describe what function(s) is/are called in line 15. e. What is the value of the last println in line 20?