Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java coding. No hardcoding and only helper functions allowed package questions; import java.util.ArrayList; import other_classes.Reply; import other_classes.User; public class Review { private ArrayList replies; //

Java coding. No hardcoding and only helper functions allowed

package questions;

import java.util.ArrayList;

import other_classes.Reply; import other_classes.User;

public class Review { private ArrayList replies; // An ArrayList which stores all the replies made within the Review private User reviewer; // The User who wrote the Review private String title; // The title of the Review private int rating; // The rating given out of 10 private int helpful; // The number of times the Review was marked as helpful private int unHelpful; // The number of times the Review was marked as unHelpful /** * 2 marks * This method should print the title of the Review followed by the rating * and all the replies made within it. * * Refer to the last pages of the Assignment PDF for the correct formatting * */ public void printReview() { this.getTitle(); this.getRating(); } /** * 4 marks * @param u - The User to search for * @return the total number of replies posted by the parameter User */ public int totalReplies(User u) { // To be completed return -10; } /** * 4 marks * @param u - the User object to search for * * @return an ArrayList of all Reply objects which were * posted to the Review by the parameter User object. */ public ArrayList findRepliesBy(User u) { // To be completed return null; } /** * 4 marks * This method should find all Reply objects within the replies ArrayList * which contain the target String within their message. * * @param target * @return an ArrayList of Reply objects whose message contains the parameter target. * */ public ArrayList findReplies(String target) { // To be completed return null; } /** * 4 marks * This method should remove the target String from the message * contained within each Reply object in replies. * * @param target - the String to search for and remove * * Hint: replaceAll will be helpful here. */ public void cleanReplies(String target) { // To be completed } /** * 4 marks * This method should remove all Reply objects from replies * whose message contains one of the Strings within the * parameter list. * * It should return an ArrayList containing all the Reply objects * which were removed. * * @param list - a list of Strings to search for * @return an ArrayList containing all Reply objects which * were removed. */ public ArrayList clearReplies(ArrayList list) { // To be completed return null; }

/** * 8 marks * This method should return an ArrayList which contains the unique User objects * which have posted a Reply within the Review * * @return an ArrayList of User objects who have posted within the Review * * Note that there should be no duplicates within the returned ArrayList * */ public ArrayList getUniqueUsers() { // To be completed return null; } /** * * DO NOT EDIT THE BELOW CODE * */ public Review(User reviewer,String title,int rating, int helpful,int unHelpful){ replies = new ArrayList(); this.title = title; this.reviewer=reviewer; this.rating = rating; this.helpful=helpful; this.unHelpful=unHelpful; } public String getTitle() { return title; } public double getHelpfulRatio() { return helpful * 1.0 / (helpful + unHelpful); } public int getRating() { return rating; } public ArrayList getComments(){ return replies; } public User getReviewer() { return reviewer; } public void voteHelpful(boolean h) { if(h) { helpful++; }else { unHelpful++; } } public void addReply(User commentor, String message) { replies.add(new Reply(commentor,message)); } } -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Testing:

package testclients;

import java.util.ArrayList;

import other_classes.Data; import other_classes.Reply; import other_classes.User; import questions.Review;

public class ReviewClient {

public static void main(String[] args) {

// This file can be used to test your Review.java solutions

// First lets create a Review Object (for more information read Data.java) Review r1 = Data.review1(); // Checking totalReplies: System.out.println("--- Testing totalReplies ---"); System.out.println(r1.totalReplies(Data.getUser(4))); // Has replies System.out.println(r1.totalReplies(Data.getUser(5))); // Has no replies System.out.println(r1.totalReplies(Data.getUser(1))); // Has 1 reply // Checking findRepliesBy System.out.println("--- Testing findRepliesBy ---"); // This user has posts for(Reply r : r1.findRepliesBy(Data.getUser(1))){ System.out.println(r); } // This user has no posts for(Reply r : r1.findRepliesBy(Data.getUser(0))){ System.out.println(r); } // Checking findReplies System.out.println("--- Testing findReplies ---"); // This user has posts for(Reply r : r1.findReplies("")){ System.out.println(r); } // This user has no posts for(Reply r : r1.findReplies("")){ System.out.println(r); } System.out.println("--- Testing uniqueUsers ---"); for(User u : r1.getUniqueUsers()){ System.out.println(u); } // Checking cleanReplies: r1.cleanReplies("No change"); // This should not effect anything r1.cleanReplies("bad"); // This should remove the word "bad" from all Replies

// Checking clearReplies: ArrayList toClear = new ArrayList(); toClear.add("insult"); toClear.add("rude"); toClear.add("cancel"); r1.clearReplies(toClear); // This should remove all Reply objects containing the above words // Checking printReview System.out.println("--- Testing printReview, clearReplies and cleanReplies ---"); r1.printReview();

} }

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Required Output ReviewClient.java

Below is the required output when executing ReviewClient.java:

--- Testing totalReplies ---

4

0

1

--- Testing findRepliesBy ---

Kiera Moses: This was a bit rude

Lincoln Walter: I thought this movie was bad

--- Testing findReplies ---

Amaya Lyons: Thank you for taking the time to write a review of the movie.

Lincoln Walter: I thought this movie was bad

Kiera Moses: This was a bit rude

Amaya Lyons: We appreciate your honest review of the film.

Amaya Lyons: Thank you for your review.

Jacquelyn Mendez: Great review!

Gerald Garner: Nice to see that there were no insults

Troy Powell: I hope this gets cancelled

Emmett House: All I can say is bad bad bad

Amaya Lyons: This was not a bad review

Amaya Lyons: Thank you for taking the time to write a review of the movie.

Lincoln Walter: I thought this movie was bad

Kiera Moses: This was a bit rude

Amaya Lyons: We appreciate your honest review of the film.

Amaya Lyons: Thank you for your review.

Jacquelyn Mendez: Great review!

Gerald Garner: Nice to see that there were no insults

Troy Powell: I hope this gets cancelled

Emmett House: All I can say is bad bad bad

Amaya Lyons: This was not a bad review

--- Testing uniqueUsers ---

User: Amaya Lyons

User: Lincoln Walter

User: Kiera Moses

User: Jacquelyn Mendez

User: Gerald Garner

User: Troy Powell

User: Emmett House

--- Testing printReview, clearReplies and cleanReplies ---

Okay movie 6/10

Amaya Lyons: Thank you for taking the time to write a review of the movie.

Lincoln Walter: I thought this movie was

Amaya Lyons: We appreciate your honest review of the film.

Amaya Lyons: Thank you for your review.

Jacquelyn Mendez: Great review!

Emmett House: All I can say is

Amaya Lyons: This was not a review

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems Uropean Conference Adbis 2020 Lyon France August 25 27 2020 Proceedings Lncs 12245

Authors: Jerome Darmont ,Boris Novikov ,Robert Wrembel

1st Edition

3030548317, 978-3030548315

More Books

Students also viewed these Databases questions