-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathV.java
86 lines (75 loc) · 1.9 KB
/
V.java
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/***************************************
* FIFTH EXERCISE
* RAYMOND YANG
**************************************/
/* RETURN FUNCTIONS*/
public class exercise {
public static void main(String[]args){
int var=1;
double x1 = 1;
double y1 = 1;
double x2 = 5;
double y2 = 1;
double d1 = x1 - x2;
double d2 = y1 - y2;
if(var == 1){
System.out.println(calcDist(d1, d2);)
}
else if(var==2) {
System.out.println(calcSlope(d1, d2);)
}
else{
System.out.println("PEBKAC ERROR: CONTACT YOUR SERVICE REPRESENTATIVE FOR INSTRUCTIONS.");
}
}
static void calcDist(d1, d2);{
double distance;
distance = Math.sqrt( d1^2 + d2^2 );
return distance;
}
static void calcSlope(d1, d2);{
return d2/d1;
}
}
/* VOID FUNCTIONS */
public class exercise2 {
public static void main(String[]args){
int var =1;
double x1 = 1;
double y1 = 1;
double x2 = 5;
double y2 = 1;
/***************************************
* DETERMINING FUNCTION TO USE
* IF VAR = 1 : CALCULATE DISTANCE
* IF VAR = 2 : CALCULATE SLOPE
* OTHERWISE : SHOULDN'T HAPPEN. ERROR
**************************************/
if(var == 1){
System.out.println("CALCULATING DISTANCE");
calcDist(x1, x2, y1, y2);
}
else if(var == 2){
System.out.println("CALCULATING SLOPE");
calcSlope(x1, x2, y1, y2);
}
else{
System.out.println("AN ERROR HAS OCCURRED");
System.out.println("PLEASE CONTACT A SERVICE REPRESENTATIVE");
}
}
static void calcDist(double x1, double x2, double y1, double y2){
double dx, dy, out;
dx = Math.abs(x1 - x2);
dy = Math.abs(y1 - y2);
out = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy,2));
System.out.println(out);
}
static void calcSlope(double x1, double x2, double y1, double y2){
double dx, dy, out;
dx = Math.abs(x1 - x2);
dy = Math.abs(y1 - y2);
out = dy / dx;
System.out.println(out);
}
}