Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q1) (70 points) Write a computer program that defines the class Set (assume that the elements are integers). The class should contain methods to perform

image text in transcribed

Q1) (70 points) Write a computer program that defines the class Set (assume that the elements are integers). The class should contain methods to perform the operations listed below. Write a test program that tests your Set class. The test program will be a menu-like to test all the operations in class Set. Different constructors to initialize the set (one is to set the elements from a one dimension array) COMPLETE IN JAVA, SWIFT, OR C#

a) union: find the union of the set with a given set. OUTPUT/RETURN: a Set object.

b) intersection: find the intersection of the set with a given set. OUTPUT/RETURN: a Set object.

c) difference: find the difference of the set and the given set (Set given Set). OUTPUT/RETURN: a Set object.

d) Cartesian product: find the Cartesian product (Set X given set). OUTPUT: prints out the product.

e) Check whether the set is a subset of another set. OUTPUT/RETURN: True or False.

f) isEmpty method that returns true if the set is empty (no elements).

g) isElement method that takes an element and check if it is an element of the set.

h) isEqual method that check if the set is equal to a given set.

i) getCardinality method that returns the cardinality of the set.

j) addElement method that adds an element to the set. Make sure that you dont add an existing element. You will use isElement check before you try to add it. k) removeElement method to remove an element from the set.

l) Clear method to remove all elements of the set.

m) toArray that converts the object of the Set class to a one dimensional array.

n) print method to print the elements of the set. In your test program, declare two sets objects and use the constructor to initialize them by sending a one dimension array contains the elements of the set.

Q1) (70 points) Write a computer program that defines the class "Set (assume that the elements are integers). The class should contain methods to perform the operations listed below. Write a test program that tests your "Set class. The test program will be a menu-like to test all the operations in class "Set". Different constructors to initialize the set (one is to set the elements from a one dimension array) a) union: find the union of the set with a given set. OUTPUT/RETURN: a Set object. b) intersection: find the intersection of the set with a given set. OUTPUT/RETURN: a Set object. c) difference: find the difference of the set and the given set (Set - given Set). OUTPUT/RETURN: a Set object. d) Cartesian product: find the Cartesian product (Set X given set). OUTPUT: prints out the product. e) Check whether the set is a subset of another set. OUTPUT/RETURN: True or False. f) isEmpty method that returns true if the set is empty (no elements). g) isElement method that takes an element and check if it is an element of the set. h) isEqual method that check if the set is equal to a given set. i) getCardinality method that returns the cardinality of the set. j) addElement method that adds an element to the set. Make sure that you don't add an existing element. You will use isElement check before you try to add it. k) removeElement method to remove an element from the set. 1. Clear method to remove all elements of the set. m) toArray that converts the object of the Set class to a one dimensional array. n) print method to print the elements of the set. In your test program, declare two sets objects and use the constructor to initialize them by sending a one dimension array contains the elements of the set

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Science Project Ideas In Health Care Volume 1

Authors: Zemelak Goraga

1st Edition

B0CPX2RWPF, 979-8223791072

More Books

Students also viewed these Databases questions