Hello Henry! This is such a great question and I am happy to help you with it. In order to answer this most accurately, there are a few pieces of information missing that we need to know before an effective answer can be provided. However, we can definitely start with the basics of how this Class will look to achieve the general idea. Let's get started!
First, we need to create a Class file called IntegerSet...
public class IntegerSet{
}
Second, we are asked to create a "no-argument" constructor that performs the task of initializing a boolean type array with all indices set to false.
Constructions are just methods with the same name as the Class.
public class IntegerSet{
public IntegerSet( ){
}
}
Next, all we have to do is create and initialize the boolean array. To do that, let's create the array under the Class and then initialize it in the constructor. By doing this, we can easily access the array from the Main or Driver class. Let's call the array set and initialize it with 101 indices. The reason we use 101 instead of 100 is because 0 is included in the possible set of integers.
public class IntegerSet{
Boolean[] set;
public IntegerSet( ){
set = new Boolean[101];
}
}
Finally, we want to make sure the entire array is an "empty set". When arrays are initialized each index is set to null so we need to create either a loop to go through the array and set each index to "false" or use the Arrays class.
Using a loop:
public class IntegerSet{
Boolean[] set;
public IntegerSet( ){
set = new Boolean[101];
for(int i = 0; i < set.length; I++){
set[I] = false;
}
}
}
Using Arrays class:
public class IntegerSet{
Boolean[] set;
public IntegerSet( ){
set = new Boolean[101];
Arrays.fill(set, false);
}
}
And there we have it! Now this may be all you need for this question, and if so way to go!! However, there are a few things that can make this program more effective and utilize a few more programming skills.
- There are multiple ways to receive the set of numbers when the program runs. Are we receiving each number individually or all at once?
- Do we need to verify the data type of the information provided so the program doesn't crash?
If you include these things in the program it will run more efficiently and make it less prone to crashing.
I hope this helps! :)