-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCellPhone.java
More file actions
104 lines (84 loc) · 1.88 KB
/
CellPhone.java
File metadata and controls
104 lines (84 loc) · 1.88 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//---------------------------------
//assignment 3
//Written by Jiemin Liang 40262509
//----------------------------------
public class CellPhone implements Cloneable {
/**
* Name and ID: Jiemin liang 40262509
* COMP 249 Assignment 3
* Due Date: Dec 2,2024
*
* @param args
*/
// Attributes
long serialNum;
String brand;
int year;
double price;
// constructors
public CellPhone(long serialNum, String brand, double price, int year) {
this.serialNum = serialNum;
this.brand = brand;
this.year = year;
this.price = price;
}
public CellPhone(CellPhone c, long x) {
serialNum = x;
brand = new String(c.brand);
year = c.year;
price = c.price;
}
public CellPhone(CellPhone c) {
brand = new String(c.brand);
serialNum = c.serialNum;
year = c.year;
price = c.price;
}
// clone method
public CellPhone clone(long x) throws CloneNotSupportedException {
CellPhone temp = (CellPhone) super.clone();
temp.serialNum = x;
temp.brand = new String(this.brand);
return temp;
}
// getter and setter
public long getSerialNum() {
return serialNum;
}
public void setSerialNum(long serialNum) {
this.serialNum = serialNum;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
@Override
// equals method
public boolean equals(Object obj) {
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
CellPhone other = (CellPhone) obj;
return brand.equals(other.brand) && price == other.price && year == other.year;
}
@Override
// toString method
public String toString() {
return "[" + serialNum + ": " + brand + " " + price + "$ " + year + "]";
}
}