-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRater.java
67 lines (57 loc) · 1.59 KB
/
Rater.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
/**
* Write a description of Rater here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.util.ArrayList;
public class Rater {
public ArrayList<Rating> myRatings;
public String myID;
public Rater(String id)
{
//constructor
myID=id;
}
public void addRating(String item,double rating)
{
// A new Rating is created and added to myRatings.
myRatings.add(new Rating(item,rating));
//here Rating creates an object and item,rating comes from Rating class
}
public String getID()
{
return myID;
}
public double getRating(String item)
{
double m=0.0;
for(int k=0;k<myRatings.size();k++)
{
if(myRatings.get(k).getItem().equals(item))//here k is a position in myRatings where we get Item declared in class
// Rating. The getItem is the variable in class Rating.
{
m= myRatings.get(k).getValue(); // we return value declared in class Rating corresponding to item.
}
else
{
m= -1;
}
}
return m;
}
public int numRatings()
{
int n=myRatings.size();
return n;
}
public ArrayList getItemsRated()
{
ArrayList<String> listofItems = new ArrayList<String>();
for(int i=0;i<myRatings.size();i++)
{
listofItems.add(myRatings.get(i).getItem());
}
return listofItems;
}
}