This is just an intro class i just need help with a basic pr

This is just an intro class i just need help with a basic program, no classes or pointers.

Assignment: Create a program which is capable of assembling and displaying various sets I will provide you with. The program must correctly display the result of operators on sets (such as Union and Intersection), and in addition it must do the following two things: First, it must NOT repeat any values that might appear more than once. So if you Union two sets together that each have the number ‘5’ somewhere in them, then ‘5’ should only appear ONCE in the resulting set. Second, if the resulting thread is empty, your program must indicate the empty thread in some recognizable manner, such as displaying “Empty Thread” or “E” or something similar. Below are the threads you will use. Also assume that the A group comprises ‘reality’ so to speak, the numbers 1-10 being all elements possible, such that the INVERSE of A, is the empty thread. Thus if you were asked to compute the INVERSE of B, it would be equivalent to saying “Set A minus Set B”. For this exercise, we will represent inverse with the ! symbol. (100pts total: 60 for program, 5 per problem)

A = {1,2,3,4,5,6,7,8,9,10}

B = {2,4,6,8,10}

C = {1,3,5,7,9}

D = {1,2,3,5,7}

Problem 1.) A n D

Problem 2.) ( B U C ) n  A

Problem 3.) (!C U C) n  A

Problem 4.) A – D

Problem 5.) N(!A  U ( C U  D))

Problem 6.) B n  C

Problem 7.) N(B n C)

Problem 8.) A U B U C U  D

A reminder, N() indicates the SIZE of the resulting set. So if you have a set such as A = {1,3,7,10} then N(A) = 4. For problems asking for N(), your result should be a single number indicating the resulting set’s size. Finally, a basic hint to help with this assignment: You may find arrays to be useful.

Solution

The Best what I can come up is this code in specific time. Please refer to this code and you need to make just some tweeks, to match your result.

import java.util.TreeSet;

public class SetCalc {

public static void main(String[] args) {

System.out.println(\"This program will compute union, intersection,\");
System.out.println(\"and set difference of sets of integers.\");
System.out.println(\"\");
System.out.println(\"\");
System.out.println(\"Enter set computations (press return to end):\");

while (true) {
char ch;
System.out.print(\"\ ? \");
TextIO.skipBlanks();
if (TextIO.peek() == \'\ \') {

break;
}
try {
calc();
}
catch (IllegalArgumentException e) {
  
System.out.println(\"Error in input: \" + e.getMessage());
System.out.print(\"Discarding input: \");
}
do {
ch = TextIO.getAnyChar();
System.out.print(ch);
} while (ch != \'\ \');
}

}

private static void calc() {

TreeSet<Integer> A, B;
char op;

A = readSet(); // Read the first set.

TextIO.skipBlanks();
if (TextIO.peek() != \'*\' && TextIO.peek() != \'+\'
&& TextIO.peek() != \'-\')
throw new IllegalArgumentException(
\"Expected *, +, or - after first set.\");
op = TextIO.getAnyChar(); // Read the operator.

B = readSet(); // Read the second set.

TextIO.skipBlanks();
if (TextIO.peek() != \'\ \')
throw new IllegalArgumentException(\"Extra unexpected input.\");

if (op == \'+\')
A.addAll(B);
else if (op == \'*\')
A.retainAll(B);
else
A.removeAll(B);
  
System.out.print(\"Value: \" + A);

}


private static TreeSet<Integer> readSet() {

TreeSet<Integer> set = new TreeSet<Integer>(); // The set that will be read.

TextIO.skipBlanks();
if (TextIO.peek() != \'[\')
throw new IllegalArgumentException(\"Expected \'[\' at start of set.\");
TextIO.getAnyChar(); // Read the \'[\'.

TextIO.skipBlanks();
if (TextIO.peek() == \']\') {
TextIO.getAnyChar(); // Read the \']\'.
return set;
}

while (true) {
  
TextIO.skipBlanks();
if (! Character.isDigit(TextIO.peek()))
throw new IllegalArgumentException(\"Expected an integer.\");
int n = TextIO.getInt(); // Read the integer.
set.add( new Integer(n) );
TextIO.skipBlanks();
if (TextIO.peek() == \']\')
break; // \']\' marks the end of the set.
else if (TextIO.peek() == \',\')
TextIO.getAnyChar();
else
throw new IllegalArgumentException(\"Expected \',\' or \']\'.\");
}

TextIO.getAnyChar();

return set;

}

}

This is just an intro class i just need help with a basic program, no classes or pointers. Assignment: Create a program which is capable of assembling and displ
This is just an intro class i just need help with a basic program, no classes or pointers. Assignment: Create a program which is capable of assembling and displ
This is just an intro class i just need help with a basic program, no classes or pointers. Assignment: Create a program which is capable of assembling and displ

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site