1. Engineering
  2. Computer Science
  3. please solve this asap part 1a we already discussed intcoll1client...

Question: please solve this asap part 1a we already discussed intcoll1client...

Question details

Please solve this ASAP

Part 1a. We already discussed Intcoll1client and Intcoll1 in class. Add any code still needed for the methods. Also add documentation to each of the 9 methods of the class. These methods are the default and alternate constructors -
Intcoll1() and Intcoll1(int i),
and
void copy(Intcoll1 obj)
boolean belongs(int i)
void insert(int i)
void omit(int i)
int get_howmany()
void print()
boolean equals(Intcoll1 obj)

/*This file, Lab1.java, defines the class Lab1. Write the missing code for the enlarge method. It is to change c so it contains the same integers as when it is invoked but has double that size.
*/
import java.util.*;

public class Lab1
{
private int[] c;

public static void main(String[] args)
{
Lab1 A=new Lab1();
A.show();
A.enlarge();
A.fill();
A.show();
}

public Lab1()
{
System.out.println("Enter the array size");
Scanner keyboard=new Scanner(System.in);
int n=keyboard.nextInt();
c=new int[n];
System.out.println("Enter the "+n+" integers");
int i=0;
while (i<n)
{
System.out.println("Enter an integer");
c[i]=keyboard.nextInt();
i++;
}
}

public void enlarge()
{
  


}

public void fill()
{
Scanner keyboard=new Scanner(System.in);
int n=c.length;
int i=n/2;
System.out.println("Enter the last "+n/2+" integers");
while (i<n)
{
System.out.println("Enter an integer");
c[i]=keyboard.nextInt();
i++;
}
}

public void show()
{
System.out.println("The array entries are now:");
int i=0;
int n=c.length;
while (i<n)
{
System.out.println(c[i]);
i++;
}
}
}


Run Intcoll1client using the Intcoll1 class on a number of different inputs to test the class. Choose the inputs with some thought to try to cover special cases and more general inputs.


Part 1b. Here you must first create Intcoll2 which has the same methods as Intcoll1 but doesn't use a zero in array c to signify the end of the integers stored in c. Instead it has another private member how_many that contains the number of integers in the collection. These integers are also stored at the top of array c.
After adding how_many as a member you need to write the code for each method of Intcoll2. To do this, consider the code for each method of Intcoll1 and see how it needs to be changed to carry out its task correctly for Intcoll2. Be sure to write a more efficient equals method.
Of course the same documentation will be used for Intcoll2 as for Intcoll1.
Run Intcoll2client using the Intcoll2 class on a number of different inputs to test the class. Choose the inputs with some thought to try to cover special cases and more general inputs.


Part1c. This is just like Part 1b except it involves Intcoll3client and the Intcoll3 class. The Intcoll3 class uses private members c and how_many. The array c is now of type boolean and contains a true value in slot i if the integer i is in the collection and false otherwise. This version of the Intcoll class is simpler than the other versions in some ways but more complicated in others. Whenever an integer needs to be inserted into the collection and c is not large enough to accept it then you must increase the size of c to accomodate the new integer before adding it.

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution