-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJam.java
More file actions
42 lines (32 loc) · 798 Bytes
/
Jam.java
File metadata and controls
42 lines (32 loc) · 798 Bytes
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
package assignment1;
public class Jam extends MarketProduct{
//fields
private int jarsNumber = 0;
private int jarsPrice = 0;
//constructor
public Jam(String name, int n, int p) {
super(name);
this.jarsNumber = n;
this.jarsPrice = p;
}
//methods
@Override
public int getCost() {
return jarsNumber * jarsPrice ;
}
@Override
public boolean equals (Object j) {
boolean sameType = j.getClass() == this.getClass();
if (sameType) {
boolean sameName = ((MarketProduct) j).getName().equals(this.getName());
boolean sameCost = ((MarketProduct) j).getCost() == this.getCost();
boolean sameNumber = ((Jam) j).jarsNumber == this.jarsNumber;
if (sameName && sameCost && sameNumber)
return true;
else
return false;
}
else
return false;
}
}