DATA STRUCTURES IN JAVA A Laboratory Course phần 10 doc

44 378 0
DATA STRUCTURES IN JAVA A Laboratory Course phần 10 doc

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

LABORATORY 15 364 Step 3: Plot your results below. 1,000 2,000 3,000 4,000 Number of keys in the list (numKeys) Search time (ms) LABORATORY 15 365 Step 4: How well do your measured times conform with the order-of-magnitude estimates given for the selectionSort() and quickSort() routines? Step 5: Using the code in the file Sort.java and your measured execution times as a basis, develop an order-of-magnitude estimate of the execution time of the unknownSort() routine. Briefly explain your reasoning behind this estimate. TEAMFLY Team-Fly ® LABORATORY 15 366 LABORATORY 15: In-lab Exercise 3 Name Hour/Period/Section Date In this exercise, you measure the performance of the array and linked list implementations of the Stack ADT that you created in Laboratory 5. Step 1: Using the implementation of the Timer ADT that you created in the Prelab as a foun- dation, write a program that measures the time it takes to completely fill and then empty a 10,000-element stack using the push and pop operations in Stack ADT. Assuming testStack is of type Stack, you can use the following statement to print whether you are testing the class AStack or LStack: System.out.println("Testing the " + testStack.getClass( )); Save your file as TimeStack.java. Because these operations execute so rapidly, you may need to fill and empty the stack a number of times in order to produce an accurate measurement of the time it takes to complete a fill/empty cycle. Step 2: Use your program to measure the time it takes each of your Stack ADT implementa- tions to fill and empty a stack containing 10,000 characters and record the results in the follow- ing table. LABORATORY 15 367 Step 3: Repeat these measurements using a stack containing 10,000 long integers and record the results below. Stack ADT implementation Stack Element char long int Array implementation Linked list implementation Note : Times shown are in milliseconds. Time to Fill and Empty a 10,000-Element Stack LABORATORY 15 369 LABORATORY 15: Postlab Exercise 1 Name Hour/Period/Section Date You are given another pair of searching routines. Both routines have order-of-magnitude exe- cution time estimates of O(N). When you measure the actual execution times of these routines on a given system using a variety of different data sets, you discover that one routine consis- tently executes five times faster than the other. How can both routines be O(N), yet have dif- ferent execution times when they are compared using the same system and the same data? LABORATORY 15 370 LABORATORY 15: Postlab Exercise 2 Name Hour/Period/Section Date Using your measurements from In-lab Exercises 1 and 2 as a basis, estimate the execution times of the routines listed below for a randomly generated list of 8,000 integer keys. Do not measure the actual execution times of these routines using a list of this size. Estimate what their exe- cution times will be based on the measurements you have already done. Briefly explain your reasoning behind each estimate. Routine Number of keys in the list (numKeys) = 8000 linearSearch( ) Estimated execution time: Explanation: binarySearch( ) Estimated execution time: Explanation: Note : Times shown are in milliseconds. Execution Times of a Set of Sorting Routines LABORATORY 15 371 Routine Number of keys in the list (numKeys) = 8000 selectionSort( ) Estimated execution time: Explanation: quickSort( ) Estimated execution time: Explanation: Note : Times shown are in milliseconds. Execution Times of a Set of Sorting Routines 373 LABORATORY 16 16 Team Software Development Project OBJECTIVES In this laboratory, you • see how a complex problem can be solved by decomposing it into a set of interrelated objects. • get a feel for the dynamics of a team programming environment. • learn some object-oriented analysis and design (OOAD) techniques. • create and implement a program design for a given complex problem. OVERVIEW The programs you developed in previous labs solved very specific problems. These programs tended to be relatively short and you were able to create them by yourself directly from the problem descriptions. As problems become more complex, however, team programming efforts and formal program designs become necessary parts of the program development process. In this laboratory, you work with other students as part a software development team that designs and implements a programming project using established OOAD techniques. This program development process is done over the space of two weeks. During the first week, you work with your teammates to create a program design. In the second week, you implement your design to form a working program. [...]... using a Java class called Face in which the happy/sad attribute is 376 LABORATORY 16 represented by an integer data member state and the behaviors are represented by the class methods display(), makeHappy(), and makeSad() An incomplete definition/implementation for the Face class and the specifications for its class methods are shown below Note that we have included a constructor that initializes a face... Displays a calculator We create the Interface class in much the same way we did the Calculator and Face classes In this case, we represent the calculator, face, and command attributes by three data members: calc, smiley, and userCmd class Interface { // Data members private Calculator calc; private Face smiley; private Command userCmd; // Calculator object // Face object // User command } All the data members... members in the Interface class are objects in other classes rather than one of Java s predefined data types We have already defined two of these classes The userCmd data member stores the last command the user entered along with the command’s argument (if any) in the class Command The Command class is defined below Note that its data members are not 379 LABORATORY 16 declared private, so they are treated as... the files Calculator .java, Face .java, and Interface .java, respectively The implementation for the Command class may also be placed in the Interface .java file Let’s start the implementation process with the Calculator class The methods of this class are quite simple—no surprises here The display() method forms the calculator using standard ASCII characters This approach allows for generality of use—every... of an image and a calendar day grid In addition, the notes for each month are output in ascending order based on day Default: horizontal User Interface Your program begins by prompting the user for the name of a noteboard (.nbd) file It then reads in the calendar year, the calendar image file names, and the entire set of notes, grouping the notes by month as they are read in You can assume that there are... coordinate the actions of the Calculator and Face objects based on the command input by the child This object is commonly called the interface Object: Interface Attributes: Calculator Face Command Behaviors: Coordinates the calculator and face displays Reads a command Executes the command Now that we have identified a set of objects, we need to develop a Java class for each object As a general rule, an... object/class: Attributes: Behaviors: 393 LABORATORY 16 Team member (name): Proposed object/class: Attributes: Behaviors: Proposed object/class: Attributes: Behaviors: 394 LABORATORY 16 Test Plan for the class Expected result Checked AM FL Y Sample data TE Test case Team-Fly® 395 LABORATORY 16 Test Plan for the Calendar/Noteboard Programming Project Test case 396 Sample data Expected result Checked LABORATORY. .. constant Default: black Layout of the noteboard display, where style is either horizontal or vertical The corresponding layouts are illustrated below vertical horizontal January January January calendar calendar notes January notes February February February calendar calendar notes February notes December December December calendar calendar notes December notes In either layout, each month’s calendar... by other classes in this Java package or subdirectory class Command { // Data Members char cmd; double arg; } // Command name (letter) // Command argument We represent the Interface object’s behaviors by the class methods generateDisplay(), getCommand(), and executeCommand() To these we add a constructor that initializes the data members and a done() method that indicates when the child has entered... “happy” and “sad” incarnations that are commonly used in textual e-mail messages public void display ( ) // Displays a face { if ( state == 1 ) System.out.print( ":-)"); else System.out.print(":-("); } Implementing the Interface class is a little trickier Recall that this class has three data members: calc, smiley, and userCmd The Interface class constructor must correctly initialize all these data members . or to sad. We represent the Face object using a Java class called Face in which the happy/sad attribute is LABORATORY 16 377 represented by an integer data member state and the behaviors are represented. Creates an interface and initializes its data members. void generateDisplay ( ) Precondition: None. Postcondition: Generates an interface display consisting of a calculator and a happy/sad face. void. classes. In this case, we represent the calculator, face, and command attributes by three data members: calc, smiley, and userCmd. class Interface { // Data members private Calculator calc;

Ngày đăng: 12/08/2014, 16:21

Từ khóa liên quan

Mục lục

  • Performance Evaluation

    • LABORATORY 15: In-lab Exercise 3

    • Time to Fill and Empty a 10,000-Element Stack

    • LABORATORY 15: Postlab Exercise 1

    • LABORATORY 15: Postlab Exercise 2

    • Execution Times of a Set of Sorting Routines

    • Execution Times of a Set of Sorting Routines

    • LABORATORY

    • Team Software Development Project

      • LABORATORY 16 Ñ Week 1: Prelab Exercise 1

      • LABORATORY 16 Ñ Week 1: Prelab Exercise 2

      • LABORATORY 16 Ñ Week 1: Bridge Exercise

      • LABORATORY 16 Ñ Week 1: Project Cover Sheet

      • Test Plan for the class

      • Test Plan for the Calendar/Noteboard Programming

      • Project

      • LABORATORY 16 Ñ Week 1: In-lab Exercise

      • LABORATORY 16 Ñ Week 2: Project Cover Sheet

      • LABORATORY 16 Ñ Week 2: In-lab Exercise

      • LABORATORY 16 Ñ Postlab Exercise

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan