### Abstract

In project 5, Decision-making Simulation: Checkout Lines, one of the main ideas of the project was to use node-based linked lists, node-based doubly linked lists and array lists. The end goal was to utilize our knowledge of these data structures and Queues to simulate customers picking out which checkout line to join. To do so, we needed to create three different algorithms in which we allowed the customers to have different line picking methods. In order to make the different customers and their different methods, we had to utilize the concept of inheritance to make child classes. By having the RandomCustomer class, PickyCustomer class, and Pick2Customer class inherit methods from the Customer class, we saved a lot of repetition. By having the checkout agent act as a queue that added and removed the customers, the checkout lines would shorten and elongate. The customers would hold information which included the number of items they each had and how much time they took. With this information, the RandomCustomer class, PickyCustomer class, and Pick2Customer class would choose which line they wanted. In the end, the display showed rectangles representing the checkout lines changing heights depending on the number of customers. The heights would be constantly changing, either decreasing and increasing or continuously increasing depending on the number of items each customer had.

### Solutions

**RandomCustomer.java**: For this class, the goal was to create a customer that chose a random line. After having the RandomCustomer class inherit its methods from the Customer class, I made the time step 1. This is because the customer only spends time looking at 1 random line. To make the customer choose a random line in the chooseLine() method, I utilized the random class. By setting the variable int randInt to rand.nextInt(checkouts.size()) I made the random class choose a random integer from 0 to the number of checkout lines. randInt would then be given a random checkout line to join. I then returned randInt.**PickyCustomer.java**: For this class, the goal was to create a customer that chose the shortest line out of all the checkout lines. After having the PickyCustomer class inherit its methods from the Customer class, I made the time num_lines. This is because this customer spends time looking at all the individual lines before making a decision. To make this method of choosing I utilized a combination of a for loop and if statement in my chooseLine() method. With a for loop, I checked through all the checkout lines. In order to find the least amount of customers in each line, I utilized an if statement. To start, I made least equal a very large number with Integer.MAX_VALUE. By doing so, the number of customers in the first checkout line would be stated as least and all the other lines can be compared to it. To get the number of customers in each checkout line, I utilized checkouts.get(i).getNumInQueue(). If the number of customers in that checkout line was less than the least, then it would be the new least. In addition, the index of the checkout line will be updated to leastIDX. With the for loop, the program will check the next checkout line and find the number of customers in that line. If that line has fewer customers than the least, then it will become the new least. Also, the index of the checkout line will be updated to leastIDX. If it is has more customers than the least, then the least will remain the least and the program will move on to the next line. The loop will continue to go through all the lines and update the least until there are no more lines to check. In the end, chooseLine() will return leastIDX which is the index of the checkout line with the least amount of customers.**Pick2Customer.java**: The goal of this class was to create a customer that chose two random lines and then chose the shorter of the two lines. After having the Pick2Customer class inherit its methods from the Customer class, I made the time 2. This is because the customer spends time looking at 2 checkout lines in the decision process. The chooseLine() method for this class was interesting because it was a combination of the other two decision-making customers. To choose two random integers, I assigned randInt to rand.nextInt(checkouts.size()) and randInt2 to rand.nextInt(checkouts.size()). By doing so, each variable will have a random checkout line. Because I did not want randInt and randInt2 being the same integer, I created a while loop. While the two random integers were the same, randInt would be assigned a new random integer with rand.nextInt(checkouts.size()). This loop will keep going until the two random integers are different. Once the program had two different random integers, I utilized checkouts.get(randInt).getNumInQueue() to get the number of customers in the first random checkout line and checkouts.get(randInt2).getNumInQueue() to get the number of customers in the second random checkout line. With an if statement I said that if the number of customers in the first random line was less than the number of customers in the second random line, then chooseLine() would return randInt. In any other situation, chooseLine() would return randInt2. As a result, chooseLine() would give the index of the shorter of the two random checkout lines.

### Evaluate the Strategies

