-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEssay.java
More file actions
122 lines (99 loc) · 2.33 KB
/
Essay.java
File metadata and controls
122 lines (99 loc) · 2.33 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
package Chapter9;
/**
* Essay class Chapter 9, Programming Challenge 4
*/
public class Essay extends GradedActivity {
private double grammar; // Points for grammar
private double spelling; // Points for spelling
private double correctLength; // Points for length
private double content; // Points for content
/**
* setScore method Overloads the base class method. Note that the other
* "set" methods are private. Those methods are for validating points before
* they are assigned.
*/
public void setScore(double gr, double sp, double len, double cnt) {
// Set the individual scores.
setGrammar(gr);
setSpelling(sp);
setCorrectLength(len);
setContent(cnt);
// Set the total score.
super.setScore(grammar + spelling + correctLength + content);
}
/**
* setGrammar method This method validates that the grammar points before
* they are set.
*/
private void setGrammar(double g) {
if (g <= 30.0)
grammar = g;
else
// Invalid points
grammar = 0.0;
}
/**
* setSpelling method This method validates that the spelling points before
* they are set.
*/
private void setSpelling(double s) {
if (s <= 20.0)
spelling = s;
else
// Invalid points
spelling = 0.0;
}
/**
* setCorrectLength method This method validates that the length points
* before they are set.
*/
private void setCorrectLength(double c) {
if (c <= 20.0)
correctLength = c;
else
// Invalid points
correctLength = 0.0;
}
/**
* setContent method This method validates that the content points before
* they are set.
*/
private void setContent(double c) {
if (c <= 30)
content = c;
else
// Invalid points
content = 0.0;
}
/**
* getGrammar method
*/
public double getGrammar() {
return grammar;
}
/**
* getSpelling method
*/
public double getSpelling() {
return spelling;
}
/**
* getCorrectLength method
*/
public double getCorrectLength() {
return correctLength;
}
/**
* getContent method
*/
public double getContent() {
return content;
}
/**
* The getScore method returns the overall numeric score. Overrides the base
* class method.
*/
public double getScore() {
return grammar + spelling + correctLength + content;
}
}