-
Notifications
You must be signed in to change notification settings - Fork 0
/
MovieReview.java
95 lines (75 loc) · 2.97 KB
/
MovieReview.java
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
/**COMP163 Movie Review Evaluation
Dr. Ken Williams
Dorian Holmes
11/03/2017
*/
public class MovieReview{
public static void main ( String [] args)throws java.io.IOException {
java.io.File data = new java.io.File("movieReviews.txt");
java.util.Scanner info = new java.util.Scanner( data) ;
/**
Get file from folder.
declare as object in program.
*/
java.util.Hashtable<String, WordValue> dict = new java.util.Hashtable<>(18000);
/** Put an object in the dictionary,giving it both the WordValue object to store.
In the dictionary and a key String to find it.
Declare begin as WordValue reference.
While read more data in the file.
Read rating level number.
Read next word.
Convert to lower case.
While word not equal to "." and if first character is a letter the word will not be ignored.
*/
WordValue begin;
int rating = 0,tempRating = 0; //declare variables
String word;
while( info.hasNext()){
rating = info.nextInt();
word = info.next().toLowerCase();
while( !word.equals(".")){
if(Character.isLetter(word.charAt(0))){
begin = dict.get(word);
if( null == begin){
begin = new WordValue(tempRating);
dict.put( word,begin );
}else{
begin.addRating( tempRating) ;
}
}
info.next();
word = word.toLowerCase();
}
}
/**
Read user's keyboard.
Convert word to lower case.
If begin not null program will add begin.avgRating() to sum for review.
Increment count of words in review.
Read word and convert to lower case review average is sum dived by count of words.
If review average is greater than 2.0 display positive else display negative.
*/
java.util.Scanner keyboard = new java.util.Scanner(System.in) ;
System.out.println(" Enter in your Review" );
String userReview = keyboard.next();
userReview= userReview.toLowerCase();
double ratingTotal=0;
double count=0;
while (! userReview.equals(".")){
begin = dict.get(userReview);
count++;
if ( begin != null ) {
ratingTotal= begin.avgRating();
begin.addRating(tempRating);
}
userReview= userReview.toLowerCase();
}
double amountOfAvg = ratingTotal/ count;
System.out.println( " The average of this rating is " + ratingTotal );
if ( amountOfAvg > 2.0){
System.out.println (" Positive Review");
}else{
System.out.println( " Negative Review");
}
}
}