• This exercise is worth 5% of your total grade (instead of 3%)• Additionally, there is an optional task for 1% extra creditChangelog• Nothing yet!DescriptionThe purpose of this assignment...

1 answer below »
The assignment is within the file and is due december first.










Thank you in advance!



• This exercise is worth 5% of your total grade (instead of 3%) • Additionally, there is an optional task for 1% extra credit Changelog • Nothing yet! Description The purpose of this assignment is to practice iterators and inner classes in Java and, optionally, graphical user interfaces too. The theme of this assignment is the detection of fake reviews on a popular website called RateMyTeacher which allows anyone to post anonymous ratings of any teacher they want without authenticating themselves. Your task is to write “smart” iterators that are able to traverse list of reviews by skipping any words or posts that are considered fake. There are mainly two approaches in implementing an iterator in Java. One is using a separate class that implements the Iterator interface and the other one is implementing the Iterator interface as an anonymous inner class. You’re going to practice both approaches by writing two di,erent iterators. Additionally, you can optionally implement a GUI to make your application more user-friendly and get some extra credit. Instructions  Validation : Make sure all method parameters are properly validated (e.g. String[] args can’t be empty, etc.)  Documentation : Comments in JavaDoc-style are required. You must comment each class, each method and each instance/class variable you declare. You must also comment any piece of code that is not obvious what it does.  Visibility : All 6elds should be made private. All methods provided in the speci6cation are public. You may add any 6elds or methods you want as long as they are private.  Packages : You may not import any classes except Scanner, File, ArrayList, Iterator Submission Submission instructions are as follows: Grading • Grading will be primarily automated with the use of unit tests. • Manual grading will be used only for checking comments, hard-coding, violations, etc. • If your code doesn’t compile with the provided tester, you will get zero points Testing You will start programming without a tester. The goal is to help you put more focus on writing logically correct programs instead of trying to pass certain tests only. At some point next week, we will provide a small tester that will cover a couple of cases only (less than 10% of the total points). The primary purpose of this tester won’t be the logic/unit testing but to verify that your code complies with the specs and doesn’t crash when compiled with the grading script. Therefore, you shouldn’t wait for the tester in order to start your assignment. Sample code Once you complete your classes, you can plug in the following four alternative loops into your main method to check if your iterators work properly // prints all reviews and all their words without skipping anything ReviewList list = ... for (Review r : list) for (String s : r) System.out.println(s); // prints all reviews and all their words without skipping anything. Same as above. ReviewList list = ... for (Review r : list) { it = r.iterator(); while(it.hasNext()) System.out.println(it.next()); } // skips the suspicious reviews and prints all the words in the non-suspicious reviews it = list.iterator(true); while(it.hasNext()) { Review r = it.next(); for (String s : r) System.out.println(s); } // skips the suspicious reviews and the suspicious words in the non-suspicious reviews it1 = list.iterator(true); while(it1.hasNext()) { Review r = it1.next(); it2 = r.iterator(true); while(it2.hasNext()) System.out.println(it2.next()); } Tasks • You must implement the following four classes based on the speci6cation provided below. • It is recommended that you work on them in the order provided. • Unlike previous assignments, we don’t list the private members of each class. You’re free to implement the private members anyway you want, provided of course that you don’t violate the rules of this assignment. RateMyTeacher This is the entry point to your executable application. We want to be able to use a command line argument when we run the application. Execution in the terminal should look like this: java RateMyTeacher input_file input_file the name of a text 6le that contains all the posts of RateMyTeacher (to simplify the assignment, you don’t have to extract any reviews yourself but the 6le is provided). Feel free to edit the 6le for testing purposes. The 6le contains a series of posts in plain-text format. Each posts consists of three pieces of information, each one in a separate line: a) username of the reviewer. It’s a text without any spaces. b) rating of the teacher. It’s a number that can take one of the following values only: 1, 2, 3, 4, 5 c) comment of the reviewer. It’s a paragraph-long text that includes whitespace characters. To simplify the task, you can assume that all punctuation has been removed during web extraction and pre-processing of the reviews. Based on the above, the number of lines in the 6le should be a multiple of 3 (no empty lines between the reviews). A sample 6le is attached to this document. Fields None Methods public static void main(String[] args) All the handling of the command line arguments as well as the validation of the user input, takes place in this method. After validation is complete, the method should simply create a ReviewList object and then use a for-loop to iterate over it. Review This class represents a single review in a series of posts. It implements the Iterable interface. Fields All 6elds are private. You can declare anything you want. Methods Review(username, rating, comment) The constructor creates the instance and does any initializations you think ae necessary. getUsername() Getter method for the username getRating() Getter method for the rating int getCommentSize() Returns the number of words that exist in the comment of the review String getCommentWord(int N) Returns the Nth word of the comment . Numbering starts from zero. No words can be skipped. All words are guaranteed to be free of punctuation. iterator() The default iterator returns a new ReviewIterator object that iterates over the entire series of words included in the comment without skipping anything. iterator(boolean skipSuspiciousWords) Overloaded iterator. If the parameter is false, it behaves exactly like the above default iterator. If the parameter is true, it returns a new ReviewIterator object that iterates over the words included in the comment but skips the ones that are considered suspicious. Anecdotal evidence suggests that fake reviews are usually written by persons that are Kuent in Gibberish. Therefore, the following words are considered suspicious and must be skipped: veritas, moribus, inmaturitas, malignus ReviewIterator This class represents an iterator for the Review class and it implements the Iterator interface. For the development of this iterator we obviously use the approach of implementing the iterator as a separate class. Fields All 6elds are private. You can declare anything you want. Methods ReviewIterator The constructor can have any parameters you want because, in practice, it’s only the iterator methods of the Review that are going to invoke it. Therefore, the calls inside these methods can use any signature you want. hasNext() It keeps track of the current location of the iterator and returns true or false depending on whether there are more elements to iterate over. This method is called either automatically, behind the scenes, by the for construct, or manually by a while construct, e.g. while(iter.hasNext()) next() Returns the next element of the iteration. You can assume that nobody will call it without 6rst calling the hasNext method and without getting a positive response from it. void remove() We’re not going to implement this operation. You can simply use the following statement just in case anyone tries to call this method: throw new UnsupportedOperationException(); ReviewList This class represents a series of Review objects. You’re free to use either a static or a dynamic array for storing the objects internally. The class implements the Iterable interface. Fields All 6elds are private. You can declare anything you want. Methods ReviewList(File f) The constructor accepts a File object (warning: this is not a 6lename), it reads the reviews contained in the 6le one at a time creating a Review object for each of them, and stores these objects in a data structure which is either a static or a dynamic array (it’s your choice). iterator() Contrary to the approach we followed in the Review class, the default iterator here is going to implement the Iterator interface as an anonymous inner class, i.e. no need to create a separate class for the iterator. This default iterator must return an object that iterates over the entire series of Review objects without skipping anything. Similar to what you did in ReviewIterator, you will fully implement the methods hasNext() and next() and, for the remove() method, you will just add the following statement: throw new UnsupportedOperationException(); iterator(boolean skipSuspiciousReviews) Overloaded iterator. If the parameter is false, it behaves exactly like the above default iterator. If the parameter is true, it returns an iterator that skips the reviews that are considered suspicious. A group of very observant and highly motivated students believes that a true review with a perfect score will not be short. Therefore, we will consider a review to be suspicious if it has a perfect rating (i.e. 5) and a very short comment (it contains 10 words or less). When counting the number of words, the suspicious words must be excluded though. GUI This is an optional task. If you decide to implement a Graphical User Interface class, you must name it GUI and you must still implement the RateMyTeacher class. This means that one should be able to execute your program either as a text-based application by running the RateMyTeacher class or as a graphical application by running the GUI class. This class should provide at a minimum the following functionalities: 1. Select a 6le to open 2. Select what kind of iterations to run. Be reminded that there are four combinations depending on whether you use true/false for the two iterators. 3. Display the result of the iteration You’re free to add more functionalities if you want of course. There are no restrictions on what 6elds, methods, and packages you use in this class but your code must adhere to the OOP principles. Disclaimer: Detection of fake news, reviews, recommendations, etc. is a very hard topic, not only for computers, but for humans too. The “rules” we use in this assignment are not scienti6c and are meant for practice only; you shouldn’t take them at face value. Changelog Description Instructions Submission Grading Testing Sample code Tasks RateMyTeacher input_file Fields Methods public static void main(String[] args) Review Fields Methods Review(username, rating, comment) getUsername() getRating() int getCommentSize() String getCommentWord(int N) iterator() iterator(boolean skipSuspiciousWords) ReviewIterator Fields Methods ReviewIterator hasNext() next() void remove() ReviewList Fields Methods ReviewList(File f) iterator() iterator(boolean skipSuspiciousReviews) GUI studentA+ 3 Anonymia in interrete maior est quaestio pro societate hodierna quae aliquid credit quod in interreti legitur valedictorian2019 4 Vestibulum veritas venenatis nulla nec moribus nisl maximus sagittis Etiam et felis vel ipsum tincidunt porttitor Nullam sit amet risus vel metus aliquet maximus Phasellus ac consectetur odio In porta pretium nisi vitae accumsan est sodales et Mauris orci dui accumsan non efficitur eu pellentesque vitae nisl Donec feugiat consectetur elit at fermentum quam condimentum eget Nullam cursus condimentum odio in elementum dui venenatis scelerisque Curabitur aliquam loveschool 5 Participatio ad universitatem doctrinam aestimationem processus est optimus aditus ad opiniones pretiosos et fideles dropout2003 2 Curabitur vestibulum dolor quam eget pulvinar quam porttitor a Cras semper efficitur dolor id pulvinar elit consequat at Duis pretium molestie justo vel posuere leo Pellentesque non ligula eget arcu porta cursus Donec sed tellus convallis facilisis mauris at rutrum tellus Curabitur ultrices a nibh a commodo Ut mollis condimentum enim sit amet vulputate Praesent eget scelerisque tellus Praesent aliquet tortor eu egestas vestibulum lectus ex best_student_ever 1 Confirmatio inclinatio est proclivitas ad informationes quaerendas interpretandas conciliandas ad gratiam revocandas ita ut prioras opiniones vel valores confirmet vel sustineat virginiaIsForLOVERS 2 Mercatus pro fictus recensiones Marketing Science 2022 Volume 41
Answered 6 days AfterNov 26, 2022

Answer To: • This exercise is worth 5% of your total grade (instead of 3%)• Additionally, there is an...

Vikas answered on Nov 29 2022
42 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here