Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d734a4d

Browse files
Add files via upload
1 parent 4315ee6 commit d734a4d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1456
-0
lines changed

‎Week 3/Assignment 2/AllFilters.class

966 Bytes
Binary file not shown.

‎Week 3/Assignment 2/AllFilters.ctxt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#BlueJ class context
2+
comment0.target=AllFilters
3+
comment1.params=
4+
comment1.target=AllFilters()
5+
comment2.params=f
6+
comment2.target=void\ addFilter(Filter)
7+
comment3.params=id
8+
comment3.target=boolean\ satisfies(java.lang.String)
9+
numComments=4

‎Week 3/Assignment 2/AllFilters.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import java.util.ArrayList;
2+
3+
public class AllFilters implements Filter {
4+
ArrayList<Filter> filters;
5+
6+
public AllFilters() {
7+
filters = new ArrayList<Filter>();
8+
}
9+
10+
public void addFilter(Filter f) {
11+
filters.add(f);
12+
}
13+
14+
@Override
15+
public boolean satisfies(String id) {
16+
for(Filter f : filters) {
17+
if (! f.satisfies(id)) {
18+
return false;
19+
}
20+
}
21+
22+
return true;
23+
}
24+
}
889 Bytes
Binary file not shown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#BlueJ class context
2+
comment0.target=DirectorsFilter
3+
comment1.params=directors
4+
comment1.target=DirectorsFilter(java.lang.String)
5+
comment2.params=id
6+
comment2.target=boolean\ satisfies(java.lang.String)
7+
numComments=3
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
/**
3+
* DirectorsFilter can be used to extract movies directed by either of the specified directors
4+
* in the method parameter.
5+
*
6+
* @ Konstantin Krumin
7+
* @ Version: 1.0 (February 20, 2020)
8+
*/
9+
10+
import java.util.*;
11+
12+
public class DirectorsFilter implements Filter {
13+
String directorsList;
14+
15+
public DirectorsFilter (String directors) {
16+
directorsList = directors;
17+
}
18+
19+
@Override
20+
public boolean satisfies(String id) {
21+
String[] directorsSplit = directorsList.split(",");
22+
for (int i=0; i < directorsSplit.length; i++) {
23+
if (MovieDatabase.getDirector(id).indexOf(directorsSplit[i]) != -1) {
24+
return true;
25+
}
26+
}
27+
return false;
28+
}
29+
}
2.14 KB
Binary file not shown.

‎Week 3/Assignment 2/EfficientRater.ctxt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#BlueJ class context
2+
comment0.target=EfficientRater
3+
comment1.params=id
4+
comment1.target=EfficientRater(java.lang.String)
5+
comment2.params=item\ rating
6+
comment2.target=void\ addRating(java.lang.String,\ double)
7+
comment3.params=item
8+
comment3.target=boolean\ hasRating(java.lang.String)
9+
comment4.params=
10+
comment4.target=java.lang.String\ getID()
11+
comment5.params=item
12+
comment5.target=double\ getRating(java.lang.String)
13+
comment6.params=
14+
comment6.target=int\ numRatings()
15+
comment7.params=
16+
comment7.target=java.util.ArrayList\ getItemsRated()
17+
numComments=8

‎Week 3/Assignment 2/EfficientRater.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
2+
/**
3+
* EfficientRater class contains various methods that are used to add and extract ratings
4+
* from the ratings HashMap.
5+
*
6+
* @ Konstantin Krumin
7+
* @ Version: 1.0
8+
*/
9+
10+
import java.util.*;
11+
12+
public class EfficientRater implements Rater {
13+
private String myID;
14+
private HashMap<String,Rating> myRatings;
15+
16+
public EfficientRater(String id) {
17+
myID = id;
18+
myRatings = new HashMap<String,Rating> ();
19+
}
20+
21+
public void addRating(String item, double rating) {
22+
myRatings.put(item, new Rating(item,rating));
23+
}
24+
25+
public boolean hasRating(String item) {
26+
if (myRatings.containsKey(item)) {
27+
return true;
28+
}
29+
30+
return false;
31+
}
32+
33+
public String getID() {
34+
return myID;
35+
}
36+
37+
public double getRating(String item) {
38+
for (String movieID : myRatings.keySet()) {
39+
if (movieID.equals(item)) {
40+
return myRatings.get(movieID).getValue();
41+
}
42+
}
43+
44+
return -1;
45+
}
46+
47+
public int numRatings() {
48+
return myRatings.size();
49+
}
50+
51+
public ArrayList<String> getItemsRated() {
52+
ArrayList<String> list = new ArrayList<String> ();
53+
for (String movieID : myRatings.keySet()) {
54+
list.add(myRatings.get(movieID).getItem());
55+
}
56+
57+
return list;
58+
}
59+
}

‎Week 3/Assignment 2/Filter.class

137 Bytes
Binary file not shown.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /