CMSC132 Fall 2007 Midterm 2 First Name Last Name Grader Use Only 1 Software Development Testing 17 2 Object Oriented Programming 12 3 Object Oriented Design UML 15 4 Threads Synchronization 11 5 GUIs Event Driven Programming 6 6 Heaps 9 7 Huffman Trees 6 8 Graphs 14 9 Binary Trees Recursion 10 Total 100 Honors 16 Student ID Discussion Section Time Discussion Section TA Name 5 points if time is blank or incorrect I pledge on my honor that I have not given or received any unauthorized assistance on this examination Your signature General Rules This exam is closed book and closed notes If you have a question please raise your hand Answer True False questions by circling the T or F at the end of the question Note 1 point if correct 1 point if incorrect 0 point if no answer given Answer fill in the blank questions with 1 or 2 words Note Longer answers are not necessary and will be penalized Answer essay questions concisely using 1 or 2 sentences Note Longer answers are not necessary and will be penalized WRITE NEATLY Unreadable answers will not be graded i e 0 points Honors section questions only count for credit for students in the honors section 1 1 17 pts Software Development Testing a b c d e f g h i j k l m n o p q Software is expensive to produce due to poor computer science instruction Software is expensive to produce due to lack of good programming languages Commonly used software can require millions of source lines of code Maintenance is considered a component of the software life cycle The goal of program design is to select the algorithms and data structures used Software process models are codified sets of practices for software development The Waterfall model begins a new step only when the previous step is complete The Waterfall model uses software prototypes to assess progress The Waterfall model is more appropriate for small software projects The Iterative model emphasizes the ability to adapt to changes The Agile model divides software development into 4 major phases Pair programming is a practice associated with Extreme Programming Formal methods are mathematically based techniques used for high integrity systems Empirical testing will find up to 90 of run time errors in a program Integration testing tests individual methods to ensure their integrity Regression testing ensures functionality is not lost when software is bought sold Test coverage measures whether code is executed by some test case T or F T or F T or F T or F T or F T or F T or F T or F T or F T or F T or F T or F T or F T or F T or F T or F T or F 2 12 pts Object Oriented Programming OOP a b c d e f g h i j k l Abstraction provides a high level model of a physical entity Encapsulation makes code modification easier but reduces code reuse Improvements in compiler technology help make OO Programming more usable Objects in OO systems posses state behavior and quantity Classes in OO programming provide types for objects Inheritance describes a relationship between related classes Inheritance does not affect code reuse in OO systems Specification is a form of inheritance implemented using abstract methods in Java Limitation is a form of inheritance implemented using method overriding in Java Java lacks multiple inheritance but can simulate it via interfaces Nouns in a problem statement usually become methods in OO code In OO systems invoking an object s method is equivalent to sending the object a message 2 T or F T or F T or F T or F T or F T or F T or F T or F T or F T or F T or F T or F 3 15 pts Object Oriented Design Given the following problem description produce an object oriented solution Include as many details as possible Draw a UML class diagram you may write code for Java classes if you don t know UML but will lose points if you do so Use features of UML described in lecture You must write a program to keep track of sandwiches ordered by students in a school cafeteria Sandwich ingredients include slices of bread cheese ham and chicken Each ingredient has its own cost The cafeteria offers veggie and non veggie sandwiches Veggies sandwiches are made from slices of cheese Non veggie sandwiches are made from slices of ham or chicken All sandwiches are made using 2 slices of bread Students may order multiple sandwiches at a time Students may also request 1 extra slice of ham or chicken on their non veggie sandwich but cannot mix ham and chicken Some students are vegetarians and will only order veggie sandwiches Your program should track the following number and type of sandwiches ordered by each student cost of each sandwich total cost for each student total cost of sandwiches for vegetarian students total cost of sandwiches for all students and the amount of each sandwich ingredients used by the cafeteria 3 4 11 pts Threads Synchronization a b c d e f g h i Each thread sequentially execute programs as streams of instructions in memory T or F Each thread has its own address space containing variables data T or F Multithreaded code may be simpler than non multithreaded code T or F Two scheduling approaches are preemptive and non preemptive T or F The preferred approach for creating a threaded class is by extending the Thread class T or F The join method is used by Java threads to wait for other threads to terminate T or F A thread can acquire only one lock at a time T or F A lock can be acquired by only one thread at a time T or F 3 pts The class MyTask implements the Runnable interface Define and start one thread myT below using the MyTask class You can assume the MyTask has a default constructor Thread myT 5 6 pts GUIs Event Driven Programming and Java Support for GUIs a In the software model for GUI design the view component performs the actual work b In Java the JTable class represents a part of the view component c An inner class can access all the methods and instance variables of the outer class d 3 pts In Java the ActionListener interface requires the method T or F T or F T or F void actionPerformed ActionEvent e be implemented Create an anonymous inner class implementing the ActionListener interface for the following Java component GUIcomponent addActionListener CREATE ANONYMOUS INNER CLASS HERE 4 6 9 pts Heaps Use the following heap to answer the questions that follow 5 8 1 4 9 1 5 a 1 pts Draw the heap as an array b 2 pts Draw the heap that would result from inserting 3 in the above heap c 2 pts Draw the heap that would result by deleting 5 from the original heap For a heap designed to
View Full Document
Unlocking...