| Name: | Grader: | Score: |
public void SetPosition (GP.Attributes.Coordinate pos)private double CalculateTotal (double a, double b, int c)
Explain, briefly, at least two syntactic differences between a
class' constructor and any other function.
int fee = 0;
if (speed > 35)
{
fee = 20;
}
if (speed > 50)
{
fee = 40;
}
if (speed > 75)
{
fee = 60;
}
int fee = 0;
if (speed > 75)
{
fee = 60;
}
if (speed > 50)
{
fee = 40;
}
if (speed > 35)
{
fee = 20;
}
int fee = 0;
if (speed > 75)
{
fee = 60;
}
else if (speed > 50)
{
fee = 40;
}
else if (speed > 35)
{
fee = 20;
}
public class StopLight extends GP.Shape
{
public StopLight (double lightSize)
{
a MakeBackground(lightSize);
b int count = 0;
c while (count < 3)
{
e MakeLight(count, lightSize);
f count = count + 1;
}
}
public void MakeLight (int n, double sz)
{
g GP.Shape light = new GP.Shapes.Oval();
h light.SetPosition(new GP.Attributes.Coordinate(0, (n - 1) * sz));
i light.SetSize(new GP.Attributes.Dimension(size, size));
j light.SetColor(ChooseColor(n));
}
public GP.Attributes.Color ChooseColor (int number)
{
k GP.Attributes.Color result;
l if (number == 0)
{
m result = new GP.Attributes.Colors.Red();
}
n else if (number == 1)
{
o result = new GP.Attributes.Colors.Yellow();
}
p else
{
q result = new GP.Attributes.Colors.Green();
}
r return result;
}
public void MakeBackground (double lightSize)
{
s GP.Shape bg = new GP.Shapes.Rectangle();
t bg.SetSize(new GP.Attributes.Dimension(lightSize, 3 * lightSize));
u bg.SetColor(new GP.Attributes.Colors.White());
}
}
| Line |
Code |
num |
result |
rem |
|
|
public class Mystery |
|
|
|
|
|
{
|
|
|
|
|
|
public Mystery () |
|
|
|
|
|
{
|
|
|
|
a |
int num = 9876; |
|
|
|
b |
int result = num / 10; |
|
|
|
c |
int rem = num % 10; |
|
|
|
|
|
if (num < 0) |
|
|
|
|
|
{
|
|
|
|
d |
num = -num; |
|
|
|
|
|
} |
|
|
|
|
|
while (num != 0) |
|
|
|
|
|
{
|
|
|
|
e |
result = (result * 10) + rem; |
|
|
|
f |
num = num / 10; |
|
|
|
g |
rem = num % 10; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
Explain the purpose of the Mystery function.
public class Wedgie
{
public Wedgie (int numWedges)
{
final double END = 359.99999;
double angle = END / numWedges;
double start = 0;
while (start <= END)
{
MakeWedge(start, start + angle);
start = start + angle;
}
}
public void MakeWedge (double start, double end)
{
GP.Shapes.Pie p = new GP.Shapes.Pie();
p.SetSize(new GP.Attributes.Dimension(400, 400));
p.SetPosition(new GP.Attributes.Coordinate(200, 200));
p.SetStartAngle(new GP.Attributes.Angle(start));
p.SetEndAngle(new GP.Attributes.Angle(end));
}
}
0, 1, -1, 2, -3, 5, -8, 13, -21, ?, ? ...