-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoint.java
More file actions
executable file
·54 lines (46 loc) · 1.32 KB
/
Copy pathPoint.java
File metadata and controls
executable file
·54 lines (46 loc) · 1.32 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
44
45
46
47
48
49
50
51
52
53
54
package edu.brandeis.cs12b.pa4.provided;
import java.util.Arrays;
public class Point {
public int x, y;
/*
* NOTE: THE POINT CLASS IS FULLY IMPLEMENTED FOR YOU. YOU SHOULD NOT CHANGE IT!
*/
/**
* Create a new Point with a given X and Y coordinates
* @param x to put the point at
* @param y to put the point at
*/
public Point(int x, int y) {
this.x = x;
this.y = y;
}
/**
* Create a new point from a string of the form "(1,2)". Use this to parse
* points from user input.
* @param coordinates a string with coordinates for the new point
*/
public Point(String coordinates) {
String[] splitCoordintes = coordinates.split("[(,)]");
this.x = Integer.parseInt(splitCoordintes[1]);
this.y = Integer.parseInt(splitCoordintes[2]);
}
/**
* Create a new point that is moved one tile in a given direction
* @param direction to move the tile
* @return returns a new point with the new coordinates
*/
public Point translate(Direction direction) {
int newX = this.x;
int newY = this.y;
switch (direction){
case NORTH: newY--; break;
case SOUTH: newY++; break;
case EAST: newX++; break;
case WEST: newX--; break;
}
return new Point(newX,newY);
}
public String toString(){
return "(" + this.x + "," + this.y + ")";
}
}