+2 votes
in Class 12 by kratos

A class Combine contains an array of integers which combines two arrays into a single array including the duplicate elements, if any, and sorts the combined array. Some of the members of the class are given below:

Class name: Combine

Data Members/instance variables:

com[]: integer array size:

size of the array

Member functions/methods:

Combine(nt nn): parameterized constructor to assign size = nn

void inputarray(): accepts the array elements.

void sort(): sorts the elements of the combined array in ascending order using the

selection sort technique.

void mix(Combine A, Combine B): combines the parameterized object arrays and stores the result in the current object array along with duplicate elements, if any. void display(): displays the array elements

Specify the class Combine giving details of the constructor (int), void inputarray(), void sort(), void mix (Combine, Combine) and void display (). Also, define the main() function to create an object and call the methods accordingly to enable the task.

1 Answer

+2 votes
by kratos
 
Best answer

Import java. io.*;

class Combine

{

int com [], size;

public Combine (int nn)

{

size = nn;

com = new int [size];

} void inputarray () throws IOException

{

Buffered Reader

br = new Buffered Reader [new Input Stream Reader ( System.in)];

int i;

for (i = 0; i < size; i++) { System.out.println ("Enter a no.");

com [i] = Integer.parseInt[br.readLine ()];

}

}

void sort ()

{

int i, j, t;

for (i = 0; z < size; i++)

{

for (j = i + 1; j < size; j++) {

if (com[i] > com [j]) {

t = com [i];

com [i] = com [j];

com [j] = t;

}

}

}

}

void mix (Combine A, Combine B)

{ int i, j;

for (i = 0, j = 0; i < A.size; i ++, j++)

{ com[j] = A.com[i];

{ for (i = 0; i < B.size; i++, j++)

{

com [j] = B.com [i];

}

}

void display () { int i;

for (i = 0; i < size; i ++)

{

System.out.println(com[i]);

}

}

public static void main ( String args [ ]) throws IOException

{

Combine c1 = new Combine(5);

Combine c2 = new Combine(3);

Combine c3 = new Combine(8);

c1.inputarray();

c2.inputarray();

c3.mix (c1, c2);

c3.sort();

c3.display();

}

}

...