-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleObject.java
More file actions
129 lines (114 loc) · 3.16 KB
/
Copy pathSimpleObject.java
File metadata and controls
129 lines (114 loc) · 3.16 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
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
/**
* A simple object which knows its serial number, string, and integer.
*
* @author Sachith Ranaweera
* @version 1.0 2016-10-14
*/
public class SimpleObject
{
// class field
private static int lastSerialNumber = 1;
//instance field
private int integer;
private int serialNumber;
private String string;
/**
* Constructs a simple object with the next serial number.
*/
public SimpleObject ()
{
serialNumber = ++lastSerialNumber;
string = "";
integer = 0;
}
/**
* Constructs a simple object with the next serial number and the
* specified integer.
*/
public SimpleObject (int integer)
{
serialNumber = ++lastSerialNumber;
string = "";
this.integer = integer;
}
/**
* Constructs a simple object with the next serial number
* and the specified string.
*/
public SimpleObject(String string)
{
serialNumber = ++lastSerialNumber;
integer = 0;
this.string = string;
}
/**
* Constructs a simple object with the next serial number
* and the specified string and integer.
*/
public SimpleObject(String string, int integer)
{
serialNumber = ++lastSerialNumber;
this.integer = integer;
this.string = string;
}
/**
* Returns the integer of this simple object.
*/
public int getInteger()
{
return integer;
} // end of method getNumber()
/**
* Returns the serial number of this simple object.
*/
public int getSerialNumber()
{
return serialNumber;
} // end of method serialNumber()
/**
* Returns the string of this simple object.
*/
public String getString()
{
return string;
} // end of method string()
/**
* Sets the integer of this simple object.
*/
public void setInteger(int integer)
{
integer = this.integer;
} // end of setString()
/**
* Sets the string of this simple object.
*/
public void setString(String string)
{
string = this.string;
} // end of method setString()
/**
* Returns a string representation of this simple object.
*/
public String toString()
{
return
getClass().getName()
+ "["
+ "SerialNumber: " + serialNumber
+ ", String: " + string
+ ", integer: " + integer
+ "]";
} // end of method to String()
/**
* Compare object one with object two
*/
public int compareTo(Object otherObject)
{
if(otherObject == null) return 0;
if(getClass() != otherObject.getClass()) return 0;
SimpleObject other = (SimpleObject) otherObject;
if(serialNumber < other.serialNumber) return -1;
if(serialNumber > other.serialNumber) return 1;
return 0;
}// end of compareTO method
} // end of class SimpleObject