From ggc
|
001 packagepackage is used to name the directory or folder a class is in intermediate;
002 //start auto-imports
003 importimport means to make the classes and/or packages available in this program java.sql.*;
004 //end auto-imports
005 //start auto-imports
006 importimport means to make the classes and/or packages available in this program java.awt.event.*;
007 importimport means to make the classes and/or packages available in this program java.util.*;
008 //end auto-imports
009
010
011 /**
012 * All about my application.
013 * @authorthis is the Javadoc tag for documenting who created the source code Jam Jenkins
014 */
015 publicpublic is used to indicate unrestricted access (any other class can have access) classclass is a group of fields and methods used for making objects SingleQueue2009
016 {open braces start code blocks and must be matched with a close brace
017 privateprivate is used to restrict access to the current class only Queue<Customer2009> queue;
018 privateprivate is used to restrict access to the current class only ArrayList<Customer2009> doneCustomers;
019 privateprivate is used to restrict access to the current class only longlong is the type for whole numbers (they have a larger range than int) interarrivalRate;
020 privateprivate is used to restrict access to the current class only longlong is the type for whole numbers (they have a larger range than int) serviceTime;
021 privateprivate is used to restrict access to the current class only longlong is the type for whole numbers (they have a larger range than int) endSimulationTime;
022 privateprivate is used to restrict access to the current class only longlong is the type for whole numbers (they have a larger range than int) totalTime;
023
024 publicpublic is used to indicate unrestricted access (any other class can have access) SingleQueue2009()
025 {open braces start code blocks and must be matched with a close brace
026 interarrivalRate=this assignment operator makes the left side equal to the right side300;
027 serviceTime=this assignment operator makes the left side equal to the right side150;
028 queue=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor LinkedList<Customer2009>();
029 doneCustomers=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ArrayList<Customer2009>();
030 }close braces end code blocks and must match an earlier open brace
031
032 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value simulate(longlong is the type for whole numbers (they have a larger range than int) duration)
033 {open braces start code blocks and must be matched with a close brace
034 totalTime=this assignment operator makes the left side equal to the right sideduration;
035 endSimulationTime=this assignment operator makes the left side equal to the right sideSystem.currentTimeMillis()+adds two numbers together or concatenates Strings togetherduration;
036 javax.swing.Timer enterQueue=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor javax.swing.Timer(0, newnew is used to create objects by calling the constructor Act());
037 enterQueue.start();
038 //do for duration:
039 //make a customer enter the queue on average every so many seconds
040 //so long as someone is in the queue, the cashier provides service
041 //when the cashier finishes one customer, they start the next
042 }close braces end code blocks and must match an earlier open brace
043
044 publicpublic is used to indicate unrestricted access (any other class can have access) intint is the type for whole numbers and it is short for integer getDurationBetweenCustomers()
045 {open braces start code blocks and must be matched with a close brace
046 returnreturn means to provide the result of the method and/or cease execution of the method immediately (intint is the type for whole numbers and it is short for integer)(2*Math.random()*interarrivalRate);
047 }close braces end code blocks and must match an earlier open brace
048
049 publicpublic is used to indicate unrestricted access (any other class can have access) intint is the type for whole numbers and it is short for integer getDurationOfService()
050 {open braces start code blocks and must be matched with a close brace
051 returnreturn means to provide the result of the method and/or cease execution of the method immediately (intint is the type for whole numbers and it is short for integer)(2*Math.random()*serviceTime);
052 }close braces end code blocks and must match an earlier open brace
053
054 publicpublic is used to indicate unrestricted access (any other class can have access) classclass is a group of fields and methods used for making objects Act implementsimplements means providing method bodies for the methods declared in the corresponding interface ActionListener
055 {open braces start code blocks and must be matched with a close brace
056 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value actionPerformed(ActionEvent e)
057 {open braces start code blocks and must be matched with a close brace
058 ifif executes the next statement only if the condition in parenthesis evaluates to true(System.currentTimeMillis()>=this evaluates to true if the left side is not less than the right sideendSimulationTime)
059 {open braces start code blocks and must be matched with a close brace
060 ((javax.swing.Timer)e.getSource()).stop();
061 System.out.println("done");
062 returnreturn means to provide the result of the method and/or cease execution of the method immediately;
063 }close braces end code blocks and must match an earlier open brace
064 Customer2009 customer=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Customer2009();
065 customer.joinQueue();
066 queue.offer(customer);
067 intint is the type for whole numbers and it is short for integer between=this assignment operator makes the left side equal to the right sidegetDurationBetweenCustomers();
068 ((javax.swing.Timer)e.getSource()).setDelay(between);
069 //System.out.println("Time elapsed: "+between+" Customer entering queue at time "+
070 // System.currentTimeMillis());
071 //System.out.println("Queue size: "+queue.size());
072 ifif executes the next statement only if the condition in parenthesis evaluates to true(queue.size()==this is the comparison operator which evaluates to true if both sides are the same1)
073 {open braces start code blocks and must be matched with a close brace
074 customer.startService();
075 javax.swing.Timer server=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor javax.swing.Timer(getDurationOfService(), newnew is used to create objects by calling the constructor Serve());
076 server.start();
077 }close braces end code blocks and must match an earlier open brace
078 }close braces end code blocks and must match an earlier open brace
079 }close braces end code blocks and must match an earlier open brace
080
081 publicpublic is used to indicate unrestricted access (any other class can have access) classclass is a group of fields and methods used for making objects Serve implementsimplements means providing method bodies for the methods declared in the corresponding interface ActionListener
082 {open braces start code blocks and must be matched with a close brace
083 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value actionPerformed(ActionEvent e)
084 {open braces start code blocks and must be matched with a close brace
085 ifif executes the next statement only if the condition in parenthesis evaluates to true(System.currentTimeMillis()>=this evaluates to true if the left side is not less than the right sideendSimulationTime)
086 {open braces start code blocks and must be matched with a close brace
087 ((javax.swing.Timer)e.getSource()).stop();
088 System.out.println("done");
089 returnreturn means to provide the result of the method and/or cease execution of the method immediately;
090 }close braces end code blocks and must match an earlier open brace
091 //System.out.println("Customer leaves queue");
092 Customer2009 customer=this assignment operator makes the left side equal to the right sidequeue.remove();
093 customer.finishService();
094 System.out.println("adding to done");
095 doneCustomers.add(customer);
096 //System.out.println("Queue size: "+queue.size());
097 ifif executes the next statement only if the condition in parenthesis evaluates to true(queue.size()>0)
098 {open braces start code blocks and must be matched with a close brace
099 //System.out.println("Customer starts service");
100 queue.peek().startService();
101 intint is the type for whole numbers and it is short for integer between=this assignment operator makes the left side equal to the right sidegetDurationOfService();
102 ((javax.swing.Timer)e.getSource()).setDelay(between);
103 //System.out.println("Queue size: "+queue.size());
104 }close braces end code blocks and must match an earlier open brace
105 elseelse is what happens when the if condition is false
106 {open braces start code blocks and must be matched with a close brace
107 ((javax.swing.Timer)e.getSource()).stop();
108
109 }close braces end code blocks and must match an earlier open brace
110 System.out.println("Average wait time: "+adds two numbers together or concatenates Strings togethergetAverageWaitTime());
111 System.out.println("Server utility : "+adds two numbers together or concatenates Strings togethergetServerUtility());
112 }close braces end code blocks and must match an earlier open brace
113 }close braces end code blocks and must match an earlier open brace
114
115 publicpublic is used to indicate unrestricted access (any other class can have access) doubledouble is the type for numbers that can contain decimal fractions getAverageWaitTime()
116 {open braces start code blocks and must be matched with a close brace
117 doubledouble is the type for numbers that can contain decimal fractions sum=this assignment operator makes the left side equal to the right side0;
118 forfor is a looping structure for repeatedly executing a block of code(Customer2009 c: doneCustomers)
119 {open braces start code blocks and must be matched with a close brace
120 sum+=this increases the variable on the left by the value on the rightc.getWaitTime();
121 }close braces end code blocks and must match an earlier open brace
122 returnreturn means to provide the result of the method and/or cease execution of the method immediately sum/doneCustomers.size();
123 }close braces end code blocks and must match an earlier open brace
124
125 publicpublic is used to indicate unrestricted access (any other class can have access) doubledouble is the type for numbers that can contain decimal fractions getServerUtility()
126 {open braces start code blocks and must be matched with a close brace
127 doubledouble is the type for numbers that can contain decimal fractions sum=this assignment operator makes the left side equal to the right side0;
128 forfor is a looping structure for repeatedly executing a block of code(Customer2009 c: doneCustomers)
129 {open braces start code blocks and must be matched with a close brace
130 sum+=this increases the variable on the left by the value on the rightc.getServiceTime();
131 }close braces end code blocks and must match an earlier open brace
132 returnreturn means to provide the result of the method and/or cease execution of the method immediately sum/totalTime;
133 }close braces end code blocks and must match an earlier open brace
134
135 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) voidvoid means the method does not return a value mainThe main method is the place where applications begin executing.(String[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays args)
136 {open braces start code blocks and must be matched with a close brace
137 SingleQueue2009 sim=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor SingleQueue2009();
138 sim.simulate(40000);
139 }close braces end code blocks and must match an earlier open brace
140 }close braces end code blocks and must match an earlier open brace
|
Download/View intermediate/SingleQueue2009.java