Question | Value | Score |
1 | 10 | |
2 | 15 | |
3 | 10 | |
4 | 15 | |
5 | 15 | |
6 | 10 | |
7 | 10 | |
8 | 15 | |
Total | 100 |
Solution:
boolean
xyz(int n) {
return n % 3 == 0 && n % 5 == 0 && n % 7 == 0 &&
n % 11 == 0;
}
2. Write a method, called magic, that has 3 boolean arguments and behaves according to the truth table below.
arg1 | arg2 | arg3 | returns |
true | true | true | false |
true | true | false | true |
true | false | true | true |
true | false | false | true |
false | true | true | false |
false | true | false | true |
false | false | true | false |
false | false | false | false |
public
void paint( Graphics g ) {
int i = 7;
g.drawString( "i = " + i, 50, j += 15);
xyz(g);
abc(g);
xyz(g);
abc(g);
g.drawString( "i = " + i, 50, j += 15);
}
void xyz(Graphics g) {
g.drawString( "i = " + i, 50, j += 15);
i *= 9;
g.drawString( "i = " + i, 50, j += 15);
}
void
abc(Graphics g) {
int i = 25;
g.drawString( "i = " + i, 50, j += 15);
++i;
g.drawString( "i = " + i, 50, j += 15);
}
}
i = xyz(x, y);
...
int xyz(int x, int
y) {
if (x != 10)
if (y <= 53)
return 10;
if (y > 60)
if (x < 0)
return 10;
return -1;
}
public
void paint( Graphics g ) {
g.drawString(magic(true) + " | " + magic(1.0), 20, 20);
}
//
your code would go here
}
boolean magic(double
x) {
return false;
}
for (int i = 0; i < a.length; i++)
if (a[i] == 0)
return sum;
else
sum += a[i];
return sum;
}
public void init() {
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
pots[i][j] = new Color(i*64, 0, j*64);
}
public void paint(Graphics g) {
// paint palette
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++) {
g.setColor(pots[i][j]);
g.fillRect(paletteX + j*potSize, paletteY + i*potSize, potSize, potSize);
}
// paint active color
g.setColor(active);
g.fillRect(0, 0, potSize, potSize);
}
public boolean mouseUp(Event event, int x, int y) {
if (x >= paletteX && x <= paletteX + 4*potSize &&
y >= paletteY && y <= paletteY + 4*potSize)
active = select(x, y);
repaint();
return true;
}
public Color select(int x, int y) {
//your code goes here
}
}
Solution: