Create a program that maintains a list of dogs (provided below in txt file). Begin by reading the file (below named Dog.txt), create a Dog object for each part of the file and load the Dog object into the MultiSet. Note that if the Dog object already exists In MultiSet, then the program will increment the value of the count for that Dog object. Then continue by showing the menu below and asking for user input.
Working with TreeMultiSet and MultiSets
*In Java only*. I'm learning about the topics below and would love to see this
You will have 4 different classes (please keep them separated as best as possible/use names provided below for classes):
-
Multiset class: Make a multiset interface that does not extend anything. public interface MultiSet<AnyType> Test the MultiSet by adding Strings and test if duplicates are counted.
-
TreeMultiSet class: It implements MultiSet but does not extend. Use private TreeMap<AnyType, Integer> map; (to look for any duplicates) override toString in the TreeMultiSet class.
-
Dogs class needs to implement Comparable on tagNumber
-
Test class (has main method and methods for the menu) This has the menu and asks for the user input.
Instructions:
Create a program that maintains a list of dogs (provided below in txt file). Begin by reading the file (below named Dog.txt), create a Dog object for each part of the file and load the Dog object into the MultiSet. Note that if the Dog object already exists In MultiSet, then the program will increment the value of the count for that Dog object. Then continue by showing the menu below and asking for user input.
Create a menu with the details below :
-
Show (this lists all the names)
-
Add (ask the user for dog information and add to the multiset)
0. Exit
Create a loop that reshows the menu so that the user can choose again until 0 is chosen for exit.
Use Dog.txt (below) The fields are (from left to right)
tagNumber(string), First name(string), Last name(string), Cost(double)
_________________________________________________________________________
342, Baxter, Ken, 53.50
341, Cooper, Doo, 2005
654, Duke, Hills, 9999.9
356, Elvis, Yoda, 2500
786, Kermit, Toast, 5557
435, Picasso, Prints, 444.09
223, Puck, Net, 298
765, Rocket, Springer, 850
943, Ziggy, Chills, 20.034
239, Arya, Lib, 3456
837, Cassidy, Hansel, 564
- Read the dog information from the input file "Dog.txt".
- Create a new instance of the
TreeMultiSet
class to store the dogs. - Iterate over each line of the input file:
- Split the line into tag number, first name, last name, and cost.
- Create a new
Dog
object with the extracted information. - Add the
Dog
object to theTreeMultiSet
.
- Display the menu to the user.
- Enter a loop to repeat the menu until the user chooses to exit:
- Prompt the user for their choice.
- If the choice is "Show", iterate over the
TreeMultiSet
and print the names of all the dogs. - If the choice is "Add", prompt the user for dog information (tag number, first name, last name, and cost), create a new
Dog
object, and add it to theTreeMultiSet
. - If the choice is "0", exit the loop and end the program.
- If the choice is invalid, display an error message and re-display the menu.
- End the program.
Step by step
Solved in 4 steps with 7 images