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.util.*;
004 //end auto-imports
005
006 importimport means to make the classes and/or packages available in this program wiki.Wiki;
007
008 /**
009 * All about my application.
010 * @authorthis is the Javadoc tag for documenting who created the source code My Name Here
011 */
012 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 ShoppingSimulator
013 {open braces start code blocks and must be matched with a close brace
014 privateprivate is used to restrict access to the current class only ArrayList<Cashier> cashier;
015
016 /**Customers currently in the store*/
017 privateprivate is used to restrict access to the current class only ArrayList<Customer> customer;
018
019 /**Customers who have exited the store*/
020 privateprivate is used to restrict access to the current class only ArrayList<Customer> exitCustomers;
021
022 privateprivate is used to restrict access to the current class only doubledouble is the type for numbers that can contain decimal fractions currentTime;
023
024 /**shoppers/second*/
025 privateprivate is used to restrict access to the current class only doubledouble is the type for numbers that can contain decimal fractions rateShoppersEnter;
026
027 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer minItems;
028 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer maxItems;
029 privateprivate is used to restrict access to the current class only doubledouble is the type for numbers that can contain decimal fractions shoppingTimePerItem;
030 privateprivate is used to restrict access to the current class only doubledouble is the type for numbers that can contain decimal fractions checkoutTimePerItem;
031
032 privateprivate is used to restrict access to the current class only Random random;
033
034 privateprivate is used to restrict access to the current class only doubledouble is the type for numbers that can contain decimal fractions nextEntryTime;
035
036 publicpublic is used to indicate unrestricted access (any other class can have access) ShoppingSimulator()
037 {open braces start code blocks and must be matched with a close brace
038 cashier=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ArrayList<Cashier>();
039
040 customer=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ArrayList<Customer>();
041
042 exitCustomers=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ArrayList<Customer>();
043
044 currentTime=this assignment operator makes the left side equal to the right side0;
045
046 rateShoppersEnter=this assignment operator makes the left side equal to the right side0.5;
047
048 minItems=this assignment operator makes the left side equal to the right side1;
049 maxItems=this assignment operator makes the left side equal to the right side100;
050
051 shoppingTimePerItem=this assignment operator makes the left side equal to the right side2;
052
053 random=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Random(0);
054 }close braces end code blocks and must match an earlier open brace
055
056 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value addCashier(Cashier ... c)
057 {open braces start code blocks and must be matched with a close brace
058 forfor is a looping structure for repeatedly executing a block of code(intint is the type for whole numbers and it is short for integer i=this assignment operator makes the left side equal to the right side0; i<c.length; i++this is the increment operator, which increases the variable by 1)
059 {open braces start code blocks and must be matched with a close brace
060 cashier.add(c[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays);
061 }close braces end code blocks and must match an earlier open brace
062 }close braces end code blocks and must match an earlier open brace
063
064 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 getItemCount()
065 {open braces start code blocks and must be matched with a close brace
066 returnreturn means to provide the result of the method and/or cease execution of the method immediately random.nextInt(maxItems-minItems)+adds two numbers together or concatenates Strings togetherminItems;
067 }close braces end code blocks and must match an earlier open brace
068
069 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value generateNextEntry()
070 {open braces start code blocks and must be matched with a close brace
071 doubledouble is the type for numbers that can contain decimal fractions cumulative=this assignment operator makes the left side equal to the right siderandom.nextDouble();
072 doubledouble is the type for numbers that can contain decimal fractions time=this assignment operator makes the left side equal to the right side-Math.log(cumulative)/rateShoppersEnter;
073 nextEntryTime=this assignment operator makes the left side equal to the right sidecurrentTime+adds two numbers together or concatenates Strings togethertime;
074 }close braces end code blocks and must match an earlier open brace
075
076 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value simulateNextEvent()
077 {open braces start code blocks and must be matched with a close brace
078 /**the next customer that would enter a line*/
079 Customer firstToEnterLane=this assignment operator makes the left side equal to the right sidenullnull is the value used to refer to a non-existant object;
080 forfor is a looping structure for repeatedly executing a block of code(Customer cust: customer)
081 {open braces start code blocks and must be matched with a close brace
082 ifif executes the next statement only if the condition in parenthesis evaluates to true(firstToEnterLane==this is the comparison operator which evaluates to true if both sides are the samenullnull is the value used to refer to a non-existant object ||this is boolean or, meaning if either or both are true then the result is true firstToEnterLane.getEnterLaneTime()>cust.getEnterLaneTime())
083 {open braces start code blocks and must be matched with a close brace
084 firstToEnterLane=this assignment operator makes the left side equal to the right sidecust;
085 }close braces end code blocks and must match an earlier open brace
086 }close braces end code blocks and must match an earlier open brace
087 /**the next customer that would exit the store*/
088 Customer firstToExitLane=this assignment operator makes the left side equal to the right sidenullnull is the value used to refer to a non-existant object;
089 forfor is a looping structure for repeatedly executing a block of code(Customer cust: customer)
090 {open braces start code blocks and must be matched with a close brace
091 ifif executes the next statement only if the condition in parenthesis evaluates to true(firstToExitLane==this is the comparison operator which evaluates to true if both sides are the samenullnull is the value used to refer to a non-existant object ||this is boolean or, meaning if either or both are true then the result is true firstToExitLane.getExitLaneTime()>cust.getExitLaneTime())
092 {open braces start code blocks and must be matched with a close brace
093 firstToExitLane=this assignment operator makes the left side equal to the right sidecust;
094 }close braces end code blocks and must match an earlier open brace
095 }close braces end code blocks and must match an earlier open brace
096 //act on next event
097 ifif executes the next statement only if the condition in parenthesis evaluates to true(firstToEnterLane.getEnterLaneTime()<firstToExitLane.getExitLaneTime() &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&)
098 firstToEnterLane.getEnterLaneTime()<nextEntryTime)
099 {open braces start code blocks and must be matched with a close brace
100 System.out.println("Entering a line.");
101 enterLane(firstToEnterLane);
102 }close braces end code blocks and must match an earlier open brace
103 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(firstToExitLane.getExitLaneTime()<nextEntryTime)
104 {open braces start code blocks and must be matched with a close brace
105 System.out.println("Exiting store.");
106 exitLane(firstToExitLane);
107 }close braces end code blocks and must match an earlier open brace
108 elseelse is what happens when the if condition is false
109 {open braces start code blocks and must be matched with a close brace
110 System.out.println("Enter store.");
111 enterStore();
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) voidvoid means the method does not return a value enterStore()
116 {open braces start code blocks and must be matched with a close brace
117 currentTime=this assignment operator makes the left side equal to the right sidenextEntryTime;
118 Customer c=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Customer();
119 c.setEnterStoreTime(currentTime);
120 intint is the type for whole numbers and it is short for integer items=this assignment operator makes the left side equal to the right siderandom.nextInt(maxItems-minItems)+adds two numbers together or concatenates Strings togetherminItems;
121 c.setItems(items);
122 c.setShoppingRate(shoppingTimePerItem);
123 customer.add(c);
124 generateNextEntry();
125 }close braces end code blocks and must match an earlier open brace
126
127 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value exitLane(Customer cust)
128 {open braces start code blocks and must be matched with a close brace
129 forfor is a looping structure for repeatedly executing a block of code(Cashier c: cashier)
130 {open braces start code blocks and must be matched with a close brace
131 ifif executes the next statement only if the condition in parenthesis evaluates to true(c.hasCustomer(cust))
132 {open braces start code blocks and must be matched with a close brace
133 currentTime=this assignment operator makes the left side equal to the right sidec.getNextAvailableTime();
134 c.scanNextCustomer(currentTime);
135 System.out.println("Customer "+adds two numbers together or concatenates Strings togethercust+adds two numbers together or concatenates Strings together" exits from cashier "+adds two numbers together or concatenates Strings togetherc);
136 }close braces end code blocks and must match an earlier open brace
137 }close braces end code blocks and must match an earlier open brace
138 }close braces end code blocks and must match an earlier open brace
139
140 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value enterLane(Customer cust)
141 {open braces start code blocks and must be matched with a close brace
142 intint is the type for whole numbers and it is short for integer items=this assignment operator makes the left side equal to the right sidecust.getItems();
143 Cashier fastest=this assignment operator makes the left side equal to the right sidenullnull is the value used to refer to a non-existant object;
144 forfor is a looping structure for repeatedly executing a block of code(Cashier c: cashier)
145 {open braces start code blocks and must be matched with a close brace
146 ifif executes the next statement only if the condition in parenthesis evaluates to true(fastest==this is the comparison operator which evaluates to true if both sides are the samenullnull is the value used to refer to a non-existant object &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) c.canJoin(cust))
147 {open braces start code blocks and must be matched with a close brace
148 fastest=this assignment operator makes the left side equal to the right sidec;
149 }close braces end code blocks and must match an earlier open brace
150 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(fastest.getNumberInQueue()>c.getNumberInQueue())
151 {open braces start code blocks and must be matched with a close brace
152 fastest=this assignment operator makes the left side equal to the right sidec;
153 }close braces end code blocks and must match an earlier open brace
154 }close braces end code blocks and must match an earlier open brace
155 fastest.joinLane(cust);
156 currentTime=this assignment operator makes the left side equal to the right sidecust.getEnterLaneTime();
157 ifif executes the next statement only if the condition in parenthesis evaluates to true(fastest.getNumberInQueue()==this is the comparison operator which evaluates to true if both sides are the same1)
158 {open braces start code blocks and must be matched with a close brace
159 fastest.scanNextCustomer(currentTime);
160 }close braces end code blocks and must match an earlier open brace
161 Wiki.out.println("customer "+adds two numbers together or concatenates Strings togethercust+adds two numbers together or concatenates Strings together" joins cashier lane "+adds two numbers together or concatenates Strings togetherfastest+adds two numbers together or concatenates Strings together" at time "+adds two numbers together or concatenates Strings togethercurrentTime);
162 }close braces end code blocks and must match an earlier open brace
163
164 publicpublic is used to indicate unrestricted access (any other class can have access) String toString()
165 {open braces start code blocks and must be matched with a close brace
166 String customers=this assignment operator makes the left side equal to the right side"";
167 forfor is a looping structure for repeatedly executing a block of code(Customer c: customer)
168 {open braces start code blocks and must be matched with a close brace
169 customers+=this increases the variable on the left by the value on the right"\t\t"+adds two numbers together or concatenates Strings togetherc+adds two numbers together or concatenates Strings together" with "+adds two numbers together or concatenates Strings togetherc.getItems()+adds two numbers together or concatenates Strings together" items\n";
170 }close braces end code blocks and must match an earlier open brace
171 String cashiers=this assignment operator makes the left side equal to the right side"";
172 forfor is a looping structure for repeatedly executing a block of code(Cashier c: cashier)
173 {open braces start code blocks and must be matched with a close brace
174 cashiers+=this increases the variable on the left by the value on the right"\t\t"+adds two numbers together or concatenates Strings togetherc+adds two numbers together or concatenates Strings together"\n";
175 }close braces end code blocks and must match an earlier open brace
176 String text=this assignment operator makes the left side equal to the right side"";
177 text+=this increases the variable on the left by the value on the right"Current Time: "+adds two numbers together or concatenates Strings togethercurrentTime+adds two numbers together or concatenates Strings together"\n";
178 text+=this increases the variable on the left by the value on the right"\tCustomers: \n";
179 text+=this increases the variable on the left by the value on the rightcustomers+adds two numbers together or concatenates Strings together"\n";
180 text+=this increases the variable on the left by the value on the right"\tCashiers: \n";
181 text+=this increases the variable on the left by the value on the rightcashiers+adds two numbers together or concatenates Strings together"\n";
182 returnreturn means to provide the result of the method and/or cease execution of the method immediately text;
183 }close braces end code blocks and must match an earlier open brace
184
185 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)
186 {open braces start code blocks and must be matched with a close brace
187 System.out.println("Simulation is:");
188 ShoppingSimulator simulator=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ShoppingSimulator();
189 Cashier one=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Cashier();
190 Cashier two=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Cashier();
191 simulator.addCashier(one, two);
192 System.out.println(simulator.toString());
193 simulator.generateNextEntry();
194 simulator.enterStore();
195 System.out.println(simulator.toString());
196 simulator.enterStore();
197 System.out.println(simulator.toString());
198 simulator.enterStore();
199 System.out.println(simulator.toString());
200 forfor is a looping structure for repeatedly executing a block of code(intint is the type for whole numbers and it is short for integer i=this assignment operator makes the left side equal to the right side0; i<10; i++this is the increment operator, which increases the variable by 1)
201 {open braces start code blocks and must be matched with a close brace
202 simulator.simulateNextEvent();
203 System.out.println(simulator.toString());
204 }close braces end code blocks and must match an earlier open brace
205 }close braces end code blocks and must match an earlier open brace
206 }close braces end code blocks and must match an earlier open brace
|
Download/View intermediate/ShoppingSimulator.java