forked from ChrisMayfield/ThinkJavaCode2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIsland.java
More file actions
42 lines (36 loc) · 1.3 KB
/
Island.java
File metadata and controls
42 lines (36 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
public class Island {
public static void main(String[] args){
// location of center of circle, as well as radius
int centerX = 100; // Island center x
int centerY = 200; // Island center y
int radius = 25; // Island radius
// parachuting position
int x = 105;
int y = 90;
// try treasure coordinate
// correct for wind
// correct for ice
System.out.println("Parachuting at (" + x + ", " + y + ")");
// A wind blows us +5 x and -10 y
x = x + 5;
y = y - 10;
System.out.println("A wind blew us to (" + x + ", " + y + ")");
// calculate the distance from our landing point to the center of the circle
double distance = Math.sqrt((x - centerX)*(x - centerX) +
(y - centerY)*(y - centerY));
if (distance > radius) {
System.out.println("Oh no, you landed in the water!");
}
else {
// look at isInSquare!
// doesnt use chained iff because these two conditions are not mutually exclusive
if (x >= 100 && x <= 110 && y >= 180 && y <= 195 ) {
y = y - 4; // Slide -4 units
System.out.println("You hit the patch of ice and slid to (" + x + ", " + y + ")");
}
if (x == 105 && y == 190) { // At the treasure
System.out.println("You got the treasure!");
}
}
}
}