-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhoto.java
More file actions
86 lines (77 loc) · 2.78 KB
/
Photo.java
File metadata and controls
86 lines (77 loc) · 2.78 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
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
/** A photo file object that extends the Media class
* Adds on the width and height of the photo
* @author aydin-ali kachra
* @version 1
*/
public class Photo extends Media {
//instance variables
private int imageWidth; //measured in pixels
private int imageHeight; //measured in pixels
/** Creates a new Photo object
* @param fileName - name of the photo file
* @param fileType - type of photo file
* @param fileSize - size of the photo file in MB
* @param imageWidth - the width of the image in pixels
* @param imageHeight - the height of the image in pixels
*/
public Photo(String fileName, String fileType, double fileSize, int imageWidth, int imageHeight) {
super(fileName, fileType, fileSize);
this.imageWidth = imageWidth;
this.imageHeight = imageHeight;
}
/** Returns the width of the image
* @return the image width
*/
public int getImageWidth() {
return this.imageWidth;
}
/** Returns the height of the image
* @return the image height
*/
public int getImageHeight() {
return this.imageHeight;
}
/** Calculates the resolution of the image
* @return the image resolution
*/
public int imageResolution() {
return this.imageWidth * this.imageHeight;
} //resolution = width * height of photo
/** Returns which application launches when you open a photo file
* Completes abstract method from Media class
* @return the application that launches when the photo file opens
*/
public String openFile() {
return "Launching Preview...";
}
/** Finds if the Photo object is equal another object
* Overrides equals() in Media class
* @param other - object which you are comparing the Photo file to
* @return whether the two objects are equal or not
*/
public boolean equals(Object other) {
//checks if the super class is equal, otherwise there's no point on checking the rest
if (super.equals(other)) {
if (other == null) {
return false;
}
if (!(other instanceof Photo)) {
return false;
}
Photo toCompare = (Photo) other;
if (this.imageWidth == toCompare.imageWidth &&
this.imageHeight == toCompare.imageHeight) {
return true;
}
return false;
}
return false;
}
/** Creates and returns a string rep of the Photo object
* Overrides toString() in Media class
* @return the string rep of the Photo object
*/
public String toString() {
return "Media Type: photo, " + super.toString() + ", Image Width: " + this.imageWidth + "px, Image Height: " + this.imageHeight + "px";
}
}