Question
I HAVE THE FOLLOWING ASSIGNMENT WHICH REQUIRES ME TO ADD WHAT IS ASKED BELOW TO A CODE THAT I ALREADY HAVE......PLEAE HELP AND MAKE COMMENTS
I HAVE THE FOLLOWING ASSIGNMENT WHICH REQUIRES ME TO ADD WHAT IS ASKED BELOW TO A CODE THAT I ALREADY HAVE......PLEAE HELP AND MAKE COMMENTS AS ADDING THE CONSTRUCTORS AND METHOD. THIS IS FOR DISCRETE..... JAVA PLZ
REQUIREMENT:
Extend the Sets class from lab 1.
Remember that has sets for positive integers that you will need the following functions:
addElement , will take a positive integer and add it to the set
Note: you need to change it so that it will not add a duplicate element
getElement, will take a position number and return the element at the position (return -1 if bad position)
getSize, return the size of the set
isSubset, takes a sets object (call it b) and see if the current set (call it a) is a subset of b. If so, return a Boolean true, else return a Boolean false
(You can keep other functions in if need be).
Add the functions of:
unionOps, that takes a Sets object and does a union with the current set
intersection, that takes a Sets object and does an intersection with the current set
printSet, will print the Sets object contents
It is recommended to add a constructor that will take an array and add its elements to the current set.
Define a set a with certain values, like 1, 2, 3, 4 and set b with certain values like 3, 4, 5, 6
Have main create three objects: setA with set a, setB with set b, and setC with set a.
Print the setA, setB, setC
Do an union of setA with setB (setA will be changed) then print setA
Do an intersection of setC (setC will be changed) with setB then print setC...
---------------------------------------------------------------------COPY THIS CODE AND ADD ON TO IT WHAT IS LISTED ABOVE----------------------------------------------------------
//importation of packages import java.util.HashSet; import java.util.Iterator; import java.util.Set; //class public class Sets { Set
--------------------------MAIN-----------------------
//importation of packages import java.util.HashSet; import java.util.Iterator; import java.util.Set; public class Main { //Main (running intSet) public static void main(String args[]) { Sets setA = new Sets(); Sets setB = new Sets(); setA.addElement(3); setA.addElement(5); setA.addElement(8); setB.addElement(3); setB.addElement(4); Sets obj=new Sets(); obj.printOrderedPairs(setA,setB); if(setA.isSubset(setB)) { System.out.println("Set B is subset Of Set A "); } else { System.out.println("Set B is not subset Of A "); }//close else }//close main }
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