In order to make the lines grow very long, I utilized an absurdly high number of items for each customer. I made the number of items for each customer 1+gen.nextInt(100). For example, with Random Customer, I assigned Customer cust = new RandomCustomer(1+gen.nextInt(100)); I gave each customer 100 items. Looking at the simulation, the lines grew very quickly.

In order to find a number of items per customer in which the lines would remain fairly short, I needed a low number of items. For RandomCustomerSimulation I assigned Customer cust = new RandomCustomer(1+gen.nextInt(3));. For PickyCustomerSimulation and Pick2CustomerSimulation I assigned Customer cust = new PickyCustomer(1+gen.nextInt(5)); and Customer cust = new Pick2Customer(1+gen.nextInt(5));. By doing so, the lines remained very short all throughout the simulation.

*RandomCustomerSimulation with 100 items RandomCustomerSimulation with 3 items*

*Statistics for*

*RandomCustomerSimulation with 3 items**PickyCustomerSimulation with 100 items PickyCustomerSimulation with 5 items Statistics for*

*PickyCustomerSimulation with 5 items**Pick2CustomerSimulation with 100 items Pick2CustomerSimulation with 5 items Statistics for*

*Pick2CustomerSimulation with 5 items*### Videos:

*In the following videos, there are 5 checkout lines, 1000 customers, and 10 items per customer*

### Extensions

**Extension #1:**One of the extensions that I took on was making the simulation more visually interesting and informative. To do so I wanted to show the individual customers in each line and display the customer at the end of the line with a different color. By doing so, the display will also be more informative because the viewer would be able to see the number of customers in each line and see the customers being added and removed. To do so, I created a new draw method in CheckoutAgent.java. By utilizing a combination of a for loop and if else statements, I was able to accomplish my goal. Because n represented the number of customers in the queue, the value of this.ypos-20*n would always be at the tail of the queue and therefore be the y position of the last customer in the line. To draw all the customer in the line, I created a for loop that would run through all the customers in the line. Starting from the last customer in the line, I subtracted n by 1 each iteration. By doing so, draw() would draw each customer in the queue until it reached the customer at the head. With the if else statement, I wanted to make the tail a different color. As a result, I stated that if n was equal to getNumInQueue() I would set the color to red. In any other situation, the color would be set to blue. As a result, the last customer would always be red.**Extension #2:**Another extension for my simulation was making the individual customers a fun shape. When doing extension #1, I first made each character a circle. Although that was okay, I wanted to make the simulation visually more appealing by making the customers stars. Utilizing my research on creating shapes in java, I was able to do so. To create the shape, I first graphed my shapes on graphic paper. Then I recorded the coordinates of the shape. I learned that int [] x = {} would hold the x coordinates of the shape and int [] y = {} would hold the y coordinates of the shape. The x and y coordinates would have to be in a corresponding and consecutive order. I then called g.fillPolygon( x, y, 6); The last parameter of g.fillPolygon holds the number of points in the same. I made a star method with the parameters (Graphics g, int x0, int y0) and inputted the int [] x = {} and [] y = {}. Then, I called fillPolygon. After creating the shape method, I added it to the draw method.**Extension #3:**Another extension I did was making ChooseCustomerSimulation.java where the user was able to control the size of the landscape, number of checkout lines, number of customers, number of items per customer, and the checkout line method. To do so, I utilized the scanner class.**Extension #4:**Another extension I did was making ChooseRandomMethodSimulation.java. In this simulation, each customer chooses a random method of choosing the checkout line. To do so, I assigned int randInt to gen.nextInt(3) +1; By doing so, randInt will choose a random number from 1 to 3. With the for loop, each customer will have a random number from 1 to 3. With many if statements, I assigned “1” to the random customer method of choosing, “2” to the picky customer method, and “3” to the pick 2 method. As a result, each customer would receive a random method of choosing a line.

**Extension #5:**For this extension, I analyzed the average number of Customers for each method when the customers has a certain number of items.

EXTENSION #5: Average number of Customers

*In this case, there are 5 Checkout Lines and each Customer has 5 Items*

