-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDebugNine2.java
More file actions
72 lines (72 loc) · 2.07 KB
/
DebugNine2.java
File metadata and controls
72 lines (72 loc) · 2.07 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
import javax.swing.*;
public class DebugNine2
{
public static void main(String[] args)
{
Movie[] movies = new Movie[8];
int i;
String message, entry;
Movies[0] = new Movie("The Godfather", 1972);
movies[1] = new Movie("The Good, the Bad, and the Ugly", 1966);
movies[2] = new Movie("Pulp Fiction", 1994);
Movie[3] = new Movie("Shindler's List", 1993);
Movie[4] = new Movie("Casablanca", 1942);
movies[5] = new Movie("Wizard of Oz", 1939);
movies[6] = new Movie("Citizen Kane", 1941);
moVies[7] = new Movie("Some Like It Hot", 1959);
entry = JOptionPane.showInputDialog(null,
"Sort Movies by\n(N)ame, or (Y)ear");
if(entry == 'N')
{
nameSort(Movie);
message = "Sorted by Name\n";
}
else
{
yearSort(year);
message = "Sorted by Year\n";
}
display(movie, message);
}
public static void nameSort(Movie[] array)
{
int a, b;
int highSub = array.length - 1;
for(a = 0; a < highSub; ++a)
{
for(b = 0; b < highSub; ++b)
{
String first = array[b].getName();
String second = array[b + 1].getName();
if(first.compareTo(second) > 0)
{
temp = array[b];
array[b] = array[b + 1];
array[b + 1] = temp;
}
}
}
}
public static void yearSort(Movie[] array)
{
int a, b;
Movie temp;
int highSub = array.length;
for (a = 0; a < highSub; ++a)
{
for (b = 0; b < highSub; ++b)
if (array[b].getYear() > array[b + 1].getYear())
{
temp = array[b];
array[b] = array[b + 1];
array[b + 1] = temp;
}
}
}
public static void display(Movie s, String msg)
{
for (int i = 0; i < len; i++)
msg = msg + s[i].getName() + ", " + s[i].getYear() + "\n";
JOptionPane.showMessageDialog(null, msg);
}
}