forked from MissMeriel/ShoppingCenterSystem
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestsDriver.java
More file actions
79 lines (66 loc) · 2.81 KB
/
TestsDriver.java
File metadata and controls
79 lines (66 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package master1;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Random;
public class TestsDriver {
private static BufferedReader br = new BufferedReader(
new InputStreamReader(System.in));
public static void main(String[] args) throws IOException {
ShoppingCenter acme = new ShoppingCenter();
AscendingOrderList<Customer, String> customers = acme.getCustomers();
AscendingOrderList<Item, String> inventory = acme.getInventory();
//AscendingOrderList<Customer, String> customers = new AscendingOrderList<Customer, String>();
//AscendingOrderList<Item, String> inventory = new AscendingOrderList<Item, String>();
// inventory = generateRandomInventory(5);
customers = generateTestCustomers(customers);
// System.out.println(customers.toString());
// System.out.println(inventory.toString());
// System.out.println("customers.get(-1);");
// customers.get(-1);
//String item_name = br.readLine().trim();
try {
Customer cust;
System.out.print("customers.search(Alpha): ");
int alphaIndex = (customers.search("Alpha"));
System.out.println(alphaIndex);
System.out.print("customers.get(alphaIndex): ");
System.out.println(cust = customers.get(alphaIndex));
int bananaIndex = inventory.search("Banana");
System.out.println("inventory.search(Banana): "+bananaIndex);
Item item = inventory.get(bananaIndex);
System.out.println("banana: "+item.toString());
item.adjustCurrentStock(-1);
System.out.println(inventory.toString());
}
catch (ListIndexOutOfBoundsException e) {
System.out.println(e.getMessage());
}
} //end main
public static AscendingOrderList<Customer, String> generateTestCustomers(AscendingOrderList<Customer, String> customers) {
customers.add(new Customer("Alpha"));
customers.add(new Customer("Lima"));
customers.add(new Customer("Romeo"));
customers.add(new Customer("Sierra"));
customers.add(new Customer("Zulu"));
return customers;
}
public static AscendingOrderList<Item, String> generateRandomInventory(int numberOfItems) {
AscendingOrderList<Item, String> randomInventory = new AscendingOrderList<Item, String>();
Random random = new Random();
String word_string = "";
char[] word;
for(int i = 0; i < numberOfItems; i++)
{
word_string = "";
word = new char[random.nextInt(3)+3]; // words of length 3 through 5. (1 and 2 letter words are boring.)
for(int j = 0; j < word.length; j++)
{
word_string += (char)('a' + random.nextInt(26));
// word[j] = (char)('a' + random.nextInt(26));
}
randomInventory.add(new Item(word_string, random.nextInt(15), random.nextInt(50)));
}
return randomInventory;
}
}