|
001 packagepackage is used to name the directory or folder a class is in Rohrer;
002
003 importimport means to make the classes and/or packages available in this program fang.*;
004 importimport means to make the classes and/or packages available in this program java.awt.*;
005 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
006
007 /**
008 * My loop programs
009 * @authorthis is the Javadoc tag for documenting who created the source code Kevin Rohrer
010 */
011 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 Loops_Assignment_4 extendsextends means to customize or extend the functionality of a class Game
012 {open braces start code blocks and must be matched with a close brace
013 /** sets up the game */
014 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup()
015 {open braces start code blocks and must be matched with a close brace
016
017 StringSprite steps =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite("Press a number Between 1 and 7 to Begin");
018 steps.setSize(.75);
019 steps.setLocation(.5,.4);
020 addSprite(steps);
021
022 // Horizontal(); // 1 point
023 // diagonal(); // 1 point
024 // Grid(); // 4 points
025 // Target(); // 2 points
026 // Target_4(); // 4 points
027 // Cone(); // 3 points
028 // Cone_4(); // 5 points
029 // // 20 points total
030 }close braces end code blocks and must match an earlier open brace
031
032 /** makes dots in a horizontal line*/
033 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value Horizontal() // 1 point
034 {open braces start code blocks and must be matched with a close brace
035 intint is the type for whole numbers and it is short for integer h_Dots =this assignment operator makes the left side equal to the right side 5;
036 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 side1 ; i <=this evaluates to true if the left side is not more than the right sideh_Dots ; i++this is the increment operator, which increases the variable by 1)
037 {open braces start code blocks and must be matched with a close brace
038 OvalSprite hDot =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OvalSprite(1,1);
039 hDot.setSize(0.9/h_Dots);
040 doubledouble is the type for numbers that can contain decimal fractions x =this assignment operator makes the left side equal to the right side 0.5/h_Dots +adds two numbers together or concatenates Strings together 1.0/h_Dots * (i-1);
041 hDot.setLocation(x, 0.5);
042 addSprite(hDot);
043 }close braces end code blocks and must match an earlier open brace
044 }close braces end code blocks and must match an earlier open brace
045
046 /** maked dots in a diagonal line */
047 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value Diagonal() //1 point
048 {open braces start code blocks and must be matched with a close brace
049 intint is the type for whole numbers and it is short for integer d_Dots =this assignment operator makes the left side equal to the right side 15;
050 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 side1 ; i <=this evaluates to true if the left side is not more than the right sided_Dots ; i++this is the increment operator, which increases the variable by 1)
051 {open braces start code blocks and must be matched with a close brace
052 OvalSprite dDot =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OvalSprite(1,1);
053 dDot.setSize(0.9/d_Dots);
054 doubledouble is the type for numbers that can contain decimal fractions x =this assignment operator makes the left side equal to the right side 0.5/d_Dots +adds two numbers together or concatenates Strings together 1.0/d_Dots * (i-1);
055 doubledouble is the type for numbers that can contain decimal fractions y =this assignment operator makes the left side equal to the right side 0.5/d_Dots +adds two numbers together or concatenates Strings together 1.0/d_Dots * (i-1);
056 dDot.setLocation(x, y);
057 addSprite(dDot);
058 }close braces end code blocks and must match an earlier open brace
059 }close braces end code blocks and must match an earlier open brace
060
061 /** makes dots into a full grid*/
062 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value Grid() //4 points
063 {open braces start code blocks and must be matched with a close brace
064 intint is the type for whole numbers and it is short for integer h_Row =this assignment operator makes the left side equal to the right side20;
065 intint is the type for whole numbers and it is short for integer v_Row =this assignment operator makes the left side equal to the right side20;
066 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 v=this assignment operator makes the left side equal to the right side0; v < v_Row; v++this is the increment operator, which increases the variable by 1)
067 {open braces start code blocks and must be matched with a close brace
068 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 h=this assignment operator makes the left side equal to the right side1; h<=this evaluates to true if the left side is not more than the right sideh_Row; h++this is the increment operator, which increases the variable by 1)
069 {open braces start code blocks and must be matched with a close brace
070 OvalSprite gDot=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(1, 1);
071 gDot.setSize(0.9/h_Row);
072 doubledouble is the type for numbers that can contain decimal fractions x =this assignment operator makes the left side equal to the right side 0.5 / h_Row +adds two numbers together or concatenates Strings together 1.0 / h_Row * (h-1);
073 doubledouble is the type for numbers that can contain decimal fractions y =this assignment operator makes the left side equal to the right side 0.5 / h_Row +adds two numbers together or concatenates Strings together (v+adds two numbers together or concatenates Strings together0.0) / h_Row;
074 gDot.setLocation(x, y);
075 addSprite(gDot);
076 }close braces end code blocks and must match an earlier open brace
077 }close braces end code blocks and must match an earlier open brace
078
079 }close braces end code blocks and must match an earlier open brace
080
081 /** makes a target with circles*/
082 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value Target() //2 points
083 {open braces start code blocks and must be matched with a close brace
084 intint is the type for whole numbers and it is short for integer rings =this assignment operator makes the left side equal to the right side 10;
085 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 side1; i <=this evaluates to true if the left side is not more than the right side rings; i++this is the increment operator, which increases the variable by 1)
086 {open braces start code blocks and must be matched with a close brace
087 OvalSprite ring =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OvalSprite(2,2);
088 ring.setSize(1.0 -(1.0*(i-1)/rings));
089 ring.setLocation(0.5,0.5);
090 ifif executes the next statement only if the condition in parenthesis evaluates to true (i %this divides the left side by the right side and evaluates to the remainder 2 ==this is the comparison operator which evaluates to true if both sides are the same 0)
091 ring.setColor(Palette.getColor("Lawn Green"));
092 elseelse is what happens when the if condition is false
093 ring.setColor(Palette.getColor("Orange Red"));
094
095 addSprite(ring);
096 }close braces end code blocks and must match an earlier open brace
097 }close braces end code blocks and must match an earlier open brace
098
099
100 /** makes four smaller targets*/
101 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value Target_4() //4 points
102 {open braces start code blocks and must be matched with a close brace
103 forfor is a looping structure for repeatedly executing a block of code(doubledouble is the type for numbers that can contain decimal fractions j=this assignment operator makes the left side equal to the right side1; j<=this evaluates to true if the left side is not more than the right side4; j++this is the increment operator, which increases the variable by 1)
104 {open braces start code blocks and must be matched with a close brace
105 doubledouble is the type for numbers that can contain decimal fractions x =this assignment operator makes the left side equal to the right side .25;
106 doubledouble is the type for numbers that can contain decimal fractions y =this assignment operator makes the left side equal to the right side .25;
107 ifif executes the next statement only if the condition in parenthesis evaluates to true(j ==this is the comparison operator which evaluates to true if both sides are the same 4)
108 {open braces start code blocks and must be matched with a close brace
109 x=this assignment operator makes the left side equal to the right sidex+adds two numbers together or concatenates Strings together.5;
110 y=this assignment operator makes the left side equal to the right sidey+adds two numbers together or concatenates Strings together.5;
111 }close braces end code blocks and must match an earlier open brace
112 elseelse is what happens when the if condition is false
113 {open braces start code blocks and must be matched with a close brace
114 ifif executes the next statement only if the condition in parenthesis evaluates to true (j %this divides the left side by the right side and evaluates to the remainder 2 ==this is the comparison operator which evaluates to true if both sides are the same 0)
115 {open braces start code blocks and must be matched with a close brace
116 y=this assignment operator makes the left side equal to the right side y +adds two numbers together or concatenates Strings together ((j-0.0)/4);
117 x=this assignment operator makes the left side equal to the right sidex;
118 }close braces end code blocks and must match an earlier open brace
119 elseelse is what happens when the if condition is false
120 {open braces start code blocks and must be matched with a close brace
121 x=this assignment operator makes the left side equal to the right side x +adds two numbers together or concatenates Strings together ((j-1.0)/4);
122 y=this assignment operator makes the left side equal to the right sidey;
123 }close braces end code blocks and must match an earlier open brace
124 }close braces end code blocks and must match an earlier open brace
125
126 intint is the type for whole numbers and it is short for integer rings =this assignment operator makes the left side equal to the right side 10;
127 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 side1; i <=this evaluates to true if the left side is not more than the right side rings; i++this is the increment operator, which increases the variable by 1)
128 {open braces start code blocks and must be matched with a close brace
129 OvalSprite ring =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OvalSprite(2,2);
130 ring.setSize(.5 -(.5*(i-1)/rings));
131
132 ring.setLocation(x,y);
133
134 ifif executes the next statement only if the condition in parenthesis evaluates to true (i %this divides the left side by the right side and evaluates to the remainder 2 ==this is the comparison operator which evaluates to true if both sides are the same 0)
135 ring.setColor(Palette.getColor("Lawn Green"));
136 elseelse is what happens when the if condition is false
137 ring.setColor(Palette.getColor("Orange Red"));
138 addSprite(ring);
139
140 }close braces end code blocks and must match an earlier open brace
141 }close braces end code blocks and must match an earlier open brace
142 }close braces end code blocks and must match an earlier open brace
143
144 /** makes a cone with circles*/
145 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value Cone() //3 points
146 {open braces start code blocks and must be matched with a close brace
147 intint is the type for whole numbers and it is short for integer rings =this assignment operator makes the left side equal to the right side 10;
148 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 side1; i <=this evaluates to true if the left side is not more than the right side rings; i++this is the increment operator, which increases the variable by 1)
149 {open braces start code blocks and must be matched with a close brace
150 OvalSprite ring =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OvalSprite(1,1);
151 ring.setSize(1.0 -(1.0*(i-1)/(rings)));
152 doubledouble is the type for numbers that can contain decimal fractions x =this assignment operator makes the left side equal to the right side .5 -(.5*(i-1)/rings);
153 doubledouble is the type for numbers that can contain decimal fractions y =this assignment operator makes the left side equal to the right side .5 -(.5*(i-1)/rings);
154 ring.setLocation(x,y);
155
156 ifif executes the next statement only if the condition in parenthesis evaluates to true (i %this divides the left side by the right side and evaluates to the remainder 2 ==this is the comparison operator which evaluates to true if both sides are the same 0)
157 ring.setColor(Palette.getColor("Lawn Green"));
158 elseelse is what happens when the if condition is false
159 ring.setColor(Palette.getColor("Orange Red"));
160
161 addSprite(ring);
162 }close braces end code blocks and must match an earlier open brace
163 }close braces end code blocks and must match an earlier open brace
164
165 /**makes four smaller cones*/
166 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value Cone_4() //5 points
167 {open braces start code blocks and must be matched with a close brace
168 forfor is a looping structure for repeatedly executing a block of code(doubledouble is the type for numbers that can contain decimal fractions j=this assignment operator makes the left side equal to the right side1; j<=this evaluates to true if the left side is not more than the right side4; j++this is the increment operator, which increases the variable by 1)
169 {open braces start code blocks and must be matched with a close brace
170 doubledouble is the type for numbers that can contain decimal fractions xx =this assignment operator makes the left side equal to the right side 0.0;
171 doubledouble is the type for numbers that can contain decimal fractions yy =this assignment operator makes the left side equal to the right side 0.0;
172 ifif executes the next statement only if the condition in parenthesis evaluates to true(j ==this is the comparison operator which evaluates to true if both sides are the same 4)
173 {open braces start code blocks and must be matched with a close brace
174 xx=this assignment operator makes the left side equal to the right sidexx+adds two numbers together or concatenates Strings together.5;
175 yy=this assignment operator makes the left side equal to the right sideyy+adds two numbers together or concatenates Strings together.5;
176 }close braces end code blocks and must match an earlier open brace
177 elseelse is what happens when the if condition is false
178 {open braces start code blocks and must be matched with a close brace
179 ifif executes the next statement only if the condition in parenthesis evaluates to true (j %this divides the left side by the right side and evaluates to the remainder 2 ==this is the comparison operator which evaluates to true if both sides are the same 0)
180 {open braces start code blocks and must be matched with a close brace
181 yy=this assignment operator makes the left side equal to the right sideyy +adds two numbers together or concatenates Strings together ((j-0.0)/4);
182 xx=this assignment operator makes the left side equal to the right sidexx;
183 }close braces end code blocks and must match an earlier open brace
184 elseelse is what happens when the if condition is false
185 {open braces start code blocks and must be matched with a close brace
186 xx=this assignment operator makes the left side equal to the right sidexx +adds two numbers together or concatenates Strings together ((j-1.0)/4);
187 yy=this assignment operator makes the left side equal to the right sideyy;
188 }close braces end code blocks and must match an earlier open brace
189 }close braces end code blocks and must match an earlier open brace
190
191 intint is the type for whole numbers and it is short for integer rings =this assignment operator makes the left side equal to the right side 10;
192 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 side1; i <=this evaluates to true if the left side is not more than the right side rings; i++this is the increment operator, which increases the variable by 1)
193 {open braces start code blocks and must be matched with a close brace
194 OvalSprite ring =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor OvalSprite(1,1);
195 ring.setSize((1.0 -(1.0*(i-1)/(rings)))/2);
196 doubledouble is the type for numbers that can contain decimal fractions x =this assignment operator makes the left side equal to the right sidexx +adds two numbers together or concatenates Strings together .25 -(.25*(i-1)/rings);
197 doubledouble is the type for numbers that can contain decimal fractions y =this assignment operator makes the left side equal to the right sideyy +adds two numbers together or concatenates Strings together .25 -(.25*(i-1)/rings);
198 ring.setLocation(x,y);
199
200 ifif executes the next statement only if the condition in parenthesis evaluates to true (i %this divides the left side by the right side and evaluates to the remainder 2 ==this is the comparison operator which evaluates to true if both sides are the same 0)
201 ring.setColor(Palette.getColor("Lawn Green"));
202 elseelse is what happens when the if condition is false
203 ring.setColor(Palette.getColor("Orange Red"));
204 addSprite(ring);
205
206 }close braces end code blocks and must match an earlier open brace
207 }close braces end code blocks and must match an earlier open brace
208 }close braces end code blocks and must match an earlier open brace
209
210
211
212 /** change display on keypress */
213 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance()
214 {open braces start code blocks and must be matched with a close brace
215 ifif executes the next statement only if the condition in parenthesis evaluates to true(getKeyPressed()==this is the comparison operator which evaluates to true if both sides are the same'1')
216 {open braces start code blocks and must be matched with a close brace
217 removeAllSprites();
218 Horizontal();
219 }close braces end code blocks and must match an earlier open brace
220 ifif executes the next statement only if the condition in parenthesis evaluates to true(getKeyPressed()==this is the comparison operator which evaluates to true if both sides are the same'2')
221 {open braces start code blocks and must be matched with a close brace
222 removeAllSprites();
223 Diagonal();
224 }close braces end code blocks and must match an earlier open brace
225 ifif executes the next statement only if the condition in parenthesis evaluates to true(getKeyPressed()==this is the comparison operator which evaluates to true if both sides are the same'3')
226 {open braces start code blocks and must be matched with a close brace
227 removeAllSprites();
228 Grid();
229 }close braces end code blocks and must match an earlier open brace
230 ifif executes the next statement only if the condition in parenthesis evaluates to true(getKeyPressed()==this is the comparison operator which evaluates to true if both sides are the same'4')
231 {open braces start code blocks and must be matched with a close brace
232 removeAllSprites();
233 Target();
234 }close braces end code blocks and must match an earlier open brace
235 ifif executes the next statement only if the condition in parenthesis evaluates to true(getKeyPressed()==this is the comparison operator which evaluates to true if both sides are the same'5')
236 {open braces start code blocks and must be matched with a close brace
237 removeAllSprites();
238 Cone();
239 }close braces end code blocks and must match an earlier open brace
240 ifif executes the next statement only if the condition in parenthesis evaluates to true(getKeyPressed()==this is the comparison operator which evaluates to true if both sides are the same'6')
241 {open braces start code blocks and must be matched with a close brace
242 removeAllSprites();
243 Target_4();
244 }close braces end code blocks and must match an earlier open brace
245 ifif executes the next statement only if the condition in parenthesis evaluates to true(getKeyPressed()==this is the comparison operator which evaluates to true if both sides are the same'7')
246 {open braces start code blocks and must be matched with a close brace
247 removeAllSprites();
248 Cone_4();
249 }close braces end code blocks and must match an earlier open brace
250 }close braces end code blocks and must match an earlier open brace
251 }close braces end code blocks and must match an earlier open brace
|