-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathComparisonGraph.java
More file actions
57 lines (50 loc) · 1.87 KB
/
Copy pathComparisonGraph.java
File metadata and controls
57 lines (50 loc) · 1.87 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
import java.util.*;
import java.awt.*;
/**
* contains a method for drawing a graph that compares the frequency of a given keyword on different news sites
*/
public class ComparisonGraph extends Graph {
private WebScraper FN = null;
private WebScraper WP = null;
private WebScraper NM = null;
private WebScraper NPR = null;
private String keyWord = null;
/**
* Constructor for ComparisonGraph
* @param keyWord - the word that will be compared
* @param length - the length of the graph
* @param height - the height of the graph
* @param FN - the WebScraper object for Fox News
* @param WP - the WebScraper object for the Washington Post
* @param NM - the WebScraper object for News Max
* @param NPR - the WebScraper object for NPR
*/
public ComparisonGraph (String keyWord, int length, int height, WebScraper FN, WebScraper WP, WebScraper NM, WebScraper NPR) {
super( length, height );
this.keyWord = keyWord;
this.FN = FN;
this.WP = WP;
this.NM = NM;
this.NPR = NPR;
}
/**
* draws the comparison graph of the given keyword
*/
public void draw() {
super.draw();
// Keyword
g.drawString(keyWord, 80*length/2, 20);
// x-axis labels and bars
String[] names = {"Fox News", "Wash Post", "News Max", "NPR"};
ArrayList<WebScraper> scrapers = new ArrayList<WebScraper>();
scrapers.add(FN);
scrapers.add(WP);
scrapers.add(NM);
scrapers.add(NPR);
for (int i = 0; i < 4; i++) {
g.drawString(names[i], 8*height + 70*i, 75*height - 7*height + 20 );
g.fillRect( height*8 + 70*i, 75*height - 7 * height - 29 * ( scrapers.get(i).findCount(keyWord) ),
50, 29 * ( scrapers.get(i).findCount(keyWord) ) );
}
}
}