Checkout line Choosing Method | Line 1 | Line 2 | Line 3 | Line 4 | Line 5 | Average Number of Customers |

Random | 1 | 0 | 2 | 0 | 1 | .8 |

Picky Customer | 1 | 0 | 0 | 1 | 0 | .4 |

Pick 2 Customer | 1 | 0 | 1 | 1 | 1 | .8 |

*In this case, there are 5 Checkout Lines and each Customer has 6 Items*

Checkout line Choosing Method | Line 1 | Line 2 | Line 3 | Line 4 | Line 5 | Average Number of Customers |

Random | 0 | 0 | 1 | 1 | 1 | .6 |

Picky Customer | 0 | 0 | 0 | 0 | 1 | .2 |

Pick 2 Customer | 0 | 1 | 1 | 1 | 1 | .8 |

*In this case, there are 5 Checkout Lines and each Customer has 7 Items*

Checkout line Choosing Method | Line 1 | Line 2 | Line 3 | Line 4 | Line 5 | Average Number of Customers |

Random | 4 | 1 | 0 | 8 | 6 | 3.8 |

Picky Customer | 2 | 0 | 1 | 1 | 1 | 1 |

Pick 2 Customer | 0 | 1 | 1 | 1 | 1 | .8 |

*In this case, there are 5 Checkout Lines and each Customer has 8 Items*

Checkout line Choosing Method | Line 1 | Line 2 | Line 3 | Line 4 | Line 5 | Average Number of Customers |

Random | 3 | 4 | 5 | 8 | 8 | 5.6 |

Picky Customer | 0 | 1 | 1 | 1 | 1 | .8 |

Pick 2 Customer | 3 | 2 | 2 | 2 | 0 | 1.8 |

**CONCLUSION:** Because of my extension, I was able to see the number of customers in each line rather than measure out the line length. As a result, I was able to count the number of customers to see which line was longest and shortest. The Picky Customer was always most efficient. It had the least average amount of Customers in each line. When customers have less items, Random is either more efficient or equal to Pick 2 Customer. However, as the number of items increase, Pick 2 Customer becomes significantly more efficient.

**Extension #6:**For this extension, I analyzed whether the number of items a customer has a relation to the average time spent.

**EXTENSION #6:** Is the amount of time a Customer spends in line is related to the number of items he has?

*In this case there are 5 Checkout Lines.*

Random

Number of Items | Average Total Time Spent per customer at end of Simulation |

3 | 3 |

5 | 6 |

10 | 72 |

Picky Customer

Number of Items | Average Total Time Spent per customer at end of Simulation |

3 | 6 |

5 | 7 |

10 | 50 |

Pick 2

Number of Items | Average Total Time Spent per customer at end of Simulation |

3 | 4 |

5 | 5 |

10 | 47 |

**CONCLUSION:** There is definitely a correlation between the number of Items per customer and the average time spent for a customer. As the number of items increase, the customer spends a longer time. Looking at the three different strategies, customers with many items would spend the shortest amount of time if they chose two random lines and chose the shorter of the two. Customers with many items would spend the longest amount of time if they all chose the lines at random. However, if the customers had very few items, they would spend a shorter amount of time if they chose the checkout line at random. With few items, the customers would spend the longest time if they picked the shortest line.

### Conclusion

By the end of this project, I have become more familiar with linked lists, nodes, array lists, and inheritance. It was interesting and challenging to make a checkout line simulation, especially because this simulation reflects something that would happen in real life. In real life, I would choose the method of choosing the shortest line of all the checkout lines. However, with this simulation that this method may not be the more time efficient depending on the amount of items I have and other customers have.

### A list of people you worked with, including TAs, and instructors. Include in that list anyone whose code you may have seen, such as those of friends who have taken the course in a previous semester.

Deka

TA: Riley

TA: Ethan

Bret

http://faculty.salina.k-state.edu/tmertz/Java/072graphicscolorfont/10polygons.pdf

- https://docs.oracle.com/javase/7/docs/api/java/awt/Graphics.html#drawPolygon(int[],%20int[],%20int)