|
001 packagepackage is used to name the directory or folder a class is in mcclarty;
002
003 importimport means to make the classes and/or packages available in this program wiki.Wiki;
004 importimport means to make the classes and/or packages available in this program fang.*;
005 importimport means to make the classes and/or packages available in this program java.awt.*;
006 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
007 importimport means to make the classes and/or packages available in this program java.awt.Color;
008
009 /**
010 * This program generates a rose using ovals rotated at equal intervals.
011 * The rose is made of ovals stacked on top of each other.
012 * The petals decrease in size by 10%this divides the left side by the right side and evaluates to the remainder.
013 * @authorthis is the Javadoc tag for documenting who created the source code My Name Here
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 Assignment_4 extendsextends means to customize or extend the functionality of a class Game
016 {open braces start code blocks and must be matched with a close brace
017 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value Assignment4Rose()
018 {open braces start code blocks and must be matched with a close brace
019
020 intint is the type for whole numbers and it is short for integer petals =this assignment operator makes the left side equal to the right side 10;
021
022 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 sidepetals; i++this is the increment operator, which increases the variable by 1)
023 {open braces start code blocks and must be matched with a close brace
024 OvalSprite rosepetal=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(2,1);
025
026 // The petals are centered and start off taking up 85% of the screen and decrease in size by 10%.
027 rosepetal.setLocation (0.5,0.5);
028 rosepetal.setSize(0.85*(1-(0.1*(i-1))));
029
030 //The petals are rotated 36 degrees for each new petal created.
031 rosepetal.rotateDegrees(360.0-36.0*i);
032
033 //Make the petals alternate between red and white. If it is even then the petal is red and if odd it is white.
034
035 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)
036
037 rosepetal.setColor(Palette.getColor("Red"));
038
039 elseelse is what happens when the if condition is false
040
041 rosepetal.setColor(Palette.getColor("White"));
042
043 addSprite(rosepetal);
044 }close braces end code blocks and must match an earlier open brace
045 }close braces end code blocks and must match an earlier open brace
046
047 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value Assignment4SquareGrid()
048 {open braces start code blocks and must be matched with a close brace
049 /**
050 *This program creates a 10 by 10 grid of circles.
051 */
052
053 intint is the type for whole numbers and it is short for integer circlesAcross=this assignment operator makes the left side equal to the right side10;
054 intint is the type for whole numbers and it is short for integer circlesDown=this assignment operator makes the left side equal to the right side10;
055 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 j=this assignment operator makes the left side equal to the right side0; j<circlesDown; j++this is the increment operator, which increases the variable by 1)
056 {open braces start code blocks and must be matched with a close brace
057 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 sidecirclesAcross; i++this is the increment operator, which increases the variable by 1)
058 {open braces start code blocks and must be matched with a close brace
059 OvalSprite dot=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite(1, 1);
060 dot.setSize(0.75/circlesAcross);
061 doubledouble is the type for numbers that can contain decimal fractions x=this assignment operator makes the left side equal to the right side0.5/circlesAcross+adds two numbers together or concatenates Strings together1.0/circlesAcross*(i-1);
062 doubledouble is the type for numbers that can contain decimal fractions y=this assignment operator makes the left side equal to the right side0.5/circlesAcross+adds two numbers together or concatenates Strings together(j+adds two numbers together or concatenates Strings together0.0)/circlesAcross;
063 dot.setLocation(x, y);
064 addSprite(dot);
065
066 }close braces end code blocks and must match an earlier open brace
067 }close braces end code blocks and must match an earlier open brace
068 }close braces end code blocks and must match an earlier open brace
069 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value Assignment4Bullseye()
070 {open braces start code blocks and must be matched with a close brace
071 /**
072 *This program creates a bullseye with the colors red and yellow.
073 *The bullseye is made of circles decreasing by 10%this divides the left side by the right side and evaluates to the remainder as they approach the center.
074 */
075
076 intint is the type for whole numbers and it is short for integer layers =this assignment operator makes the left side equal to the right side 10;
077
078 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 sidelayers; i++this is the increment operator, which increases the variable by 1)
079 {open braces start code blocks and must be matched with a close brace
080 OvalSprite bulls=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite (1,1);
081
082 // The circles are centered and start off taking up 90% of the screen and decrease in size by 10%.
083 bulls.setLocation (0.5,0.5);
084 bulls.setSize(0.9*(1-(0.1*(i-1))));
085
086 //Make the circles alternate between red and yellow. If it is even then the circle is red and if odd it is yellow.
087
088 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)
089
090 bulls.setColor(Palette.getColor("Red"));
091
092 elseelse is what happens when the if condition is false
093
094 bulls.setColor(Palette.getColor("Yellow"));
095
096 addSprite(bulls);
097 }close braces end code blocks and must match an earlier open brace
098 }close braces end code blocks and must match an earlier open brace
099 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value Assignment4Cone()
100 {open braces start code blocks and must be matched with a close brace
101 /**
102 *This program creates a cone with the colors blue and green.
103 *The cone is made of circles decreasing by 10%this divides the left side by the right side and evaluates to the remainder as they shift.
104 *The circles also shift up and to the right 10%this divides the left side by the right side and evaluates to the remainder as they get smaller.
105 */
106
107 intint is the type for whole numbers and it is short for integer layers =this assignment operator makes the left side equal to the right side 10;
108
109 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 sidelayers; i++this is the increment operator, which increases the variable by 1)
110 {open braces start code blocks and must be matched with a close brace
111 OvalSprite cones=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite (1,1);
112
113 // The circless are centered and start off taking up 90% of the screen and decrease in size by 10%.
114 cones.setSize(0.9*(1-(0.1*(i-1))));
115
116 //The circles are shifted up and right at 10% invervals.
117 doubledouble is the type for numbers that can contain decimal fractions x=this assignment operator makes the left side equal to the right side0.45+adds two numbers together or concatenates Strings together0.05*i;
118 doubledouble is the type for numbers that can contain decimal fractions y=this assignment operator makes the left side equal to the right side0.55-0.05*i;
119 cones.setLocation (x, y);
120
121 //Make the circles alternate between blue and green. If it is even then the circle is blue and if odd it is green.
122
123 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)
124
125 cones.setColor(Palette.getColor("Blue"));
126
127 elseelse is what happens when the if condition is false
128
129 cones.setColor(Palette.getColor("Green"));
130
131 addSprite(cones);
132 }close braces end code blocks and must match an earlier open brace
133 }close braces end code blocks and must match an earlier open brace
134 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value Assignment4Bullseyesx4()
135 {open braces start code blocks and must be matched with a close brace
136 /**
137 *This program creates 4 bullseyes that take up 1/4 of the screen each.
138 */
139
140 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)
141 {open braces start code blocks and must be matched with a close brace
142 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;
143 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;
144 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 1)
145 {open braces start code blocks and must be matched with a close brace
146 x=this assignment operator makes the left side equal to the right sidex;
147 y=this assignment operator makes the left side equal to the right sidey;
148 }close braces end code blocks and must match an earlier open brace
149 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 2)
150 {open braces start code blocks and must be matched with a close brace
151 x=this assignment operator makes the left side equal to the right sidex+adds two numbers together or concatenates Strings together0.5;
152 y=this assignment operator makes the left side equal to the right sidey;
153 }close braces end code blocks and must match an earlier open brace
154 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 3)
155 {open braces start code blocks and must be matched with a close brace
156 x=this assignment operator makes the left side equal to the right sidex;
157 y=this assignment operator makes the left side equal to the right sidey+adds two numbers together or concatenates Strings together0.5;
158 }close braces end code blocks and must match an earlier open brace
159 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)
160 {open braces start code blocks and must be matched with a close brace
161 x=this assignment operator makes the left side equal to the right sidex+adds two numbers together or concatenates Strings together0.5;
162 y=this assignment operator makes the left side equal to the right sidey+adds two numbers together or concatenates Strings together0.5;
163
164 }close braces end code blocks and must match an earlier open brace
165
166
167 intint is the type for whole numbers and it is short for integer layers =this assignment operator makes the left side equal to the right side 10;
168
169 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 sidelayers; i++this is the increment operator, which increases the variable by 1)
170 {open braces start code blocks and must be matched with a close brace
171 OvalSprite bull=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OvalSprite (1,1);
172
173 // The circles are centered and start off taking up 25% of the screen and decrease in size by 10%.
174 bull.setSize(0.45*(1-(0.1*(i-1))));
175 bull.setLocation (x,y);
176
177 //Make the circles alternate between red and yellow. If it is even then the circle is red and if odd it is yellow.
178
179 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)
180
181 bull.setColor(Palette.getColor("Red"));
182
183 elseelse is what happens when the if condition is false
184
185 bull.setColor(Palette.getColor("Yellow"));
186
187 addSprite(bull);
188
189 }close braces end code blocks and must match an earlier open brace
190 }close braces end code blocks and must match an earlier open brace
191 }close braces end code blocks and must match an earlier open brace
192
193
194
195 /**handle input and game events*/
196 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance()
197 {open braces start code blocks and must be matched with a close brace
198 /* Place commands on the screen. */
199
200 StringSprite commands =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite( "Press: g, r, b, c, or f.");
201 commands.setWidth(1);
202 commands.setHeight(0.05);
203 commands.setLocation(0.5,0.95);
204 commands.setColor(Palette.getColor("Ivory"));
205 addSprite(commands);
206
207 /* Display graphic depending on command chosen. */
208 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 'g')
209 {open braces start code blocks and must be matched with a close brace
210 removeAllSprites();
211 Assignment4SquareGrid();
212 }close braces end code blocks and must match an earlier open brace
213 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 'r')
214 {open braces start code blocks and must be matched with a close brace
215 removeAllSprites();
216 Assignment4Rose();
217 }close braces end code blocks and must match an earlier open brace
218 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 'b')
219 {open braces start code blocks and must be matched with a close brace
220 removeAllSprites();
221 Assignment4Bullseye();
222 }close braces end code blocks and must match an earlier open brace
223 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 'c')
224 {open braces start code blocks and must be matched with a close brace
225 removeAllSprites();
226 Assignment4Cone();
227 }close braces end code blocks and must match an earlier open brace
228 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 'f')
229 {open braces start code blocks and must be matched with a close brace
230 removeAllSprites();
231 Assignment4Bullseyesx4();
232 }close braces end code blocks and must match an earlier open brace
233
234 }close braces end code blocks and must match an earlier open brace
235 }close braces end code blocks and must match an earlier open brace
|