forked from eparrarod/GitFall2024
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpireDeck.java
More file actions
82 lines (71 loc) · 2.61 KB
/
SpireDeck.java
File metadata and controls
82 lines (71 loc) · 2.61 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
73
74
75
76
77
78
79
80
81
82
import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;
public class SpireDeck
{
public static Scanner scan;
public static int deckId;
public static int cardCount;
public static int totalCost = 0;
public static String[] invalidCards = new String[10];
public static int invalidCount = 0;
public static int[] histogram = new int[6];
public static void main(String[] args) throws FileNotFoundException {
Scanner input = new Scanner(System.in);
System.out.println("Please type in the correctly formated file name with your deck");
String filename = input.next();
fileReader(filename);
}
public static void fileReader(String filename) throws FileNotFoundException {
scan = new Scanner(new File(filename));
Random random = new Random();
if (scan.hasNext() == true){
deckId = random.nextInt(111111111,999999999);
System.out.println(deckId);
} else {
System.out.println("This file is empty");
return;
}
while (scan.hasNext()) {
if (invalidCards[9] != null) {
System.out.println("SpireDeck_" + deckId + "(VOID).pdf");
System.out.println("This deck has 10 invalid cards");
for (int i = 0; i < invalidCards.length; i++) {
System.out.println(invalidCards[i]);
}
return;
}
if (cardCount > 1000) {
return;
}
costTally(scan.next());
}
System.out.println("SpireDeck_" + deckId + ".pdf");
System.out.println("Total energy cost of the deck: " + totalCost + " energies");
System.out.println("Histogram array starting from 1-6 left to right: " + Arrays.toString(histogram));
System.out.println("This deck had " + invalidCount + " cards with invalid energy values");
if (invalidCount == 0) {
return;
}
for (int i = 0; i < invalidCards.length; i++) {
if (invalidCards[i] == null) {
return;
}
System.out.println(invalidCards[i]);
}
}
public static void costTally(String cardInfo){
String [] temp = cardInfo.split(":");
if (temp.length == 1) {
return;
}
int cost = Integer.parseInt(temp[1]);
if ((cost >= 0) && (cost <= 6)) {
histogram[cost-1] = histogram[cost-1] + 1;
totalCost += cost;
cardCount++;
} else {
invalidCards[invalidCount] = cardInfo;
}
}
}