FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java-Programs/ObjectOrdering/ComparatorMovie.java at master · amulyadas001/Java-Programs · GitHub
amulyadas001
/
Java-Programs
Public
forked from
divScorp/Java-Programs
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java-Programs
/
ObjectOrdering
/
ComparatorMovie.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
64 lines (53 loc) · 1.51 KB
Breadcrumbs
Java-Programs
/
ObjectOrdering
/
ComparatorMovie.java
Copy path
File metadata and controls
64 lines (53 loc) · 1.51 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package
ObjectOrdering
;
import
java
.
util
.
ArrayList
;
import
java
.
util
.
Collections
;
import
java
.
util
.
Comparator
;
class
MovieCom
{
private
double
rating
;
private
String
name
;
private
int
year
;
public
MovieCom
(
String
n
,
double
rt
,
int
y
) {
this
.
name
=
n
;
this
.
rating
=
rt
;
this
.
year
=
y
;
}
public
double
getRating
() {
return
rating
;
}
public
String
getName
() {
return
name
;
}
public
int
getYear
() {
return
year
;
}
public
String
toString
() {
return
"Name: "
+
name
+
"
\t
Rating: "
+
rating
+
"
\t
Year: "
+
year
;
}
}
class
RatingCompare
implements
Comparator
<
MovieCom
> {
public
int
compare
(
MovieCom
m1
,
MovieCom
m2
) {
return
(
m1
.
getRating
() <
m2
.
getRating
()) ? -
1
: ((
m1
.
getRating
() >
m2
.
getRating
()) ?
1
:
0
);
}
}
class
NameCompare
implements
Comparator
<
MovieCom
> {
public
int
compare
(
MovieCom
m1
,
MovieCom
m2
) {
return
m1
.
getName
().
compareTo
(
m2
.
getName
());
}
}
public
class
ComparatorMovie
{
public
static
void
main
(
String
[]
args
) {
ArrayList
<
MovieCom
>
mov
=
new
ArrayList
<>();
mov
.
add
(
new
MovieCom
(
"Inception "
,
8.9
,
2010
));
mov
.
add
(
new
MovieCom
(
"The Dark Knight"
,
9.0
,
2008
));
mov
.
add
(
new
MovieCom
(
"Intersteller"
,
8.7
,
2014
));
mov
.
add
(
new
MovieCom
(
"The Prestige"
,
8.2
,
2005
));
System
.
out
.
println
(
"Sorted Movie list on the basis of Name."
);
Collections
.
sort
(
mov
,
new
NameCompare
());
for
(
MovieCom
m
:
mov
)
System
.
out
.
println
(
m
);
System
.
out
.
println
(
"
\n
Sorted Movie list on the basis of Rating."
);
Collections
.
sort
(
mov
,
new
RatingCompare
());
for
(
MovieCom
m
:
mov
)
System
.
out
.
println
(
m
);
}
}
Back
|
FazBrowse Home
|
New Git URL