From ggc
|
01 packagepackage is used to name the directory or folder a class is in intermediate;
02
03 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 Customer
04 {open braces start code blocks and must be matched with a close brace
05 /**time to enter in seconds since start of simulation*/
06 privateprivate is used to restrict access to the current class only doubledouble is the type for numbers that can contain decimal fractions enterTime;
07 privateprivate is used to restrict access to the current class only doubledouble is the type for numbers that can contain decimal fractions enterLaneTime;
08 privateprivate is used to restrict access to the current class only doubledouble is the type for numbers that can contain decimal fractions exitLaneTime;
09 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer items;
10 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer id;
11 privateprivate is used to restrict access to the current class only staticstatic means that an instance is not required for access (class level access) intint is the type for whole numbers and it is short for integer customersCreated=this assignment operator makes the left side equal to the right side1;
12
13 publicpublic is used to indicate unrestricted access (any other class can have access) Customer()
14 {open braces start code blocks and must be matched with a close brace
15 enterTime=this assignment operator makes the left side equal to the right side-1;
16 enterLaneTime=this assignment operator makes the left side equal to the right side-1;
17 exitLaneTime=this assignment operator makes the left side equal to the right sideDouble.POSITIVE_INFINITY;
18 items=this assignment operator makes the left side equal to the right side-1;
19 id=this assignment operator makes the left side equal to the right sidecustomersCreated;
20 customersCreated++this is the increment operator, which increases the variable by 1;
21 }close braces end code blocks and must match an earlier open brace
22
23 publicpublic is used to indicate unrestricted access (any other class can have access) Customer(doubledouble is the type for numbers that can contain decimal fractions enterStore, doubledouble is the type for numbers that can contain decimal fractions enterLane, doubledouble is the type for numbers that can contain decimal fractions exitLane, intint is the type for whole numbers and it is short for integer itemsBought)
24 {open braces start code blocks and must be matched with a close brace
25 enterTime=this assignment operator makes the left side equal to the right sideenterStore;
26 enterLaneTime=this assignment operator makes the left side equal to the right sideenterLane;
27 exitLaneTime=this assignment operator makes the left side equal to the right sideexitLane;
28 items=this assignment operator makes the left side equal to the right sideitemsBought;
29 id=this assignment operator makes the left side equal to the right sidecustomersCreated;
30 customersCreated++this is the increment operator, which increases the variable by 1;
31 }close braces end code blocks and must match an earlier open brace
32
33 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setItems(intint is the type for whole numbers and it is short for integer items)
34 {open braces start code blocks and must be matched with a close brace
35 thisthis means the current object (the implicit parameter).items=this assignment operator makes the left side equal to the right sideitems;
36 }close braces end code blocks and must match an earlier open brace
37
38 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setEnterStoreTime(doubledouble is the type for numbers that can contain decimal fractions time)
39 {open braces start code blocks and must be matched with a close brace
40 enterTime=this assignment operator makes the left side equal to the right sidetime;
41 }close braces end code blocks and must match an earlier open brace
42
43 /**must be called after setItems*/
44 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setShoppingRate(doubledouble is the type for numbers that can contain decimal fractions timePerItem)
45 {open braces start code blocks and must be matched with a close brace
46 enterLaneTime=this assignment operator makes the left side equal to the right sidetimePerItem*items+adds two numbers together or concatenates Strings togetherenterTime;
47 }close braces end code blocks and must match an earlier open brace
48
49 publicpublic is used to indicate unrestricted access (any other class can have access) doubledouble is the type for numbers that can contain decimal fractions getEnterLaneTime()
50 {open braces start code blocks and must be matched with a close brace
51 returnreturn means to provide the result of the method and/or cease execution of the method immediately enterLaneTime;
52 }close braces end code blocks and must match an earlier open brace
53
54 publicpublic is used to indicate unrestricted access (any other class can have access) doubledouble is the type for numbers that can contain decimal fractions getServiceTime()
55 {open braces start code blocks and must be matched with a close brace
56 returnreturn means to provide the result of the method and/or cease execution of the method immediately exitLaneTime-enterLaneTime;
57 }close braces end code blocks and must match an earlier open brace
58
59 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setExitLaneTime(doubledouble is the type for numbers that can contain decimal fractions time)
60 {open braces start code blocks and must be matched with a close brace
61 exitLaneTime=this assignment operator makes the left side equal to the right sidetime;
62 }close braces end code blocks and must match an earlier open brace
63
64 publicpublic is used to indicate unrestricted access (any other class can have access) doubledouble is the type for numbers that can contain decimal fractions getExitLaneTime()
65 {open braces start code blocks and must be matched with a close brace
66 returnreturn means to provide the result of the method and/or cease execution of the method immediately exitLaneTime;
67 }close braces end code blocks and must match an earlier open brace
68
69 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 getItems()
70 {open braces start code blocks and must be matched with a close brace
71 returnreturn means to provide the result of the method and/or cease execution of the method immediately items;
72 }close braces end code blocks and must match an earlier open brace
73
74 publicpublic is used to indicate unrestricted access (any other class can have access) String toString()
75 {open braces start code blocks and must be matched with a close brace
76 returnreturn means to provide the result of the method and/or cease execution of the method immediately "Customer#"+adds two numbers together or concatenates Strings togetherid;
77 }close braces end code blocks and must match an earlier open brace
78
79 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)
80 {open braces start code blocks and must be matched with a close brace
81 Customer c=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Customer();
82 System.out.println(c);
83 Customer c2=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Customer();
84 System.out.println(c2);
85 c2.setEnterStoreTime(5);
86 c2.setItems(10);
87 c2.setShoppingRate(0.5);
88 System.out.println(c2+adds two numbers together or concatenates Strings together" enters at 5 seconds, shops for 10 items"+adds two numbers together or concatenates Strings together
89 " at a rate of 0.5 seconds per item\n"+adds two numbers together or concatenates Strings together"and enters the lane at time "+adds two numbers together or concatenates Strings together
90 c2.getEnterLaneTime());
91 c2.setExitLaneTime(15);
92 System.out.println(c2+adds two numbers together or concatenates Strings together" exits the lane at time 15");
93 System.out.println(c2+adds two numbers together or concatenates Strings together" has a service duration of "+adds two numbers together or concatenates Strings togetherc2.getServiceTime());
94
95 }close braces end code blocks and must match an earlier open brace
96 }close braces end code blocks and must match an earlier open brace
|
Download/View intermediate/Customer.java