-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem.java
More file actions
executable file
·47 lines (40 loc) · 1.16 KB
/
Problem.java
File metadata and controls
executable file
·47 lines (40 loc) · 1.16 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
import java.util.ArrayList;
/* A collection class for GradeSections, representative of a Problem */
public class Problem {
private String name;
private ArrayList<GradeSection> sections;
public Problem (String n) {
name = validate(n);
sections = new ArrayList<GradeSection>();
}
// Prompts the user, asking if the section
public void addGradeSection(String s) {
sections.add(new GradeSection(s));
}
// Cuts off the [## Marks] at the end of unparsed problems
public String validate(String n) {
String[] broken = n.split(" ");
String response = "";
for (String s : broken) {
if (s.charAt(0) == '[')
break;
response += s;
}
return response;
}
public boolean addGradeItemToLatestSection(String s) {
try {
sections.get(sections.size()-1).addGradeItem(s);
return true;
}
catch (Exception e) { return false; }
}
public String toString() {
return name;
}
public GradeSection[] getSections() {
GradeSection[] g = new GradeSection[sections.size()];
g = sections.toArray(g);
return g;
}
}