forked from haonlywan/CodeHS-Java-APCSA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3.3.7 Ratings (Part 2)
55 lines (47 loc) · 1.26 KB
/
3.3.7 Ratings (Part 2)
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
public class Rater
{
private String name; // name of company
private double rating; // number rating (1 - 5)
private String review; // review shown with company name
public Rater(String company, double initialRating)
{
name = company;
rating = initialRating;
review = "";
}
// Set rating to newRating
// As long as it's no more than 5
public void setRating(double newRating)
{
if (newRating < 5.0){
rating = newRating;
} else if (newRating == 5.0) {
rating = 5.0;
}
}
// Updates review line based on rating
public void updateReview()
{
if (rating >= 3.0){
review = "Proudly recommended";
} else{
review = "Needs more ratings";
}
}
// Returns the rating of the company
public double getRating()
{
return rating;
}
// Returns a string representation of the company
// Uses the form
// name: review
public String toString()
{
if (rating >= 3.0){
return name + " : " + review;
} else{
return name + " : " + review;
}
}
}