FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java-Programs/ObjectOrdering/ComparableMovie.java at master · Gawsan/Java-Programs · GitHub
Gawsan
/
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
/
ComparableMovie.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
52 lines (44 loc) · 1.16 KB
Breadcrumbs
Java-Programs
/
ObjectOrdering
/
ComparableMovie.java
Copy path
File metadata and controls
52 lines (44 loc) · 1.16 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
package
ObjectOrdering
;
import
java
.
util
.
Arrays
;
class
Movie
implements
Comparable
<
Movie
> {
private
double
rating
;
private
String
name
;
private
int
year
;
public
Movie
(
String
n
,
double
rt
,
int
y
) {
this
.
name
=
n
;
this
.
rating
=
rt
;
this
.
year
=
y
;
}
// compare on the basis of rating
/*
* public int compareTo(Movie arg) { return this.year - arg.year; }
*/
// compare on the basis of name
public
int
compareTo
(
Movie
m
) {
return
this
.
name
.
compareTo
(
m
.
name
);
// this will call compareTo method of String Class
}
public
double
getRating
() {
return
rating
;
}
public
String
getName
() {
return
name
;
}
public
int
getYear
() {
return
year
;
}
}
public
class
ComparableMovie
{
public
static
void
main
(
String
[]
args
) {
Movie
[]
mov
=
new
Movie
[
4
];
mov
[
0
]=
new
Movie
(
"Inception"
,
8.9
,
2010
);
mov
[
1
]=
new
Movie
(
"The Dark Knight"
,
9.0
,
2008
);
mov
[
2
]=
new
Movie
(
"Intersteller"
,
8.7
,
2014
);
mov
[
3
]=
new
Movie
(
"The Prestige"
,
8.2
,
2005
);
Arrays
.
sort
(
mov
);
System
.
out
.
println
(
"Movie list in sorted order: "
);
for
(
Movie
mv
:
mov
) {
System
.
out
.
println
(
"Name: "
+
mv
.
getName
() +
"
\t
\t
[Rating: "
+
mv
.
getRating
() +
"
\t
Year: "
+
mv
.
getYear
() +
"]"
);
}
}
}
Back
|
FazBrowse Home
|
New Git URL