first commit
This commit is contained in:
28
Homework 2/src/barnestr/Point.java
Normal file
28
Homework 2/src/barnestr/Point.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package barnestr;
|
||||
|
||||
public class Point {
|
||||
double x;
|
||||
double y;
|
||||
|
||||
public Point(double x, double y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public double shiftRight(double shiftAmount) {
|
||||
x += shiftAmount;
|
||||
return shiftAmount;
|
||||
}
|
||||
public double shiftUp(double shiftAmount) {
|
||||
y += shiftAmount;
|
||||
return shiftAmount;
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public double getY() {
|
||||
return y;
|
||||
}
|
||||
}
|
||||
30
Homework 2/src/barnestr/Rectangle.java
Normal file
30
Homework 2/src/barnestr/Rectangle.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package barnestr;
|
||||
|
||||
public class Rectangle {
|
||||
Point topLeft;
|
||||
Point bottomRight;
|
||||
|
||||
public Rectangle(Point topLeft, Point bottomRight) {
|
||||
this.topLeft = topLeft;
|
||||
this.bottomRight = bottomRight;
|
||||
}
|
||||
|
||||
public double shiftRight(double shiftAmount) {
|
||||
topLeft.x += shiftAmount;
|
||||
bottomRight.x += shiftAmount;
|
||||
return shiftAmount;
|
||||
}
|
||||
|
||||
public double shiftUp(double shiftAmount) {
|
||||
topLeft.y += shiftAmount;
|
||||
bottomRight.y += shiftAmount;
|
||||
return shiftAmount;
|
||||
}
|
||||
|
||||
public void printCenter() {
|
||||
double centerX = (topLeft.x + bottomRight.x)/2;
|
||||
double centerY = (topLeft.y + bottomRight.y)/2;
|
||||
System.out.println("x = " + centerX + " y = " + centerY);
|
||||
}
|
||||
|
||||
}
|
||||
14
Homework 2/src/barnestr/RectangleDriver.java
Normal file
14
Homework 2/src/barnestr/RectangleDriver.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package barnestr;
|
||||
|
||||
public class RectangleDriver {
|
||||
public static void main(String[] args) {
|
||||
Point p1 = new Point(-3.0,1.0);
|
||||
Point p2 = new Point(3.0,-1.0);
|
||||
Rectangle rectangle = new Rectangle(p1,p2);
|
||||
rectangle.printCenter();
|
||||
rectangle.shiftUp(1.0);
|
||||
rectangle.shiftRight(1.0);
|
||||
rectangle.printCenter();
|
||||
}
|
||||
}
|
||||
|
||||
BIN
Homework 2/src/barnestr/barnestr.zip
Normal file
BIN
Homework 2/src/barnestr/barnestr.zip
Normal file
Binary file not shown.
Reference in New Issue
Block a user