GMU Fall 2022 – CS 211 – Exercise 3• This exercise is worth 5% of your total grade (instead of 3%)• Additionally, there is an optional task for 1% extra creditDue Date: Friday, December 2nd,...

Hi I need assistance with a java assignment involving java iterators, and I have attached the document containing the requirements below as well as the .txt file it the program needs to use. Please follow all the instructions on how to create the methods.


GMU Fall 2022 – CS 211 – Exercise 3 • This exercise is worth 5% of your total grade (instead of 3%) • Additionally, there is an optional task for 1% extra credit Due Date: Friday, December 2nd, 11:59pm 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 different iterators. Additionally, you can optionally implement a GUI to make your application more user-friendly and get some extra credit. Instructions  Honor Code : This assignment is individual work of each student, you’re not allowed to collaborate in any form. Copying code from other sources (peers, websites, etc.) is a serious violation of the University’s Honor Code. Your code will be examined for similarities with other sources.  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 fields should be made private. All methods provided in the specification are public. You may add any fields 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: 1. Create the file ID.txt in the format shown below, containing your name, userid, G#, lecture section and lab section Full Name: George Mason userID: gmason G#: 01234567 Lecture section: 003 Lab section: 213 2. Upload the ID.txt and the source files (*.java) to Gradescope without zipping them https://www.gradescope.com/courses/453172/assignments/2455998 3. Download the files you just uploaded to Gradescope and recompile/rerun the code to verify that the upload was correct 4. Make a backup of your files on OneDrive (use your mason account) If you skip steps 3 and 4 and your submission is wrong and/or files are missing from it, you will get zero points and there will be no excuse! 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. https://www.gradescope.com/courses/453172/assignments/2455998 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 specification 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 file that contains all the posts of RateMyTeacher (to simplify the assignment, you don’t have to extract any reviews yourself but the file is provided). Feel free to edit the file for testing purposes. The file 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 file should be a multiple of 3 (no empty lines between the reviews). A sample file 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 fields 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 fluent 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 fields 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 first 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 fields are private. You can declare anything you want. Methods ReviewList(File f) The constructor accepts a File object (warning: this is not a filename), it reads the reviews contained in the file 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 file 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 fields, 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 scientific 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()
Nov 30, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here