Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Class Week05Debugging - Week 05 Activity Code

1/1

import comp102x.IO;

2
3
4
5
6
7
8
9
10
11
12
13
14

/*
* Expected output of the program:
*
_____________________
* 9/F |_?_|_?_|_?_|_?_|_?_|
* 8/F |_$_|_$_|_$_|_$_|_$_|
* 7/F |___|___|___|___|___|
* 6/F |_@_|_@_|_@_|_@_|_@_|
* 5/F |___|___|___|___|___|
* 3/F |_?_|_?_|_?_|_?_|_?_|
* 2/F |_$_|_$_|_$_|_$_|_$_|
* 1/F |___|___|___|___|___|
*/

15
16
17
18

public class Week05Debugging


{
public static final int numberOfFloors = 8;

19

public static void printBuilding()


{
IO.outputln("
_____________________");
int currentFloor = numberOfFloors;

20
21
22
23
24

do {

25
26

if (currentFloor > 4)
printFloor(currentFloor + 1);

27
28
29

else {
printFloor(currentFloor);
currentFloor--;
}

30
31
32
33
34

}; while (currentFloor > 1)

35

36
37

/** Prints a floor. e.g. "1/F |___|___|___|___|___|" */


public static void printFloor(int floor)
{
IO.output(floor + "/F ");
String symbol = "_";

38
39
40
41
42
43

//
//
//
if

for floors divisible by both


for floors divisible by just
for floors divisible by just
(floor % 2 == 0 && floor % 3
symbol = "@";
if (floor % 3 == 0)
symbol = "?";
if (floor % 2 == 0)
symbol = "$";

44
45
46
47
48
49
50
51
52

2 and 3, symbol should be "@"


3, symbol should be "?"
2, symbol should be "$"
== 0)

53

for (i = 0, i < 5, i + 1); {


IO.output("|_" + symbol + "_");
}

54
55
56
57

IO.outputln("|");

58

59
60

Jul 14, 2014 4:21:29 PM

You might also like