|
|
Store
Background:
We will use these classes to load and manipulate data stored in a text file named file50.txt.
public class Item{
private int myId;
private int myInv;
public Item(int id, int inv){
myId = id;
myInv = inv;
}
public int getId(){}
public int getInv(){}
public int compareTo(Item other){ }
public boolean equals(Item other){ }
public String toString(){}
}
public class Store{
private ArrayList <Item> myStore = new ArrayList <Item>();
public Store(String fName){ }
public Store(){}
private void loadFile(String inFileName){ }
public void displayStore(){}
public String toString(){}
public void Sort(){} //to get recursive sort going
private void merge(ArrayList <Item> a, int first, int mid, int last){}
public void mergeSort(ArrayList <Item> a, int first, int last){ }
private void swap(ArrayList <Item> list, int a, int b){}
}
The file, file50.txt, contains a list of id/inventory integer pairs - one pair per line. The idea behind the data type Item is to simulate an item in a store that is being tracked with a bar code id number (or value) for identification purposes. Each item in the store is tracked with both an id value and an inventory amount. Each id value in file50.txt is unique. So file50.txt looks like this:
3679 87
196 60
17914 12
18618 64
2370 65
... ...
etc. (for 45 more lines)
Assignment:
- Write a
Store class capable of doing each of the following:
- load the data file, file50.txt by default, as a collection of Item types
- sort the data, in increasing order of id number
- print the data, in order
The printed output should add a blank line after every 10 items for better readability. Include a line number in the output. For example:
|
Id |
Inv |
1 |
184
|
14
|
2 |
196
|
60
|
3 |
206
|
31
|
4 |
584
|
85
|
5 |
768
|
85
|
6 |
2370
|
65
|
7 |
3433
|
5
|
8 |
3679
|
87
|
9 |
4329
|
64
|
10 |
5529
|
11
|
|
|
|
11 |
6265
|
58
|
12 |
6835
|
94
|
13 |
6992
|
76
|
14 |
7282
|
73
|
15 |
8303
|
90
|
16 |
9267
|
68
|
etc. |
|
|
-
You will need to complete the getId() , getInv() , compareTo() , equals() and toString() methods for the Item class.
-
You will need to complete the Store() constructor, displayStore() , loadFile() , mergeSort() and toString() methods for the Store class.
|