Homework Assignment 8

Using Existing Java Classes in Matlab

Due: Friday, October 24, 2003

Write your solutions on separate m files and submit them on WebCT.

Using the MStack Class

a.         Write a Matlab script called reverse that inputs a line of text from the user as a string (Hint: check out the Matlab input( ) function options) and uses a MStack (available in the “Java Examples” download) object to write out that line in reverse order.

b.         Write a Matlab script called is_palindrome that inputs a line of text from the user as a string and uses a MStack object to determine whether the string is a palindrome (spelled the same forwards and backwards)  Since the answer will be either true or false, the m-function should return a 0 or 1 value.  Test your script by entering the following strings:

'' -> true (1)

'A' -> true (1)

'George P Burdell' -> false (0)

'George P egroeG' -> true (1)

Using the Queue Class

Write a supermarket checkout lane simulation in Matlab called checkout using a Queue object to represent the customers in a checkout line.  Customers normally arrive at checkout at random intervals between 1 and 4 minutes.  During peak hours, this is every minute. Peak hours for this simulation will be between time values of 360 and 480. They will have from 1 to 100 things in their baskets.  Checkout clerks can average 12 things per minute at checkout. We want a simulation that looks at the line once per minute for 12 hours. Write the simulation according to the following specification:

a.         Write a function rand_gen(m) that consumes a number m and returns a random integer number from 1 to m.  Hint:  check out the Matlab functions rand and ceil

b.         Create a new Queue object.

c.         Use rand_gen to compute the arrival time of the first customer.

d.         Since there are currently no customers in line, the finish time for the current customer is 0.

e.         Write a loop that will terminate after 720 minutes.  Each time through this loop, perform the following:

f.          If this is the arrival time of the next customer, generate the number of items in their basket, and put into the queue an array containing their arrival time and the number of items in their basket. Also, show that the customer arrived with some kind of display message.

g.         If the current customer is finished, check the queue.  If there is a customer in the queue, pull the arrival time and number of items in the basket from the queue, show that customer starting checkout, and calculate the time that customer will finish checkout.

h.         Add to your program so that when the program finishes, you print out the maximum number of customers in the queue and the maximum wait between arriving and finishing checkout.

i.           Plot the queue length and wait time against time of day.

Looking Ahead

Write a short discussion of how you would emulate a number of checkout lanes rather than just one.  What logic would you use to open extra lanes?  What logic would you use to close a lane?  How would you allocate arriving customers to the different lanes?  What characteristic would be most useful to add to the behavior of a Queue to make this task easier? [turn in this discussion as a separate text or Word file].