In Java The MyMath Interface public interface MyMath { public T add(T o); public
ID: 3813978 • Letter: I
Question
In Java
The MyMath Interface
public interface MyMath {
public T add(T o);
public T subtract(T o);
public T divide(T o);
public T multiply(T o);
}
You will create two classes, MyFraction and MySet. Each of these classes must implement the above interface. When you implement the interface you must use the correct "generic" for the class which implements the interface:
implements MyMath for the MySet class
The MySet Class
NOTE: Java has a built in Set class. You may NOT use this class or any of its methods. Also, you may not use any of the built in Java Collection classes inside of your MySet class. This means no ArrayLists, Lists, Maps, etc.
A set is a collection of items in which each item is unique. You will implement a simplified version of the Java Set class. Your MySet class should have a private instance variable which is a reference to an array of ints. A MySet object can be constructed by passing a Java array to its constructor. The constructor of the MySet class should take the given array and create an array of integers in which each value is unique. In other words, if the user creates a MySet object from an array with duplicate values, then your constructor must strip out any duplicates and only keep unique values in the set. This array will be the one which is stored in the instance variable of your MySet class. NOTE: Remember that arrays are fixed in size, so you will have to account for the fact that new sets may have more or less values than an array has space for. You should create new arrays and copy values to them when necessary.
MySet must have an equals() method that tests whether two MySets (the one for which this is an instance method and the one that comes in as a parameter) contain the same integers.
MySet should also implement the methods found in the MyMath interface. Don't get hung up on the name of the methods even if they do not seem to intuitively relate to what the method actually does. Just follow the directions carefully.
add(MySet o) This should return a new MySet object which is the union of two MySet objects. Remember that a set may not contain any duplicate elements, so you must discard duplicates.
subtract(MySet o) This should return a new MySet object which is the relative complement of o in the current MySet. In other words, it should contain only those elements of the current MySet which are not contained in o.
multiply(MySet o) This should return a new MySet object which is the Symmetric Difference of two MySet objects.
divide(MySet o) This should return a new MySet object which is the intersection of two MySet objects.
You should also implement toString() to print your MySet objects.
Explanation / Answer
#include
#include "w7integer.h"
using std::cout;
int main()
cout << total << ' ';
return 0;
}
// w7integer_subtract.cpp
#include
#include "w7integer.h"
using std::cout;
int main() ;
string val2[] = ;
for (int i = 0; i < 7; i++)
compare(val1[i], val2[i]);
string s[] = ;
for (int i = 0; i < 5; i++)
testbool(s[i]);
}
// w7integer_zero.cpp
#include
#include "w7integer.h"
using std::cout;
int main() a pair of << ' ' << three * i << ' ' << i*i + four << ' ';
string val1[] = ;
string val2[] = ;
for (int i = 0; i < 10; i++)
return 0;
}
// w7integer_divide.cpp
#include
#include "w7integer.h"
using std::cout;
int main() > i) {
cout
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.