Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a JAVA program that will be used to perform simple set manipulation. A set

ID: 3627560 • Letter: W

Question

Write a JAVA program that will be used to perform simple set manipulation. A set consists of a list of non-duplicated integers, so the following list of integers:
5, 9, 16, 9, 3, 0, 5
would be stored in a set as follows:
0, 3, 5, 9, 16
Notice that sets are stored in sorted, ascending, order. In the computer, a set is actually a partially-filled array. It, therefore, consists of
1. An array to hold the numbers in the set
2. An integer variable used to keep track of the used size of the array
For this program, any array used to hold a set should be declared to have a size of 20.
In general, your program will need to get two sets from the user, and then perform some calculations using the sets.
Your program should perform the following steps (in the order specified here):
A. Begin by asking the user how many numbers will be in the first set. If the user enters a number larger than the maximum set size (20), you should display an appropriate error message and ask them to reenter a different size. Put this into a loop so that the user cannot continue the program until they enter a correct size.
B. Ask the user to enter the integers that belong in the first set
C. Ask the user how many numbers will be in the second set. If the user enters a number larger than the maximum set size, you should display an appropriate error message and ask them to reenter a different size. Put this into a loop so that the user cannot continue the program until they enter a correct size.
D. Ask the user to enter the integers that belong in the second set
E. Sort the integers in the two sets in ascending order using any sorting algorithm of your choice. You are NOT allowed to use any sorting methods that are already built into Java; you must write your own sorting method!
F. Calculate and display the intersection of the two sets
G. Calculate and display the difference: first set - second set
H. Calculate and display the difference: second set - first set
I. Ask the user if they want to repeat the program again with two different sets. If the user answers "Y" or "y", return to step A.

Definitions:
The intersection of two sets is defined as the list of integers that are common to both sets. For example if we have the following two sets:
A. 1, 5, 7, 8, 12, 20
B. 2, 4, 6, 8, 10, 12, 19, 20, 21
The intersection of set A and set B would be as follows:
8, 12, 20
The difference of two sets is defined as the list of integers in one set that does not appear in the other. For example the difference, A – B, would be all of the numbers in set A which do NOT also appear in set B.
The resulting set would be as follows:
1, 5, 7
The difference, B – A, would be all of the numbers in set B which do NOT also appear in set A. The resulting set would be as follows:
2, 4, 6, 10, 19, 21
Technical notes and restrictions:
• Remember that the keyboard object should be declared as a class variable (global) and initialized only one time - at the beginning of the main program.
• Absolutely NO global variables (class variables) are allowed except for the keyboard object.
• You are only allowed to use the number 20 one time in your program! You are not allowed to use the numbers 20, 19, or any other number that is logically related to 20 anywhere in your program. Your program should be designed so that the maximum size of the sets can be changed by simply changing only one globally defined constant. You should declare a constant called MAXSIZE and set it to be size 20.
• You must write and use the following methods in this program:
1. public static void getData(int [] set, int size)
// This method will retrieve "size" number of unique integers from the keyboard. The integers will be placed into the array “set”.
2. public static int intersection(int [] setA, int sizeA , int [] setB, int sizeB, int [] resultSet)
// This method will calculate the intersection of sets A and B.
// setA and setB are partially filled arrays assumed to be holding properly created sets, in ascending order.
// sizeA and sizeB are the number of elements in setA and setB, respectively
// When the method finishes, resultSet will contain the intersection of sets A and B.
// The return value from the method is the number of elements that were placed into resultSet.
3. public static int difference(int [] setA, int sizeA , int [] setB, int sizeB, int [] resultSet)
// This method calculates the difference (A – B) of the two sets.
// setA and setB are partially filled arrays assumed to be holding properly created sets, in ascending order.
// sizeA and sizeB are the number of elements in setA and setB, respectively
// When the method finishes, resultSet will contain the difference of sets A and B.
// The return value from the method is the number of elements that were placed into resultSet.
4. public static void sort(int [] nums, int size)
// This method will sort the elements in the nums array into ascending order.
// When the method ends, the elements in nums will have been rearranged into sorted, ascending order.
// size is the number of elements in nums
• You are free to add additional methods if you need. Just make sure they have a useful purpose and are properly commented.
• You MUST write the sort method yourself. You are NOT allowed to use any sorting methods that you may find built into Java.
• The intersection, difference and sort methods should NOT print anything to the screen.
• When you write your loop to read in the numbers, the loop shouldn't simply count from 1 to the "set size". The user can theoretically enter an infinite number of integers if duplicates are entered. For example, if the user enters:
5, 9, 4, 5, 5, 3, 5
the user actually entered 7 numbers, however the set size is only 4.

So, for example, even though the arrays are declared to hold only 20 numbers, the user can actually enter 30 numbers if desired. The key point is that 20 of them must be unique. If the user enters 30 numbers where some of them are duplicated, only the 20 unique ones would be stored in the array and therefore, still within the limits of the array declaration.
• Watch out for correct indenting! By now, you should know how to properly indent a program and therefore, indention problems will be penalized heavily! Do not use the SPACEBAR to move lines into their proper positions. Instead, use the TAB key.
Eclipse uses TABs to properly indent your program. If you also using spaces, the mixture of tabs and spaces will cause your lines to be improperly indented if your source code is moved to a different operating system (as I will do when I am testing and grading your programs).
• Make sure your program is neat! I will NOT accept a program that is not neatly laid out!
Use line breaks to separate methods and to separate sections of code.
Don't write long lines that scroll off the right side of the screen or that wrap around to the next line. Break them where appropriate to make them neater.
• YOU MUST WRITE COMMENTS THROUGHOUT YOUR CODE TO EXPLAIN WHAT YOUR CODE IS DOING!
Failure to include accurate, unambiguous, and useful comments will be penalized heavily!
Don’t forget that every method you write is REQUIRED to include comments that explain the purpose of the method, the purpose of the return value (if any), the purpose of every parameter, side effects, and how the method handles expected special cases (i.e. error conditions).

Explanation / Answer

Dear, Due to time up i will post the answer.........
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote