forked from rileyalankirk/food-truck-simulation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
executable file
·47 lines (37 loc) · 1.54 KB
/
Main.java
File metadata and controls
executable file
·47 lines (37 loc) · 1.54 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
package Simulation;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.PriorityQueue;
public class Main
{
public static final String FILE = "AddressList100.txt";
public static void main(String[] args)
{
// Write 100 random addresses to a file
AddressIO.writeAddresses(FILE, 100);
// Read the addresses from the file and place them in a PriorityQueue
PriorityQueue<Address> addresses = AddressIO.readAddresses(FILE);
// Draw the neighborhood with the addresses and distribution center shown
Neighborhood neighborhood = new Neighborhood();
neighborhood.generateNeighborhood(addresses);
// neighborhood.printNeighborhood();
// Put the addresses into a list
Iterator<Address> iterator = addresses.iterator();
ArrayList<Address> addressList = new ArrayList<>();
while (iterator.hasNext())
addressList.add(iterator.next());
// Add the distribution center as the final destination
addressList.add(new Address(Address.DISTRIBUTION_HOUSENUM, Address.SOUTH, Address.DISTRIBUTION_STREETNUM, 1900));
// Create the route the truck will follow and calculate the length of the trip
try
{
neighborhood.addRoute(addressList);
}
catch (UTurnException ute)
{
System.out.println("UTurnException occurred.");
}
System.out.println("Route length: " + neighborhood.getRouteLength());
Neighborhood.drawNeighborhood(addresses);
}
}