-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
176 lines (174 loc) · 9.85 KB
/
Copy pathMain.java
File metadata and controls
176 lines (174 loc) · 9.85 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package advisor;
import java.io.PrintWriter;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
CompositeOutput output = new CompositeOutput();
PrintWriter out = new PrintWriter("filename.txt");
System.out.println("Provide access for the application by typing in: auth");
Scanner scanner = new Scanner(System.in);
boolean authorized = false;
int limit = 20;
for (int i = 0; i < args.length; i++) {
if (args[i].equals("-page")) {
limit = Integer.parseInt(args[i + 1]);
}
}
while (true) {
String input = scanner.nextLine();
String command = input.contains(" ") ? input.substring(0, input.indexOf(" ")) : input;
if ("auth".equals(command)) {
if (!authorized) {
authorized = Controller.authorize();
System.out.println(authorized ? "Success!" : "Failed");
System.out.println("Options: new, featured, categories, playlists C_NAME, count, save, unit_test, exit:");
} else {
System.out.println("Already authorized");
}
continue;
}
if ("exit".equals(command)) {
out.println(output.returnOutput());
System.out.println("---GOODBYE!---");
out.close();
return;
}
if (authorized) {
switch (command) {
case "new":
var newReleases = Controller.getNewReleases(limit);
View.print(newReleases);
break;
case "featured":
var featured = Controller.getFeatured(limit);
View.print(featured);
break;
case "categories":
var categories = Controller.getCategories(limit);
View.print(categories);
break;
case "playlists":
String categoryName = input.substring(input.indexOf(" ") + 1);
var playlists = Controller.getPlaylists(categoryName, limit);
View.print(playlists);
break;
case "next":
var nextPage = Controller.getPage("next");
if (nextPage == null) {
System.out.println("All pages reached.");
} else {
View.print(nextPage);
}
break;
case "previous":
var previousPage = Controller.getPage("previous");
if (previousPage == null) {
System.out.println("All pages reached.");
} else {
View.print(previousPage);
}
break;
case "count": {
System.out.println("Counting songs in current output text file.");
Visitor visit = new Visitor();
output.accept(visit);
break;
}
case "unit_test": {
UnitTests.tests(limit);
break;
}
case "save": {
System.out.println("What type of songs do you want to save in a text file?");
System.out.println("Choose from new, featured, playlists C_NAME:");
boolean stopSaving = false;
command = scanner.nextLine();
if (command.equals("new")){
String choice = "";
SaveMusic m = new NewSave();
System.out.println("Would you like to add a title, message or both to the output? Type title, message, both, or none.");
choice = scanner.nextLine();
if (choice.equals("title")){
AddTitle t = new AddTitle(m);
var newOutput = Controller.getNewReleases(limit);
t.writeToText(newOutput);
output.addToList(t);
System.out.println("Saved with title!");
}
else if (choice.equals("message")) {
AddMessage message = new AddMessage(m);
var newOutput = Controller.getNewReleases(limit);
message.writeToText(newOutput);
output.addToList(message);
System.out.println("Saved with message!");
}
else if (choice.equals("both")) {
AddTitle t = new AddTitle(m);
AddMessage message = new AddMessage(t);
var newOutput = Controller.getNewReleases(limit);
message.writeToText(newOutput);
output.addToList(message);
System.out.println("Saved both title and message!");
}
else if (choice.equals("none")) {
var newOutput = Controller.getNewReleases(limit);
m.writeToText(newOutput);
output.addToList(m);
System.out.println("Saved new releases!");
}
else {
System.out.println("Wrong input, going back to normal choices.");
}
break;
}
else if (command.equals("featured")) {
String choice2 = "";
SaveMusic n = new FeaturedSave();
System.out.println("Would you like to add a title, message or both to the output? Type title, message, both, or none.");
choice2 = scanner.nextLine();
if (choice2.equals("title")){
AddTitle t = new AddTitle(n);
var newOutput = Controller.getFeatured(limit);
t.writeToText(newOutput);
output.addToList(t);
System.out.println("Saved with title!");
}
else if (choice2.equals("message")){
AddMessage message = new AddMessage(n);
var newOutput = Controller.getFeatured(limit);
message.writeToText(newOutput);
output.addToList(message);
System.out.println("Saved with message!");
} else if (choice2.equals("both")) {
AddTitle t = new AddTitle(n);
AddMessage message = new AddMessage(t);
var newOutput = Controller.getFeatured(limit);
message.writeToText(newOutput);
output.addToList(message);
System.out.println("Saved both title and message!");
}
else if (choice2.equals("none")) {
var featuredOutput = Controller.getFeatured(limit);
n.writeToText(featuredOutput);
output.addToList(n);
System.out.println("Saved featured releases!");
}
else {
System.out.println("Wrong input, going back to normal choices.");
choice2 = scanner.nextLine();
}
break;
}
else {
System.out.println("Booting back to normal choices!:");
}
}
default:
System.out.println("Type a command.");
}
} else {
System.out.println("Type auth to get access to this app!");
}
}
}
}