Computer Science II



Computer Science II

Spring 2003, Wednesday, 2/5/03

Name _____________________________

Explain or give the UNIX or vi commands or keystrokes to do the following tasks.

[27 pts]

1. Display filenames and all their details found in your current directory that have the .java extension. _______________________[2]

2. Display only filenames (including the special ones starting with a period) found in /academic/cs2 ________________________ [2]

3. Create a subdirectory called myclasses. ___________________________[2]

4. Copy all .class files in your current directory to this new subdirectory myclasses ____________________________________ [2]

5. Delete all files with extension .class in your current directory. ____________________________[2]

6. Change your current working directory to the new classes subdirectory ________________________[2]

7. Display the contents of the file test.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, default printer using the enscript formatter ____________________________[2]

10. Start the visual editor on file test.java ______________________[2]

11. What keystroke terminates a program in Unix?____

What keystroke designates end of input in Unix?____

What character designates the current directory? _____ [3]

12. Which file contains commands for initializing your c-shell? _________________________ [2]

13. Run the non-Java program prog using the file data for input and pipe the output stream through more. __________________________________________________[3]

14. Explain the action executed for each of these vi commands

[8 pts]

i ________________________________________

ESC (key)________________________________________

10k________________________________________

dd________________________________________

u__________________________________________

. (period) ___________________________________________

ZZ _____________________________________________

:q! ____________________________________________

15. Collections.

[5 pts]

a. Connect the four elements below into a purely linear collection with arrows starting at element A and ending at element D [3].

b. Connect the four elements below into a hierarchical structure with the root (start) as B with C as an intermediate node. [2]

16. Abstract Data Types. (True/False)

[5 pts]

a. ____ The ArrayList is an example of a dynamic structure.

b. ____ The ArrayList is designed to hold only primitive data types.

c. ____ All ADTs implemented as classes ultimately inherit from the Object class.

d. ____ The abstract class can be used to define methods and instance variables inheritable by related classes.

e. ____ An abstract class cannot define the body of any of its methods.

17. Object-oriented programming design principles.

[10 pts]

a. Define the Information Hiding Principle from the perspective of the user [3].

b. How do pre conditions and post conditions support the separation of activities between the user and implementer of a module? [4]

c. Define black-box testing [3].

18. Miscellaneous Java concepts (True/False)

[10 pts]

a. _____ Each Java class should be defined in its own separate file with the extension .java and that file name must match the class name.

b _____ The contents of the .class file are called bytecodes, which are platform independent.

c. _____ Garbage collection is automatically invoked by the Java Virtual Machine to recover memory from the unreferenced objects.

d. _____ The toString function that can be defined for each class is an example of a transformer or mutator.

e. _____ An iterator ensures that each element of a collection can eventually be accessed.

f. _____ A class that is inherited from an existing class is the superclass.

g. _____A record structure is one usually composed of private instance variables and public methods.

h. _____The Exception class is the exception of not being a subclass of Object.

i. _____ Two strings can be compared with < and >.

j. _____ Object variables are really pointers or references to objects stored in the heap space.

19. Number the steps of the software development cycle (Waterfall method) from 1 to 6 in correct order.

[5 pts]

_____ Integration _____ Maintenance

_____ Design _____ User request

_____ Analysis _____ Implementation

20. We have discussed the differences between an UnsortedStringList and SortedStringList. For each of the abstract operations below, assuming a list size of 100, approximate the average number of copy or compare operations a program would have to carry out to accomplish the operation for the different type of StringLists.

[10 pts]

|Abstract operation (basic operation to be |For UnsortedStringLists |For SortedStringLists |

|approximated) | | |

|Insert a new element (copy) | | |

|Delete an element (copy) | | |

|Return the length of the list (compare, but be | | |

|careful here) | | |

|Find an existing element (compare) | | |

|getNextItem (compare) | | |

21. Below is a segment of code similar from class and your project. Assume classes Date is a class that holds the day, month and year along with a String name. IncDate inherits from Date and adds the increment method that advances the day by one. In both cases the toString() function prints the date in mo/day/yr format.

[20 pts]

0 try {

1 Date [] events;

2 events = new Date[10];

3 events[0] = new Date (1,13,2003, “Classes start”);

4 events[1] = new Date (2,2,2003, “Groundhog Day”);

5

6 IncDate today = new IncDate(2,5,2003,”CS 240 Exam 1”);

7 IncDate tomorrow = new IncDate(2,5,2003,”Work on Program 3”);

8 tomorrow.increment();

9 events[2] = today;

10 events[3] = tomorrow;

11 events[4] = new IncDate (4,30,2003,”Reading Day”);

12 } catch (Exception e) {

13 System.out.println(“Error in initialization: “+e.getMessage());

14 }

15 for(i=0; i ................
................

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

Google Online Preview   Download