Question
public class MyNewSet { public MyNewSet(){ super(); } public static void main(String[] args) { } } In Java: 1. Add implements Set to
public class MyNewSet{ public MyNewSet(){ super(); } public static void main(String[] args) { } }
In Java:
1. Add "implements Set
2. We want this class to use an ArrayList to implement a Set (as noted above). To do that we will need to override the add method in the ArrayList class to match the Set definition. Write the add method so that we can't add duplicates. Don't forget to use the key word super if you need a super classes method.
3. In the main method create an instance of MyNewSet
String h = "Hello"; String n = "Hey"; String i = "Hello";
Now try to add all 3 Strings to the MyNewSet object and verify that your add method is working the way that you would expect by printing the output to console (leave this part in your code).
4. Next create a new ArrayList
5. Finally, override the addAll method to work as you would expect (hint you should use your add method, google the api to make sure you know what to return and when!). Run your code from 4 above to verify that you got what you expected. (If you don't get this step completed make sure to comment on what you were working on and going to do next).
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started