forked from sensei-thundercleese/closet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatPrinter.java
More file actions
95 lines (71 loc) · 3.26 KB
/
Copy pathStatPrinter.java
File metadata and controls
95 lines (71 loc) · 3.26 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
/*===========================================
An AP-style question, for practice:
Write the StatPrinter class below. The StatPrinter Object receives an
ArrayList of nonnegative integers, then builds a frequency ArrayList in which
the index values are the data and the entry at the index is the frequency.
For example, if the received data is 2,3,2,5,1,3 then the frequency
list would be [0,1,2,2,0,1]. This is read as 0 zeroes, 1 one, 2 twos,
2 threes, 0 fours, 1 five. The size of the frequency list is the equal to
the maximum value of the data.
A capability of the class is to calculate local modes from the frequency
list. A local mode is a value that is greater than the value at index-1
and greater than the value at index+1. A local mode is never at the end
points of the list. For example, if the frequency list is [1,2,1,4,2,3,5]
then the local modes are 2 and 4.
This class is also capable of printing a histogram of the frequencies, using
‘*’s to indicate a frequency amount. To print a histogram, the user specifies
the longest sequence of ‘*’s used and then all other values are printed in
proportion to this value. For example, if longest bar is 10 and the frequency
list is [1,2,1,4,2,3,5] then the histogram printed looks like this:
0 : **
1 : ****
2 : **
3 : ********
4 : ****
5 : ******
6 : **********
For each method, state run time efficiency using Big O notation.
Tips for Awesome:
* Look over all fxns, think a bit, decide which to tackle first.
( Simplest? Prerequisites? . . . )
* Develop 1 fxn at a time, test it, then move to next.
* For coding today, what extra code do you need to get past Mr. Compiler?
===========================================*/
import java.util.ArrayList;
public class StatPrinter {
// instance variable for frequencies of each integer in input ArrayList
private ArrayList <Integer> _frequency;
//*************** QUESTION __ **************************
//precond: data.size() > 0, each entry b/t 0,100 inclusive
//postcond: _frequency.size() set to max(data)+1
// _frequency.get(i) returns frequency of i in data
//eg, for data [2,3,2,5,2,3]
// _frequency would be [0,0,3,2,0,1]
public StatPrinter( ArrayList <Integer> data ) {
}
//*************** QUESTION __ **************************
//precond: data.size() > 0
//postcond: returns largest integer in data
public Integer max( ArrayList <Integer> data ) {
}
//*************** QUESTION __ **************************
//postcond: returns true if i>0 and i<_frequency.size()-1
// and _frequency.get(i-1) < _frequency.get(i)
// and _frequency.get(i+1) < _frequency.get(i)
// Otherwise, returns false
//eg, for _frequency [1,2,1,5,5,8,2,4]
// 2 and 8 are local modes, so
// isLocalMode(0) -> false
// isLocalMode(1) -> true
// isLocalMode(5) -> true
public boolean isLocalMode( int i ) {
}
//*************** QUESTION __ **************************
//postcond: returns list of modes in _frequency
public ArrayList <Integer> getLocalModes() {
}
//*************** QUESTION __ **************************
//precond: longestBar > 0
public void printHistogram( int longestBar ) {
}
}//end class StatPrinter