I don't know what changes I've made lol
This commit is contained in:
9
OCT-6-Debugging/src/module-info.java
Normal file
9
OCT-6-Debugging/src/module-info.java
Normal file
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* @author brett
|
||||
*
|
||||
*/
|
||||
module oct2_debug {
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package uwstout.courses.cs144.examples.debug;
|
||||
|
||||
/**
|
||||
* Calculates the slope of a line through two points.
|
||||
*
|
||||
* @author Turner
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Slope {
|
||||
|
||||
private double slope;
|
||||
|
||||
/**
|
||||
* Calculates the slope using two points.
|
||||
*
|
||||
* @param x1 First x coordinate
|
||||
* @param y1 First y coordinate
|
||||
* @param x2 Second x coordinate
|
||||
* @param y2 Second y coordinate
|
||||
*/
|
||||
public void setSlope(int x1, int y1, int x2, int y2) {
|
||||
int rise;
|
||||
int run;
|
||||
|
||||
rise = y2 - y1;
|
||||
run = x2 - x1;
|
||||
|
||||
slope = (double) rise / run;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the slope
|
||||
*
|
||||
* @return The slope
|
||||
*/
|
||||
public double getSlope() {
|
||||
return slope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the Slope class
|
||||
*
|
||||
* @param args Command line - not used
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
Slope slope = new Slope();
|
||||
|
||||
// tests
|
||||
// Input: 0, 0, 1, 1 -> slope: 1
|
||||
slope.setSlope(0, 0, 1, 1);
|
||||
System.out.println("Slope: " + slope.getSlope());
|
||||
|
||||
// Input: 0, 0, 1, -1 -> slope: -1
|
||||
slope.setSlope(0, 0, 1, -1);
|
||||
System.out.println("Slope: " + slope.getSlope());
|
||||
|
||||
// Input: 0, 0, 1, 0 -> slope: 0
|
||||
slope.setSlope(0, 0, 1, 0);
|
||||
System.out.println("Slope: " + slope.getSlope());
|
||||
|
||||
// Input: 0, 0, 0, 1 -> slope: UND
|
||||
slope.setSlope(0, 0, 0, 1);
|
||||
System.out.println("Slope: " + slope.getSlope());
|
||||
|
||||
// Input: 0, 0, 1, 2 -> slope:
|
||||
slope.setSlope(0, 0, 3, 2);
|
||||
System.out.println("Slope: " + slope.getSlope());
|
||||
|
||||
// More?
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user