AP CSA 2022 Q3 - ReviewAnalysis Class
| <-- Back to Solution of Q2 (TextBook) - FRQ - 2022 | Next to Solution of Q4 (Data) - FRQ - 2022 --> |
Solution of Q3 (ReviewAnalysis) - Free Response Question - 2022
The original question can be found at: https://apcentral.collegeboard.org/media/pdf/ap22-frq-computer-science-a.pdf
Part (a)- public double getAverageRating()
public double getAverageRating()
{
int sum=0;
for (int i=0; i< allReviews.length; i++)
{
sum = sum + allReviews[i].getRating();
}
return ((double)sum/allReviews.length);
}
Part (b)- public ArrayList
public ArrayList collectComments()
{
ArrayList arr = new ArrayList();
String str= "";
for (int i=0; i < allReviews.length; i++)
{
str= "";
if (allReviews[i].getComment().indexOf("!") != -1)
{
//found; form the string and add to arraylist
str = i+"-"+allReviews[i].getComment();
if (!allReviews[i].getComment().endsWith(".") && !allReviews[i].getComment().endsWith("!"))
{
str = str + ".";
}
arr.add(str);
}
}
return arr;
}
Java project files (with Runner code):
| <-- Back to Solution of Q2 (TextBook) - FRQ - 2022 | Next to Solution of Q4 (Data) - FRQ - 2022 --> |