-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRosterEditer.java
More file actions
86 lines (75 loc) · 1.97 KB
/
Copy pathRosterEditer.java
File metadata and controls
86 lines (75 loc) · 1.97 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
import java.util.NoSuchElementException;
// --== CS400 File Header Information ==--
// Name: Elaina Timmerman
// Email: eltimmerman@wisc.edu
// Team: BA
// Role: back end developer
// TA: Brianna Cochran
// Lecturer: Gary Dahl
// Notes to Grader: <optional extra notes>
// search, adjust grade adjust name and print all
public class RosterEditer {
RedBlackTree<Student> roster = new RedBlackTree();
/**
* constructor for RosterEditor
*
* @param roster
*/
public RosterEditer(RedBlackTree roster) {
this.roster = roster;
}
/**
* searches through roster, using a helper, to find student
*
* @param studentName
* @return student object
*/
public Student search(String studentName) {
Student student = new Student(studentName, 0, 0.0);
return searchHelper(student, roster.root);
}
/**
* search helper method to traverse through RedBlackTree
*
* @param studentName
* @param current
* @return Student object
*/
public Student searchHelper(Student student, RedBlackTree.Node<Student> current) {
if (current == null) {
throw new NoSuchElementException("Student cannot be found");
}
if (student.compareTo(current.data) == 0) {
return current.data;
} else if(student.compareTo(current.data) < 0) {
return searchHelper(student, current.leftChild);
} else if (student.compareTo(current.data) > 0) {
return searchHelper(student, current.rightChild);
} else {
throw new NoSuchElementException("Student cannot be found");
}
}
/**
* searches to find student and change their grade
*
* @param studentName
* @param newGrade
*/
public void adjustGrade(String studentName, Double newGrade) {
search(studentName).setGrade(newGrade);
}
/**
* prints the roster
*
* @return a string of the roster
*/
public String printAll() {
return roster.toString();
}
/**
* clears the roster
*/
public void clear() {
roster.root = null;
}
}