-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstrument.java
More file actions
73 lines (67 loc) · 1.76 KB
/
Instrument.java
File metadata and controls
73 lines (67 loc) · 1.76 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
/**
* The abstract parent class named Instruments from
* which my different classes inherit
* @author Alizain Charania
* @version 1.0 Oct. 6 2015
*/
public abstract class Instrument {
private double price;
private int serialNum;
private static int num = 2358;
/**
* This is a constructor for the Instrument class
* @param price The cost price of each instrument
*/
public Instrument(double price) {
this.price = price;
serialNum = num++;
}
/**
* An abstract method to be implemented in the subclasses
* @return a String that makes the sound of that specific instrument
*/
public abstract String play();
/**
* A getter method for instance variable price
* @return a double price
*/
public double getPrice() {
return price;
}
/**
* A getter method for instance variable serial number
* @return a int serial number
*/
public int getSerialNum() {
return serialNum;
}
/**
* Overriding the equals() method
* @param other The reference object to compare
* @return a boolean return of the value-equality
*/
@Override
public boolean equals(Object other) {
if (null == other) {
return false;
}
if (this == other) {
return true;
}
if (!(other instanceof Instrument)) {
return false;
}
//Instrument that = (Instrument) other;
return this.serialNum == (((Instrument) other).serialNum);
}
/**
* Overriding the hashCode() method. Just a dummy to
* stop checkstyle error
* @return a int
*/
@Override
public int hashCode() {
int result = serialNum;
return result;
}
}