Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java create a class called charset so each object of class charset can hold printable ASCII characters in the range from space 32 through ~

Java

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 0's):

index 0 ... 31 32 33 34 35 ... 127
value 0 ... 0 0 1 0 1 ... 0

1. Three overload constructors: CharSet(), CharSet(char c), CharSet(String s)

2. Union of two CharSets(union): union of two sets and return a newly created set

3. Intersection of two CharSets(intersection): intersection of two sets and return a newly created set

4. Insert an element to a CharSet(inset): inset element if valid and return true;

5. Remove an element from a CharSet(remove): remove element if valid and return; otherwise, return false.

6. Check if element c is in the set (isElement): return true if valid element is in the set;

7. Return the number of elements in the set (size): return 0 for an empty set, 1 for a set of element and so on.

8. Return String representation of an CharSet(toSting): return {} for empty set, {!$} for a set with '!' and '$'

9. Copy one CharSet to another CharSet(clone): create a copy of current set and return a newly created set

public class Charset {

private int asciiSet[] = new int [128]; public Charset() { for(int i=0;i=32 && ascii<=127) asciiSet[ascii]=1; } public Charset(String str) { for(int i=0;i=32 && ascii<=127) asciiSet[ascii]=1; } } public void printSet() { System.out.println("*******************"); System.out.println("Index:\tValue"); for(int i=0;i

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

Database And Expert Systems Applications 24th International Conference Dexa 2013 Prague Czech Republic August 2013 Proceedings Part 1 Lncs 8055

Authors: Hendrik Decker ,Lenka Lhotska ,Sebastian Link ,Josef Basl ,A Min Tjoa

2013 Edition

3642402844, 978-3642402845

More Books

Students also viewed these Databases questions