Download presentation

Presentation is loading. Please wait.

Published byMaleah Bodily Modified over 3 years ago

1
CS 2511 Fall 2014

2
Class Diagrams public class ClassX extends ClassW { … public ClassY getY() … private ClassZ localZ; } Draw the Class Diagram. ClassX ClassW ClassY ClassZ

3
Binary Heaps Draw the Binary Heap corresponding to the array above as a tree structure. 243879141610 123456789 11120 Array Index Array Value 2 4 3 87914 1610

4
Binary Heaps (cont.) Draw the heap (as a tree structure) after one priority queue removal. Original: 2 4 3 87914 1610 4 3 87 9 14 16 10

5
Class Example Suppose we want to define an interface type called BankAccount whose values can be objects that have balances like SavingsAccount and CheckingAccount: > BankAccount getBalance(): double SavingsAccountCheckingAccount

6
Class Example (cont.) Define the BankAccount interface public interface BankAccount { double getBalance(); }

7
Class Example (cont.) Define the SavingsAccount Class public class SavingsAccount implements BankAccount { private double balance; public SavingsAccount(double startingBalance) { balance = startingBalance; } public double getBalance() { return balance; }

8
Class Example (cont.) We want to be able to compare bank accounts on the basis of their balances (use the Comparable interface). Redefine BankAccount to reflect the change. public interface BankAccount extends Comparable { double getBalance(); }

9
Class Example (cont.) Define the compareTo method that must be added to the SavingsAccount and CheckingAccount Classes. public int compareTo(BankAccount other) { if(getBalance() < other.getBalance()) return -1; else if(getBalance() > other.getBalance()) return 1; else return 0; }

10
Class Example (cont.) SavingsAccount and CheckingAccount now share an identical compareTo method. Draw a modified class diagram that incorporates a class called AbastractAccount that implements BankAccount and from which SavingsAccount and CheckingAccount inherit the compareTo method

11
Class Example (cont.) > BankAccount getBalance(): double SavingsAccountCheckingAccount > Comparable compareTo(T other): int AbstractAccount

12
Class Example (cont.) What Design Pattern does AbstractAccount exemplify? Template method

13
Button Listeners/UML Sequence Diagrams Write the class definition for the ButtonListener for the following scenario: There is a button that initially has the text “Start” When the user clicks the button, the text should change to “Stop” When the user clicks the “Stop” button, the text should change to “Start”

14
Button Listeners/UML Sequence Diagrams (cont.) class ButtonListener implements ActionListener { private JButton button; public ButtonListener(JButton b) { button = b; } public void actionPerformed(ActionEvent e) { if ( button.getText().equals("Start") ) { button.setText("Stop"); } else { button.setText("Start"); }

15
Button Listeners/UML Sequence Diagrams (cont.) Given the following test class: public class ButtonTest { public static void main(String[] args) { JButton button = new JButton("Start"); button.addActionListener(new ButtonListener(button)); JFrame frame = new JFrame(“Button Test"); frame.getContentPane().add(button); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(200, 100); frame.show(); } Draw a UML Sequence Diagram for the Main method

16
Button Listeners/UML Sequence Diagrams (cont.)

17
Hash Tables Consider the hash table of capacity 10 below. Suppose that for integer key k and table capacity c, we define the hash function h(k) = k mod c. Show how the hash table looks after elements with the following keys are inserted into the table in the following order: 99, 161, 2, 44, 88, 54, 23, 84 Show just the keys

18
Hash Tables (cont.) 0 1 2 3 4 5 6 7 8 9 99 161 2 44 88 54 23 84

19
Analysis A _____ is/does the following: Completely defines tasks to be solved Free from internal contradictions Readable both by domain experts and software developers Reviewable by diverse interested parties Testable against reality Options: Functional Specifications Use Case

20
Design

21
Implementation

22
Data Structures In an array Implementation of a Binary Heap, if a node is located at index i of the array A its parent (if any) is located at: A[i-1] A[i-2] A[i*2] A[i/2]

23
Data Structures The time it takes to do an add operation in a Binary Heap where n is the number of nodes in the heap is: O(n^2) O(n) O(n*log(n)) O(log(n))

24
Data Structures In an array Implementation of a Binary Heap, if a node is located at index i of the array A its left child (if any) is located at: A[i-1] A[i-2] A[i*2] A[i/2]

25
Data Structures A disadvantage of using adjacency matrix representation for a sparse graph is: Memory usage is O(v^2) where v is the number of vertices Memory usage is O(v+e) where v is the number of vertices and e is the number of edges Determining if two edges are connected by an edge takes O(1) time It is well suited for sparse graphs

26
Data Structures What structures are used for the following search types: Breadth-first Depth-first Best-first Queue Stack Priority Queue

27
Data Structures Which is a requirement for a heuristic for the A* search to return an optimal result: Never underestimates the distance to the goal Never overestimates the distance to the goal

28
Design Patterns What design patterns will you use in the following situations? 1.) A change in one object needs to be notified to other objects. 2.) We need to supply different algorithms of a particular type to a component. 3.) Only one object of a class is needed. 4.) Allow a composite object made up of primitive objects to behave similar to how each primitive would behave. 5.) Create different types of objects by overriding one method.

29
Design Pattern Answers 1.) Observer 2.) Strategy 3.) Singleton 4.) Composite 5.) Factory Method

Similar presentations

OK

What is Covered Everything up to and including Lecture 11 Types Recursion (including grammars) Lists and Trees GUIs Does not include Big-O notation (Lecture.

What is Covered Everything up to and including Lecture 11 Types Recursion (including grammars) Lists and Trees GUIs Does not include Big-O notation (Lecture.

© 2018 SlidePlayer.com Inc.

All rights reserved.

To ensure the functioning of the site, we use **cookies**. We share information about your activities on the site with our partners and Google partners: social networks and companies engaged in advertising and web analytics. For more information, see the Privacy Policy and Google Privacy & Terms.
Your consent to our cookies if you continue to use this website.

Ads by Google

Ppt on network switching software Ppt on computer languages list Ppt on social entrepreneurship in india Ppt on world war 1 Ppt on natural resources and associated problems Ppt on electric meter testing school Ppt on object oriented technologies Ppt on 9-11 conspiracy theories video Ppt on acid-base indicators worksheets Project ppt on introduction to business finance