-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLineSlope.java
More file actions
43 lines (30 loc) · 1.03 KB
/
Copy pathLineSlope.java
File metadata and controls
43 lines (30 loc) · 1.03 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
43
package com.example.slope;
public class LineSlope {
private double a, b, c, d, slope;
// use the parameters to assign your instance variables
public void set_coordinates(double x1, double y1, double x2, double y2) {
a = x1;
b = y1;
c = x2;
d = y2;
}
// calculate the slope using your instance variables
public void calculate_slope() {
slope = Math.abs(b - d) / Math.abs(a - c);
}
// print the slope you calculated in calculate_slope
public void display_slope() {
System.out.println(slope);
}
public static void main(String[] args) {
LineSlope runner = new LineSlope();
// this line should have a slope of 2
runner.set_coordinates(3, 3, 7, 11);
runner.calculate_slope();
runner.display_slope();
// this line should have a slope of -.75
runner.set_coordinates(0, -2, -4, 1);
runner.calculate_slope();
runner.display_slope();
}
}