-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcourseCalc.java
More file actions
52 lines (39 loc) · 1.01 KB
/
Copy pathcourseCalc.java
File metadata and controls
52 lines (39 loc) · 1.01 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
/**
* courseCalc calculates the course average
* @author jhou25
*
*/
public class courseCalc{
//Instance variables
private stackImplement stack;
//Constructor
public courseCalc(stackImplement implement){
stack = implement;
}
/**
* Get the Average
* @return
*/
public double getAverage(){
double total = 0.0;
int length = stack.size();
for(int x = 0; x < length; x ++){
total = total + stack.pop();
}
return total;
}
public static void main(String[] args) {
//Let user enter a number, number of evaluation methods
stackImplement stack = new stackImplement(5);
// let user add mark and weight
stack.push(60.3, 0.2);
stack.push(79.3, 0.2);
stack.push(89.2, 0.2);
stack.push(84.7, 0.2);
stack.push(92.5, 0.2);
//get the mark
courseCalc calc = new courseCalc(stack);
//display the mark
System.out.println("Your average is: " + calc.getAverage() + "%");
}
}