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

*I only need help on the sorting method, as described with the note below. I can

ID: 3627569 • Letter: #

Question

*I only need help on the sorting method, as described with the note below. I can write it with the built-in tools, but am having troubles writing an alogrithim to sort the sets.*

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


*Note: You MUST write the sort method yourself. You are NOT allowed to use any sorting methods that you may find built into Java.

Explanation / Answer

please rate - thanks

left f-i for you as requested

{System.out.print("set "+m+"{");
int i;
for(i=0;i<n-1;i++)
System.out.print(s[i]+
", ");
System.out.println(s[n-1]+
"}");
}
}


import java.util.*;
public class Main
{
public static void main(String[] args)
{
int n1=0,n2=0,i,j;
Scanner in=
new Scanner(System.in);
int []set1=new int[20];
int []set2=new int[20];
n1=getSet(set1,
"1",in);
sort(set1,n1);
n2=getSet(set2,
"2",in);
sort(set2,n2);
print(set1,n1,
"1");
print(set2,n2,
"2");
}
public static int getSet(int set[],String mess,Scanner in)
{
int i=0,n;
System.out.print(
"How many numbers in set "+mess+"? ");
n=in.nextInt();
while(n<1||n>20)
{System.out.println(
"must be between 1 and 20");
System.out.print(
"How many numbers in set "+mess+"? ");
n=in.nextInt();
}
for(i=0;i<n;i++)
{System.out.print(
"Enter number "+(i+1)+": ");
set[i]=in.nextInt();
}
return n;
}
public static void sort(int set[],int n)
{
int i,j,t;
for(i=0;i<n-1;i++)
for(j=i;j<n;j++)
if(set[i]>set[j])
{t=set[i];
set[i]=set[j];
set[j]=t;
}
}
public static void print(int s[],intn,String m)