public class Review
{
private int rating;
private String comment;
/** Precondition: r >= 0
* c is not null.
*/
public Review( int r, String c )
{
rating = r;
comment = c;
}
public int getRating()
{
return rating;
}
public String getComment()
{
return comment;
}
}
|
import java.util.ArrayList;
public class ReviewAnalysis
{
/** All user reviews to be included in this analysis */
private Review[] allReviews;
/** Initializes allReviews to contain all the Review objects to be analyzed */
public ReviewAnalysis( int n )
{
allReviews = new Review[n];
}
public double getAverageRating()
{
//write the code for Part A
return 0; // Statement included so program can be compiled, change if necessary
}
public ArrayList
|
Use this Java program to test your answer to question A:
public class TestPartA
{
public static void main(String[] args)
{
ReviewAnalysis x = new ReviewAnalysis(5);
x.add(1, new Review(5, "Great") );
x.add(0, new Review(4, "Good!") );
x.add(2, new Review(5, "Nice job!") );
x.add(3, new Review(1, "No! Bad") );
x.add(4, new Review(3, "") );
System.out.println( x.getAverageRating() );
}
}
|
The correct answer is: 3.6
Use this Java program to test your answer to question B:
public class TestPartB
{
public static void main(String[] args)
{
ReviewAnalysis x = new ReviewAnalysis(5);
x.add(1, new Review(5, "Great") );
x.add(0, new Review(4, "Good!") );
x.add(2, new Review(5, "Nice job!") );
x.add(3, new Review(1, "No! Bad") );
x.add(4, new Review(3, "") );
System.out.println( x.collectComments() );
}
}
|
The correct answer is: [0-Good!, 2-Nice job!, 3-No! Bad.]
Make sure you add the period at the end of the sentence if it was missing !!!