Skip to content

Commit b7d5fb9

Browse files
committed
wow such update
1 parent 3f7a5bb commit b7d5fb9

File tree

18 files changed

+968
-987
lines changed

18 files changed

+968
-987
lines changed

src/Items/Assignment.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
11
/**
2-
* Represents an assignment of tutors to slots.
3-
* More or less represents a matching of tutors to slots,
4-
* but not necessarily a perfect matching
5-
* (allow asymmetry and multiple assignments)
2+
* Represents an assignment of tutors to slots. More or less represents a matching of tutors to
3+
* slots, but not necessarily a perfect matching (allow asymmetry and multiple assignments)
64
*/
75

86
package Items;
97

108
public class Assignment {
11-
12-
// TODO
13-
private boolean[][] a;
149

15-
public Assignment(Tutor[] tutors, Slot[] slots) {
16-
// TODO
17-
}
10+
// TODO
11+
private boolean[][] a;
12+
13+
public Assignment(Tutor[] tutors, Slot[] slots) {
14+
// TODO
15+
}
1816

19-
// assigns tutor to slot
20-
public void assign(Tutor tutor, Slot slot) {
21-
// TODO
22-
}
17+
// assigns tutor to slot
18+
public void assign(Tutor tutor, Slot slot) {
19+
// TODO
20+
}
2321

24-
@Override
25-
public String toString() {
26-
return null;
27-
}
22+
@Override
23+
public String toString() {
24+
return null;
25+
}
2826
}

src/Items/Data.java

Lines changed: 86 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
/**
2-
* Data.java contains the classes for the Java object representation for
3-
* our data elements.
4-
* Includes classes for:
5-
* * Tutors (and their preferences)
6-
* * Office hour slots (and their preferences)
2+
* Data.java contains the classes for the Java object representation for our data elements. Includes
3+
* classes for: * Tutors (and their preferences) * Office hour slots (and their preferences)
74
* Populate these classes using the Gson library
85
*/
96

@@ -17,106 +14,103 @@
1714
import com.google.gson.JsonPrimitive;
1815

