Problem: Re-do HW#4 to add either a BST or HashMap/LinkedHashMap/TreeMap of RomanNumeral objects (instead of array), where (if using a Map) the "key" is the RomanNumeral int value, and the "value" is the RomanNumeral object (NOTE: BECAUSE THIS IS UPDATED SO LATE, I'LL ACCEPT THE KEY TO BE THE romNumStr String, BUT BE AWARE IF IT'S THE STRING, YOUR OUTPUT WILL BE DIFFERENT). You'll need to make the RomanNumeral implement Comparable so you'll have to override compareTo(RomanNumeral parameter) (which will compare the int values, must be unique if using a HashMap). Change the display method to traverse the BST (inorder) or HashMap iterator.
Other than making RomanNumeral implement Comparable and adding a compareTo method, keep the same RomanNumeral class as specified on Prog. HW#4. If your Prog. HW#4 wasn't working correctly or you left out parts, be sure to fix it.
In a separate file from RomanNumeral or BST (see below), write a driver class (includes main). In main, declare a BST or HashMap/LinkedHashMap/TreeMap of RomanNumeral objects, then do call the following static methods:
a method (in the same class as main that you write) that returns (in a return statement) a BST or HashMap/LinkedHashMap/TreeMap of RomanNumeral objects created from file input or user input (your choice). If reading from an input file, open the file first. In this method, in a loop, call a static method (see A. below) to get a new RomanNumeral, but check if it's the default (value is 0, meaning invalid) OR if it's already in the BST or HashMap/LinkedHashMap/TreeMap , and if not, insert it into to the BST or HashMap/LinkedHashMap/TreeMap. Read until the end of file (if you choose to read from a file) or until the user indicates no more input.
display each object's toString ONLY by traversing the BST inorder OR using an iterator for the HashMap/LinkedHashMap/TreeMap .
a method (in the same class as main that you write) to return the sum of the RomanNumerals in the BST or HashMap/LinkedHashMap/TreeMap of RomanNumeral objects (described in B. below) (main will display the return value with a label, something like "The sum of the Roman Numerals = ")
In the method that reads a String and returns a RomanNumeral, you may read from the user OR read from a file (Scanner object should be a parameter if reading from a file, or NO parameters if reading from the user). If reading from the user, prompt the user for a roman numeral (with Roman Numeral chars, NOT ints). Read into a local String. Return a new RomanNumeral (with the input String) or null if end of file.
In the method that finds the sum of the RomanNumerals in the BST or HashMap/LinkedHashMap/TreeMap of RomanNumeral objects, traverse the BST or HashMap/LinkedHashMap/TreeMap of RomanNumeral objects using the BST iterator: public java.util.Iterator inorderIterator() (or iterator from the Map) and using the add instance method in the RomanNumeral class (it generates lot of garbage, but this is just for practice). Return the sum (int) in a return statement. DON'T PRINT IN THIS METHOD.
It is not our intention to break the school's academic policy. Projects posted are only used as a reference
and should not be submitted as is. We are not held liable for any misuse of the solutions.
Please see the frequently asked questions page
for further questions and inquiries.
Kindly fill out the form.
Please provide a valid email address and we'll get back to you in less than 24 hours.
We will be sending an invoice through PayPal upon confirmation.
We are a non profit organization however we need an amount to keep this organization running,
and to be able to complete our research and development.