-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCardSort.java
More file actions
49 lines (48 loc) · 1.14 KB
/
CardSort.java
File metadata and controls
49 lines (48 loc) · 1.14 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
import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;
public class CardSort {
public static void main(String[] args) throws FileNotFoundException
{
Scanner fin = new Scanner(new File("card_sort.dat"));
String[] temp;
int attack, defense;
String name;
ArrayList<Card> cards = new ArrayList<Card>();
while (fin.hasNextLine())
{
temp = fin.nextLine().split("/");
name = temp[0];
attack = Integer.parseInt(temp[1]);
defense = Integer.parseInt(temp[2]);
cards.add(new CardSort().new Card(attack, defense, name));
}
Comparator<Card> c = new Comparator<Card>()
{
public int compare(Card o1, Card o2)
{
if (o1.power != o2.power)
return o2.power-o1.power;
else if (o1.attack != o2.attack)
return o2.attack - o1.attack;
else
return (o1.name).compareTo(o2.name);
}
};
cards.sort(c);
for (Card card: cards)
System.out.printf("%d (%s/%d/%d)\n", card.power, card.name, card.attack, card.defense);
}
public class Card
{
int attack, defense, power;
String name;
public Card(int a, int d, String n)
{
attack = a;
defense = d;
power = a+d;
name = n;
}
}
}