1916
/**
20-
* Class directly populated by the JSON reader. Each index corresponds exactly
21-
* to the index in any of the courses[].
17+
* Class directly populated by the JSON reader. Each index corresponds exactly to the index in any
18+
* of the courses[].
2219
*/
2320
public class Data {
2421

25-
/**
26-
* Array of all course names. Each index corresponds exactly to the index in
27-
* any of the courses[].
28-
*/
29-
public String[] courseNames;
30-
/**
31-
* Array of all tutors.
32-
*/
33-
public Tutor[] tutors;
22+
/**
23+
* Array of all course names. Each index corresponds exactly to the index in any of the courses[].
24+
*/
25+
public String[] courseNames;
26+
/**
27+
* Array of all tutors.
28+
*/
29+
public Tutor[] tutors;
3430

35-
/**
36-
* Array of all slots. Each index corresponds exactly to the slot's sid.
37-
*/
38-
public Slot[] slots;
31+
/**
32+
* Array of all slots. Each index corresponds exactly to the slot's sid.
33+
*/
34+
public Slot[] slots;
3935

40-
/**
41-
* Initialize some data fields not done by the JSON parser.
42-
*/
43-
public void init() {
44-
// initialize the adjacent slot references
45-
for (Slot s : slots) {
46-
s.adjacentSlots = new Slot[s.adjacentSlotIDs.length];
47-
for (int i = 0; i < s.adjacentSlots.length; ++i) {
48-
for (Slot t : slots) {
49-
if (t.sid == s.adjacentSlotIDs[i]) {
50-
s.adjacentSlots[i] = t;
51-
break;
52-
}
53-
}
54-
}
36+
/**
37+
* Initialize some data fields not done by the JSON parser.
38+
*/
39+
public void init() {
40+
// initialize the adjacent slot references
41+
for (Slot s : slots) {
42+
s.adjacentSlots = new Slot[s.adjacentSlotIDs.length];
43+
for (int i = 0; i < s.adjacentSlots.length; ++i) {
44+
for (Slot t : slots) {
45+
if (t.sid == s.adjacentSlotIDs[i]) {
46+
s.adjacentSlots[i] = t;
47+
break;
48+
}
5549
}
50+
}
5651
}
52+
}
5753

58-
/**
59-
* Returns a string of all assignments in the set of slots. Output is
60-
* formatted in rows of "[SLOT_ID] [TUTOR_ID]" if no slot is assigned to the
61-
* tutor, [TUTOR_ID] is -1.
62-
*/
63-
public String assignments() {
64-
String ret = "";
65-
for (Slot s : slots) {
66-
ret += String.valueOf(s.sid) + " ";
67-
ret += String.valueOf(s.tutors.get(0).tid);
68-
for (int i = 1; i < s.tutors.size(); i++)
69-
ret += " " + String.valueOf(s.tutors.get(i).tid);
70-
ret += "\n";
71-
}
72-
return ret.trim();
54+
/**
55+
* Returns a string of all assignments in the set of slots. Output is formatted in rows of
56+
* "[SLOT_ID] [TUTOR_ID]" if no slot is assigned to the tutor, [TUTOR_ID] is -1.
57+
*/
58+
public String assignments() {
59+
String ret = "";
60+
for (Slot s : slots) {
61+
ret += String.valueOf(s.sid) + " ";
62+
ret += String.valueOf(s.tutors.get(0).tid);
63+
for (int i = 1; i < s.tutors.size(); i++)
64+
ret += " " + String.valueOf(s.tutors.get(i).tid);
65+
ret += "\n";
7366
}
67+
return ret.trim();
68+
}
7469

75-
public String formattedAssignments() {
76-
JsonObject jason = new JsonObject();
77-
for (Slot s : slots) {
78-
JsonArray j = new JsonArray();
79-
for (Tutor t : s.tutors) {
80-
j.add(new JsonPrimitive(t.tid));
81-
}
82-
jason.add(s.name.substring(s.name.length() - 3), j);
70+
public String formattedAssignments() {
71+
JsonObject jason = new JsonObject();
72+
for (Slot s : slots) {
73+
JsonArray j = new JsonArray();
74+
for (Tutor t : s.tutors) {
75+
j.add(new JsonPrimitive(t.tid));
8376
}
84-
85-
return jason.toString();
86-
}
87-
88-
public String readableFormattedAssignments() {
89-
String ret = "";
90-
for (Slot s : slots) {
91-
ret += s.details();
92-
for (int i = 0; i < s.tutors.size(); i++)
93-
ret += " " + String.valueOf(s.tutors.get(i).name);
94-
ret += "\n";
95-
}
96-
return ret.trim();
97-
}
98-
99-
public void clearAssignments() {
100-
for (int i = 0; i < tutors.length; i++)
101-
tutors[i].slots = new ArrayList <Slot> ();
102-
for (int i = 0; i < slots.length; i++)
103-
slots[i].tutors = new ArrayList <Tutor> ();
77+
jason.add(s.name.substring(s.name.length() - 3), j);
10478
}
10579

106-
@Override
107-
public String toString() {
108-
return "Data {" + "courseNames=" + Arrays.toString(courseNames)
109-
+ ", tutors=" + Arrays.toString(tutors) + ", slots="
110-
+ Arrays.toString(slots) + "}";
111-
}
112-
113-
@Override
114-
public Data clone() {
115-
Data ret = new Data();
116-
// ret.courseNames = courseNames.clone();
117-
ret.tutors = tutors.clone();
118-
ret.slots = slots.clone();
119-
return ret;
80+
return jason.toString();
81+
}
82+
83+
public String readableFormattedAssignments() {
84+
String ret = "";
85+
for (Slot s : slots) {
86+
ret += s.details();
87+
for (int i = 0; i < s.tutors.size(); i++)
88+
ret += " " + String.valueOf(s.tutors.get(i).name);
89+
ret += "\n";
12090
}
91+
return ret.trim();
92+
}
93+
94+
public void clearAssignments() {
95+
for (int i = 0; i < tutors.length; i++)
96+
tutors[i].slots = new ArrayList<Slot>();
97+
for (int i = 0; i < slots.length; i++)
98+
slots[i].tutors = new ArrayList<Tutor>();
99+
}
100+
101+
@Override
102+
public String toString() {
103+
return "Data {" + "courseNames=" + Arrays.toString(courseNames) + ", tutors="
104+
+ Arrays.toString(tutors) + ", slots=" + Arrays.toString(slots) + "}";
105+
}
106+
107+
@Override
108+
public Data clone() {
109+
Data ret = new Data();
110+
// ret.courseNames = courseNames.clone();
111+
ret.tutors = tutors.clone();
112+
ret.slots = slots.clone();
113+
return ret;
114+
}
121115

122116
}

src/Items/Slot.java

Lines changed: 49 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -7,64 +7,63 @@
77
import java.util.ArrayList;
88

99
public class Slot {
10-
public Slot() {
11-
tutors = new ArrayList<Tutor>();
12-
}
10+
public Slot() {
11+
tutors = new ArrayList<Tutor>();
12+
}
1313

14-
// identifying information
15-
public int sid;
16-
public String name;
17-
public String day;
18-
public int hour;
19-
public String office;
14+
// identifying information
15+
public int sid;
16+
public String name;
17+
public String day;
18+
public int hour;
19+
public String office;
2020

21-
// preference information
22-
public int[] courses;
23-
public int[] adjacentSlotIDs;
24-
public Slot[] adjacentSlots;
25-
public Slot[] simultaneousSlots;
21+
// preference information
22+
public int[] courses;
23+
public int[] adjacentSlotIDs;
24+
public Slot[] adjacentSlots;
25+
public Slot[] simultaneousSlots;
2626

27-
public ArrayList<Tutor> tutors;
27+
public ArrayList<Tutor> tutors;
2828

29-
public void assign(Tutor t) {
30-
tutors.add(t);
31-
}
32-
33-
public boolean unassign (Tutor t) {
34-
return tutors.remove(t);
35-
}
29+
public void assign(Tutor t) {
30+
tutors.add(t);
31+
}
3632

37-
public boolean simultaneous(Slot s) {
38-
return (hour == s.hour) && str_equals(day, s.day);
39-
}
33+
public boolean unassign(Tutor t) {
34+
return tutors.remove(t);
35+
}
4036

41-
public boolean adjacent(Slot s) {
42-
for (int i = 0; i < adjacentSlots.length; i++)
43-
if (adjacentSlots[i].equals(s))
44-
return true;
45-
return false;
46-
}
37+
public boolean simultaneous(Slot s) {
38+
return (hour == s.hour) && str_equals(day, s.day);
39+
}
4740

48-
@Override
49-
public boolean equals(Object other) {
50-
if (!(other instanceof Slot))
51-
return false;
52-
return sid == ((Slot) other).sid && hour == ((Slot) other).hour
53-
&& str_equals(name, ((Slot) other).name)
54-
&& str_equals(day, ((Slot) other).day)
55-
&& str_equals(office, ((Slot) other).office);
56-
}
41+
public boolean adjacent(Slot s) {
42+
for (int i = 0; i < adjacentSlots.length; i++)
43+
if (adjacentSlots[i].equals(s))
44+
return true;
45+
return false;
46+
}
5747

58-
public static boolean str_equals(String a, String b) {
59-
return a == null ? b == null : a.equals(b);
60-
}
48+
@Override
49+
public boolean equals(Object other) {
50+
if (!(other instanceof Slot))
51+
return false;
52+
return sid == ((Slot) other).sid && hour == ((Slot) other).hour
53+
&& str_equals(name, ((Slot) other).name) && str_equals(day, ((Slot) other).day)
54+
&& str_equals(office, ((Slot) other).office);
55+
}
6156

62-
public String details() {
63-
return office + " " + day + " " + hour + " " + sid;
64-
}
57+
public static boolean str_equals(String a, String b) {
58+
return a == null ? b == null : a.equals(b);
59+
}
6560

66-
@Override
67-
public String toString() {
68-
return sid + "@" + name;
69-
}
61+
public String details() {
62+
return office + " " + day + " " + hour + " " + sid;
63+
}
64+
65+
@Override
66+
public String toString() {
67+
return sid + "@" + name;
68+
}
7069
}

0 commit comments

Comments
 (0)