class attraction int numb String name int year int durability int arnu

 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
class attraction{
int numb;
String name;
int year;
int durability;
int arnumb;
public String toString() {
String output=("Number of the attraction \"" + numb+ "\" ");
output+=("Name of the attraction \"" + name+ "\" ");
output+=("Year \"" + year+ "\" ");
output+=("Durability \"" + durability+ "\" ");
output+=("Number of area \"" + arnumb+ "\" ");
return output;
}
public String getname()
{
return name;
}
}
public class Main {
public static void main(String[] args) throws IOException, ParseException {
File f2 = new File("attraction.txt");
attraction [] array = new attraction [20];
int coun=0;
Scanner in2 = new Scanner(f2);
int c=0;
array[coun] = new attraction();
while(in2.hasNextLine()){
String line = in2.nextLine();
if(c==0)
{
array[coun].numb =Integer.parseInt(line);
}
if(c==1)
{
array[coun].name=line;
}
if(c==2)
{
array[coun].year=Integer.parseInt(line);
}
if(c==3)
{
array[coun].durability=Integer.parseInt(line);
}
if(c==4)
{
array[coun].arnumb=Integer.parseInt(line);
coun++;
array[coun]=new attraction();
c=0;
c--;
}
c++;
}
ArrayList <attraction> arraylist2 = new ArrayList <attraction> (Arrays.asList(array));
for (int i = 0 ; i<coun; i++)
System.out.println(arraylist2.get(i));
Collections.sort(arraylist2, new Comparator<attraction>() {
public int compare(attraction o1, attraction o2) {
return o1.getname().compareTo(o2.getname());
}
});
}
}