Question
CSCI 145 -- Project 3 (CharSet Class) Due Thursday, 11/09/2017 Create a class called CharSet so each object of class CharSet can hold printable ASCII
CSCI 145 -- Project 3 (CharSet Class) Due Thursday, 11/09/2017 Create a class called CharSet so each object of class CharSet can hold printable ASCII characters in the range from space (32) through ~ (127) and most common set operations are available. Your character set must be represented internally as an int array of 128 ones and zeros (or a boolean array of 128 trues and falses), but we will ignore the first 32 elements of the array (non-printable characters). Array element a[ i ] is 1 if character i is in the set and array element a[ j ] is 0 if character j is not in the set. The default constructor initializes an empty set, i.e., a set whose array representation contains all zeros. It also has a constructor that takes a char value c as a parameter (a set with one element c) and another constructor that takes a string as a parameter as well. Here is how to represent a set with elements ! and $ (values from other positions are all 0s): index 0 31 32 33 34 35 127 value 0 0 0 1 0 1 0 This class must contain member methods for the common set operations as specified next. Provide a union member method that creates a third set which is the set-theoretic union of two existing sets (i.e., an element of the third sets array is set to 1 if that element is 1 in either or both of the existing sets, and an element of the third sets array is set to 0 if that element is 0 in each of the existing sets). Provide an intersection member method that creates a third set which is the set-theoretic intersection of two existing sets (i.e., an element of the third sets array is set to 0 if that element is 0 in either or both of the existing sets, and an element of the third sets array is set to 1 if that element is 1 in each of the existing sets). Provide an insert member method that inserts a new character c into a set (by setting a[c] to 1 if c is valid). Provide a remove member method that removes character c (by setting a[c] to 0 if c is valid). Provide an isElement member method that returns true if character c is in the set. Include a size member method that returns the number of elements in the set. Provide a standard toString member method that returns a set as a list of characters enclosed by {}. Return only those elements that are present in the set (i.e., their position in the array has a value of 1). Return {} for an empty set. Provide a clone member method that copies one set to another set. Provide subset and superset operations (set 1 is a subset of set 2 if all elements in set 1 are also in set 2 and set 2 would be a superset of s1 in this case). Provide equals operation that returns true if two sets have the same exact elements. In addition, provide a clear member method to remove all elements. For some operations, make sure to perform it only if it is legal and ignore illegal element (for example, inserting only a valid element and reject an invalid element as applicable). In summary, provide public member methods for each of the following and feel free to add private member methods if needed: Three overload contructors : CharSet(), CharSet(char c), CharSet(String s) Union of two CharSets (union): union of two sets and return a newly created set Intersection of two CharSets (intersection): intersection of two sets and return a newly created set Insert an element to an CharSet (insert): insert element if valid and return true; otherwise, return false Remove an element from an CharSet (remove): remove element if valid and return; otherwise, return false Check if element c is in the set (isElement): return true if valid element is in the set; otherwise return false Return the number of elements in the set (size): return 0 for an empty set, 1 for a set of 1 element and so on Return a string representation of an CharSet (toString): return {} for empty set, {!$} for a set with ! and $ Copy one CharSet to another CharSet (clone): create a copy of current set and return a newly created set Check if first CharSet has the same elements as second CharSet (equals): return true if two sets have the same exact elements; otherwise return false Check if first CharSet is a subset of second CharSet (subset): return true if all elements of first set are in second set; otherwise return false Check if first CharSet is a superset of second CharSet (superset): return true if all elements of second set are in first set; otherwise return false Clear all elements from the CharSet (clear): remove all elements Now write a simple driver program to test your CharSet class (for this project, CharSet class is the main product). Instantiate several CharSet objects and test that all your member methods work properly (use code below as a starting point and make sure you pass these test cases; add code to print and test other operations). Make sure to set up correct interface for your class according to the requirements (correct method names, return type, and parameters). Here are some sample operations and other operations should have similar interface (for example, union method and intersection method would have the same interface): CharSet s1, s2, s3, s4, s5; String values = abc; s1 = new CharSet(); // s1 is an empty set, {} s2 = new CharSet(a); // s2 is now {a} s1.insert(b); // s1 is now {b} s3 = new CharSet(values); // s3 is now {abc} s3 = s1.clone(); // s3 is now {b} s4 = s1.union(s2); // s4 is now {ab} and s1 is still {b} s1.insert(B); // s1 is now {Bb} s4.insert(8); // s4 is now {8ab} s4.remove(b); // s4 is now {8a} s5 = s4; // s5 references s4 System.out.println(s5: + s5); // s5: {8a} System.out.println(s5.size()); // output 2 System.out.println(s3.subset(s4)); // output false System.out.println(s2.subset(s4)); // output true s5.clear(); // s4 and s5 both reference same empty set, {} char c = (char)227; // character for PI s1.insert(c); // invalid element so ignore, s1 is still {b} s1.remove(c); // invalid element so ignore, s1 is still {b} System.out.println(s1: + s1); // s1: {Bb} System.out.println(s2: + s2); // s2: {a} System.out.println(s3: + s3); // s3: {b} System.out.println(s4: + s4); // s4: {} System.out.println(s5: + s5); // s5: {} // add more test cases below You can implement one of the options below and you will not get extra credit for both. Extra Credit 1: It can be very time consuming to test all operations of CharSet class for all different situations. You can earn up to 4 additional points if you can provide a comprehensive driver to automatically test all operations and clearly document all test cases. You can replace/modify the original driver with this new driver and clearly indicate that extra credit is attempted in your write up. Briefly describe your testing strategy and the confident level of correctness with your CharSet class in your write up as well. Extra Credit 2: You can earn up to 4 additional points if class CharSet implements Comparable interface (use implements Comparable). Override compareTo method (from Comparable interface) to determine if two sets have the same number of elements, less than (first set has fewer elements), and larger than (first set has more elements). Test this feature by calling Compare3.largest3(s1, s2, s3) and you need to use class Compare3 from lab 7. Compare two CharSets (compareTo): implement compareTo method of Comparable interface and return -1, 0, or 1 as applicable Please provide documentation and applying good coding style because it is part of the grade. Use the provided template from my website, template.java, as the starting point. You must come up with a sufficient number of test cases since the test cases are also part of the grade. Pseudocode is recommended, but it is not required. Please submit the following items in a folder if flash drive or CD is included (can also submit source code ahead of time via Canvas and a folder is not needed): 1. Title page with name, class, project number, and relevant information about your program (JDK/IDE and system used, file names). 2. Notes about your program (status of your program and lessons learned at the minimum). 3. Testing strategy and confident level if applicable (extra credit part). 4. Printouts of any input/output. 5. A printout of the source code. 6. A copy of your source code on a flash drive or Canvas (.java files). Your program will be graded as follow: Correctness/Efficiency: 30 points Test Cases: 5 points; Documentation/Coding Style: 5 points
CSCI 145 -- Project 3 (CharSet Class) Due Thursday, 11/o9/2017 Create a class called CharSet so each object of class CharSet can hold printable ASCII characters in the range from space (32) through (127) and most common set operations are available. Your character set must be represented internally as an int array of 128 ones and zeros (or a boolean array of 128 trues and falses), but we will ignore the first 32 elements of the array (non-printable character) Array element al i] is 1 if character i is in the set and array element alj] is 0 if character j is not in the set. The default constructor initializes an empty set, i.e., a set whose array representation contains all zeros. It also has a constructor that takes a char value c as a parameter (a set with one element c) and another constructor that takes a string as a parameter as well. Here is how to represent a set with elements !" and "S' (values from other positions are all 0's): index 32 34 35 127 This class must contain member methods for the common set operations as specified next. Provide a union member method that creates a third set which is the set-theoretic union of two existing sets (ie., an element of the third set's array is set to 1 if that element is 1 in either or both of the existing sets, and an element of the third set's array is set to 0 if that element is 0 in each of the existing sets). Provide an intersection member method that creates a third set which is the set-theoretic intersection of two existing sets (i.e., an element of the third set's array is set to 0 if that element is 0 in either or both of the existing sets, and an element of the third set's array is set to 1 if that element is 1 in each of the existing sets). Provide an insert member method that inserts a new character c into a set (by setting ac to 1 if e is valid). Provide a remove member method that removes character c (by setting a[cl to 0 ifc is valid). Provide an isElement member method that returms true if character c is in the set. Include a size member method that returns the number of elements in the set. Provide a standard toString member method that returns a set as a list of characters enclosed by . Return only those elements that are present in the set (i.c, their position in the array has a value of 1). Return for an empty set Provide a clone member method that copies one set to superset operations (set 1 is a subset of set 2 if all elements in set 1 are also in set 2 and set 2 would be a superset of sl in this case). Provide equals operation that returns true if two sets have the same exact elements. In addition, provide a clear member method to remove all elements. For some operations, make sure to perform it only if it is legal and ignore illegal element (for example, inserting only a valid element and reject an invalid element as applicable) another set. Provide subset and In summary, provide public member methods for each of the following and feel free to add private member methods if needed: Three overload contructors: CharSetO. CharSet(char c) CharSet(String s) Union of two CharSets (union): union of two sets and return a newly created setStep 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