Intro to java project
template with instructions below
* IntegerSet.java
*/
/**
*
* @author StudentName
*/
public class IntegerSet {
/**
* Creates a new instance of IntegerSet
*/
// TODO: implement the constructor
/**
* Return a new IntegerSet containing the union of the two
IntegerSet objects
* passed as arguments
*/
// TODO: implement the union method
/**
* Return a new IntegerSet containing the intersection of the two
IntegerSet objects
* passed as arguments
*/
// TODO: implement the intersection method
/**
* Inserts an element into the IntegerSet by setting the
corresponding
* value within the set array to true. Returns false if the value
was out
* of range and true otherwise.
*/
// TODO: implement the insertElement method
/**
* Deletes an element from the IntegerSet by setting the
corresponding
* value within the set array to false. Returns false if the value
was out
* of range and true otherwise.
*/
// TODO: implement the deleteElement method
/**
* @Override the toString method in the Object class
* Displays the integers contained by the IntegerSet separated by
spaces.
* An empty set should be displayed as:
* { --- }
* An integer set containing 5 and 10 should be displayed as:
* { 5 10 }
*/
// TODO: implement the toString method
/**
* Returns true iff the current IntegerSet contains the same
integers as
* the IntegerSet supplied as an argument
*/
// TODO: implement the isEqualTo method
}
IntegerSet.java
public class IntegerSet {
private static final int MAX_SIZE = 101;
private int[] set;
public IntegerSet()
{
this.set = new int[MAX_SIZE];
}
public IntegerSet(IntegerSet copy)
{
this.set = new int[MAX_SIZE];
for(int i = 0; i < set.length; i++)
this.set[i] = copy.set[i];
}
public IntegerSet union(IntegerSet other)
{
IntegerSet result = new IntegerSet(this);
for(int i = 0; i < set.length; i++)
{
if(other.isIntegerSet(i))
result.insert(i);
}
return result;
}
public IntegerSet intersection(IntegerSet other)
{
IntegerSet result = new IntegerSet(this);
for(int i = 0; i < set.length; i++)
{
if(!other.isIntegerSet(i))
result.delete(i);
}
return result;
}
public boolean insert(int num)
{
if(num >= 0 && num < set.length)
{
set[num] = 1;
return true;
}
return false;
}
public boolean delete(int num)
{
if(num >= 0 && num < set.length)
{
set[num] = 0;
return true;
}
return false;
}
public boolean isIntegerSet(int num)
{
return(set[num] == 1);
}
public boolean isEmpty()
{
for(int i = 0; i < set.length; i++)
{
if(isIntegerSet(i))
return false;
}
return true;
}
@Override
public String toString()
{
String out = "Set: [";
if(isEmpty())
out += "---";
for(int i = 0; i < set.length; i++)
{
if(isIntegerSet(i))
out += i + " ";
}
out = out.trim() + "]";
return out;
}
public boolean isEqualTo(IntegerSet other)
{
for(int i = 0; i < set.length; i++)
{
if (other.isIntegerSet(i) != isIntegerSet(i))
return false;
}
return true;
}
}
IntegerSetTest.java (Test class)
import java.util.Random;
public class IntegerSetTest {
public static void main(String[] args) {
IntegerSet set1 = new IntegerSet();
IntegerSet set2 = new IntegerSet();
// insert 10 random numbers between 10 and 99 to each of the 2
sets
Random rand = new Random();
for(int i = 0; i < 10; i++)
{
int pick = 10 + rand.nextInt(99 - 10);
while(pick < 10 || pick > 99)
pick = 10 + rand.nextInt(99 - 10);
set1.insert(pick);
}
for(int i = 0; i < 10; i++)
{
int pick = 10 + rand.nextInt(99 - 10);
while(pick < 10 || pick > 99)
pick = 10 + rand.nextInt(99 - 10);
set2.insert(pick);
}
System.out.println("SET 1 --> " + set1);
System.out.println("SET 2 --> " + set2);
IntegerSet union = set1.union(set2);
IntegerSet intersection = set1.intersection(set2);
System.out.println("SET 1 UNION SET 2 --> " + union);
System.out.println("SET 1 INTERSECTION SET 2 --> " +
intersection);
}
}
*************************************************************** SCREENSHOT ************************************************************
Intro to java project template with instructions below * IntegerSet.java */ /** * * @author StudentName...
can i please get help on this? i don't know how to do it and I'm so confused. This is in java. This is what I need to do. Thank you so much. In this lab assignment, you are to write a class IntegerSet that represents a set of integers (by definition, a set contains no duplicates). This ADT must be implemented as a singly linked list of integers (with no tail reference and no dummy head node) , but...
I am having trouble with my C++ program.... Directions: In this lab assignment, you are to write a class IntegerSet that represents a set of integers (by definition, a set contains no duplicates). This ADT must be implemented as a singly linked list of integers (with no tail reference and no dummy head node), but it need not be sorted. The IntegerSet class should have two data fields: the cardinality (size) of the set, and the head reference to the...
3. (15 points) Fill in the method template below to make a working method. Make sure your method conforms to the instructions given in the comments for the method. public static boolean allIn ( Set < Integer > set , List < Integer> list ) { // This method takes a set and a list as inputs and returns true if every // element in the list is also an element of the set. Otherwise // it returns false. If...
Please use java code. Implement a test class named BatArray1Test that tests all the functionality of the following given 3 methods, including the invalid arguments: 1) commonEnd Given two arrays of ints, a and b, return true if they have the same first element or they have the same last element. This method should return false if either array is empty or null. 2) midThree Given an array of integers, return a new array of length 3 containing the elements...
Please give an answer which works to print the answer given below. Please use the necessary header .h and .cpp files. Please give the right solution. "ITS MY HUMBLE REQUEST TO GIVE THE RIGHT SOLUTION" Question 2 – Creating and working with other Containers A Set is a data structure which contains information on whether a value belongs to that set or not. In this question, you have to implement an integer Set which is able to tell whether an...
This is a java file and I am very confused on how to do this project! please help!! Specifications Overview: You will write a program this week that is composed of three classes: the first class defines Ellipsoid objects, the second class defines EllipsoidList objects, and the third, Ellipsoid ListApp, reads in a file name entered by the user then reads the list name and Ellipsoid data from the file, creates Ellipsoid objects and stores them in an ArrayList of...
I am unsure how to add the following methods onto this code?? please help - rowValuesIncrease(int[][] t) A method that returns true if from left to right in any row, the integers are increasing, otherwise false. - columnValuesIncrease(int[][] t) A method that returns true if from top to bottom in any column, the integers are increasing, otherwise false. - isSetOf1toN(int[][] t) A method that returns true if the set of integers used is {1, 2, . . . , n}...
using CSCI300 java Given the following UML Class Diagram Club_Card # card_num : String # name : String # age: int # year: int + Club_Card (all parameters) + Setters & Getters + toString() : String + equals(x: Object): boolean [10 pts] Define the class Club_Card, which contains: 1. All arguments constructor which accepts all required arguments from the main and instantiate a Club_Card object. 2. Set & get method for each data attribute. 3. A toString() method which returns...
write the following code in java thank you and if you can, could you please write the code in replit and sent me a link to it replit is basically like a online compiler and you can write java code on it thank you The first part is to implement one of the questions from your examination. /* A Range objects represents an integer range, such as 1-10 or 50701-50799. The lower and upper bounds of a Range are given...
Using Java: 1. Recursive Multiplication Write a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times y. Remember, multiplication can be performed as repeated addition as follows: 5×6=6+6+6+6+6 2. Recursive findings Write a recursive boolean method named reFinding. The method should search an array for a specified value, and return true if the value is found in the array, or false if the value is not found in...