-
Notifications
You must be signed in to change notification settings - Fork 0
/
Location.java
132 lines (112 loc) · 2.87 KB
/
Location.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/**
* Team: Mary DuBard, Hannah Murphy, Alyssa Rivera
* Author of this class: Alyssa Rivera
*
* Created: December 8th, 2015
* Last Modified: December 10th, 2015
* Known Bugs: none
*
* Represents a location on Wellesley's campus, including the following information:
* name, description, image of the place
* Necessary for the Map class
*/
import java.awt.*;
import javax.imageio.ImageIO;
import java.io.File;
import java.io.IOException;
public class Location implements Comparable<Location> {
private String name, about;
private Image picture;
private double distance;
/**
* Creates a Location object with a name, about, and picture
* Imports the picture from the given fileName
*
* @param n name of the Location
* @param a about information of the Location
* @param fileName location of the picture of the Location
*/
public Location(String n, String a, String fileName){
name = n;
about = a;
distance = 0.0;
try{
picture = ImageIO.read(new File (fileName));
}
catch(IOException e){
//System.out.println("Picture could not be imported in constructor");
//throw e;
}
}
/**
* Creates a Location object with a name, an empty about, and a Wellesley logo as the image
* distance 0.0
*
* @param n name of the Location
*/
public Location (String n){
name = n;
about = " ";
distance = 0.0;
try{
picture = ImageIO.read( new File ("wellesleylogo.png"));
}
catch(IOException e){
System.out.println ("picture import failed");
}
}
/**
* Returns a String representation of the Location, including the name, about, and picture
*
* @return the String representation
*/
public String toString(){
return name; //+ "\n" + about + "\n" + picture;
}
/**
* Compares two Location objects
*
* @param that Location to compare to
* @return 0 if distances equal, -1 if this smaller than other, 1 if this bigger than other
*/
public int compareTo(Location that){
if(this.getDistance() == that.getDistance())
return 0;
else if (this.getDistance()<that.getDistance())
return -1;
else
return 1;
}
/****Getter Methods****/
public String getName(){
return name;
}
public String getAbout(){
return about;
}
public Image getPic(){
return picture;
}
public double getDistance(){
return distance;
}
/****Setter Methods****/
public void setName(String n){
name = n;
}
public void setAbout(String a){
about = a;
}
public void setDistance(double d){
distance = d;
}
public void setPicture(String fileName){
try{
picture = ImageIO.read(new File (fileName));
}
catch(IOException e){
System.out.println("Picture could not be imported in setPicture()");
//throw e;
}
}
}