Data Abstraction and Abstract Data Types
1
Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale tessema.mengistu@siu.edu Room - 3131
Data Abstraction and Abstract Data Types Tessema M. Mengistu - - PowerPoint PPT Presentation
Data Abstraction and Abstract Data Types Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale tessema.mengistu@siu.edu Room - 3131 1 Outline Abstract Data types (ADT) ADT Design Specification
1
Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale tessema.mengistu@siu.edu Room - 3131
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public class OnlineShopper { public static void main(String[] args) { Item[] items = {new Item("Bird feeder", 2050), new Item("Squirrel guard", 1547), new Item("Bird bath", 4499), new Item("Sunflower seeds", 1295)}; BagInterface<Item> shoppingCart = new Bag<Item>(); int totalCost = 0; for (int index = 0; index < items.length; index++) { Item nextItem = items[index]; // simulate getting item from shoppingCart.add(nextItem); totalCost = totalCost + nextItem.getPrice(); } // end for while (!shoppingCart.isEmpty()) { System.out.println(shoppingCart.remove()); System.out.println("Total cost: " + "\t$" + totalCost / 100 + "." + totalCost % 100); } }
23
24
25
26
27
28