intermediate/Queue2009

From ggc

Jump to: navigation, search

01 package intermediate;
02 //start auto-imports
03 import java.util.*;
04 import java.awt.event.*;
05 //end auto-imports
06 
07 
08 /**
09  * All about my application.
10  @author Jam Jenkins
11  */
12 public class Queue2009
13 {
14   private Queue<Customer2009>[] lines;
15   private Associate[] cashier;
16   private Timer timer;
17   private CustomerEntrance task;
18   private long serviceTime;
19 
20   public Queue2009(int numberOfLines, long averageInterarrivalRate, long averageServiceTime)
21   {
22     serviceTime=averageServiceTime;
23     lines=new Queue<Customer2009>[numberOfLines];
24     cashier=new Associate[numberOfLines];
25     for(int i=0; i<lines.length; i++)
26     {
27       lines[i]=new Queue<Customer2009>();
28       cashier[i]=new Associate(averageServiceTime);
29     }
30     timer=new Timer();
31     CustomerEntrance entrance=new CustomerEntrance();
32     timer.schedule(entrance, (long)(Math.random()*averageInterarrivalRate*2));
33   }
34 
35   class CustomerEntrance extends TimeTask
36   {
37     public void actionPerformed(ActionEvent e)
38     {
39       Customer2009 customer=new Customer2009();
40       int smallest=0;
41       for(int i=1; i<lines.length(); i++)
42       {
43         if(lines[i].size()<lines[smallest].size())
44         {
45           smallest=i;
46         }
47       }
48       customer.joinQueue();
49       lines[smallest].add(customer);
50       if(lines[smallest].size()==1)
51       {
52         customer.startService();
53         long timeToServe=(long)(2*Math.random()*serviceTime);
54         timer.schedule(new Service(smallest), timeToServe);
55       }
56     }
57   }
58 
59   class Service extends TimerTask
60   {
61     private int index;
62 
63     public Service(int i)
64     {
65       index=i;
66     }
67 
68     public void actionPerformed(ActionEvent e)
69     {
70       Customer customer=lines[index].remove();
71       customer.finishService();
72       if(lines[index].size()>0)
73       {
74         long timeToServe=(long)(2*Math.random()*serviceTime);
75         timer.schedule(new Service(smallest), timeToServe);
76         schedule(this, timeToServe);
77       }
78     }
79   }
80 
81   public static void main(String[] args)
82   {
83     System.out.println("Hello JavaWIDE!");
84   }
85 }

Compiler Errors:
----------
1. ERROR in intermediate/Queue2009.java (at line 15)
	private Associate[] cashier;
	        ^^^^^^^^^
Associate cannot be resolved to a type
----------
2. ERROR in intermediate/Queue2009.java (at line 23)
	lines=new Queue<Customer2009>[numberOfLines];
	      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The method schedule(Queue2009.Service, long) is undefined for the type Queue2009.Service
----------
15 problems (15 errors)

Download/View intermediate/Queue2009.java




Views
Personal tools
Add to 
del.icio.usAdd to 
diggAdd to 
FacebookAdd to 
favoritesAdd to 
GoogleAdd to 
MySpaceAdd to 
PrintAdd to 
SlashdotAdd to 
StumbleUponAdd to 
Twitter