0% found this document useful (0 votes)
74 views8 pages

Java Set Operations: Union & Intersection

The document defines a Java class called "lab7" that determines the union and intersection of sets of integers. It creates two tree sets ("s1" and "s2") to hold numbers from text areas, and additional sets for the union and intersection results. Methods are defined to add the numbers to the sets, perform the union by combining both sets, and intersect the sets by keeping only the common elements. The class displays the input and output sets using labels and text areas, and buttons to trigger the union and intersection methods.

Uploaded by

uohikjb jbjkbkj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views8 pages

Java Set Operations: Union & Intersection

The document defines a Java class called "lab7" that determines the union and intersection of sets of integers. It creates two tree sets ("s1" and "s2") to hold numbers from text areas, and additional sets for the union and intersection results. Methods are defined to add the numbers to the sets, perform the union by combining both sets, and intersect the sets by keeping only the common elements. The class displays the input and output sets using labels and text areas, and buttons to trigger the union and intersection methods.

Uploaded by

uohikjb jbjkbkj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

st. gr.

C-121

Bordeianu Mihail

Varianta 3

Defini o clas Set bazat colecii pentru un set de numere ntregi, Creai metodele de determinare
a uniunii i intersectiei de seturi .

import [Link];

public class lab7 extends [Link] {

//3 multimi

TreeSet s1 = new TreeSet();

TreeSet s2 = new TreeSet();

// TreeSet s3 = new TreeSet();

//uniunea

TreeSet sIntersectia = new TreeSet();

//intersectia

TreeSet sUniunea = new TreeSet();

public lab7() {

initComponents();

}
//esirea elementelor la ecran

public void AddToSet()

String str1 [] = [Link]().split("\n");

String str2 [] = [Link]().split("\n");

// String str3 [] = [Link]().split("\n");

for(int i=0; i<[Link]; i++)

[Link](str1[i]);

for(int i=0; i<[Link]; i++)

[Link](str2[i]);

/* for(int i=0; i<[Link]; i++)

[Link](str3[i]);*/

//Uniunea

public void Uniunea()

[Link](s1);

[Link](s2);

// [Link](s3);

//Intersectia

public void Intersectia()

[Link](s1);

[Link](s2);

// [Link](s3);

}
@SuppressWarnings("unchecked")

// <editor-fold defaultstate="collapsed" desc="Generated Code">

private void initComponents() {

jScrollPane1 = new [Link]();

jTextArea1 = new [Link]();

jScrollPane2 = new [Link]();

jTextArea2 = new [Link]();

jScrollPane4 = new [Link]();

jTextArea4 = new [Link]();

jButton1 = new [Link]();

jButton2 = new [Link]();

jLabel1 = new [Link]();

jLabel2 = new [Link]();

jLabel3 = new [Link]();

jLabel4 = new [Link]();

setDefaultCloseOperation([Link].EXIT_ON_CLOSE);

setTitle("lab_7 Bordeian Mihail gr. C-121");

setBounds(new [Link](200, 200, 0, 0));

[Link](20);

[Link](true);

[Link](5);

[Link]("3\n2\n1\n");

[Link](jTextArea1);

[Link](20);

[Link](true);
[Link](5);

[Link]("4\n2\n5");

[Link](jTextArea2);

[Link](20);

[Link](true);

[Link](5);

[Link](jTextArea4);

[Link](new [Link](0, 0, 153));

[Link]("Uniunea");

[Link](new [Link]() {

public void actionPerformed([Link] evt) {

jButton1ActionPerformed(evt);

});

[Link](new [Link](0, 0, 153));

[Link]("Intersectia");

[Link](new [Link]() {

public void actionPerformed([Link] evt) {

jButton2ActionPerformed(evt);

});

[Link](new [Link]("Tahoma", 1, 14)); // NOI18N

[Link](new [Link](0, 0, 153));

[Link](" Determinarea Uniunii si Intersectiei");


[Link]("Rezultatul:");

[Link]("1-a Multime");

[Link]("2-a Multime");

[Link] layout = new [Link](getContentPane());

getContentPane().setLayout(layout);

[Link](

[Link]([Link])

.addGroup([Link]()

.addGap(43, 43, 43)

.addGroup([Link]([Link], false)

.addComponent(jLabel1, [Link].DEFAULT_SIZE,
[Link].DEFAULT_SIZE, Short.MAX_VALUE)

.addGroup([Link]()

.addGroup([Link]([Link])

.addComponent(jScrollPane1, [Link].PREFERRED_SIZE,
[Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE)

.addComponent(jButton1)

.addComponent(jLabel3))

.addPreferredGap([Link])

.addGroup([Link]([Link])

.addComponent(jButton2)

.addComponent(jScrollPane2, [Link].PREFERRED_SIZE,
[Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE)

.addComponent(jLabel4))

.addGap(18, 18, 18)

.addGroup([Link]([Link])
.addComponent(jScrollPane4, [Link].PREFERRED_SIZE,
[Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE)

.addComponent(jLabel2))))

.addContainerGap([Link].DEFAULT_SIZE, Short.MAX_VALUE))

);

[Link](

[Link]([Link])

.addGroup([Link]()

.addGap(22, 22, 22)

.addComponent(jLabel1)

.addGap(18, 18, 18)

.addGroup([Link]([Link])

.addGroup([Link]()

.addComponent(jLabel3)

.addGap(14, 14, 14))

.addGroup([Link]()

.addGroup([Link]([Link])

.addComponent(jLabel4)

.addComponent(jLabel2))

.addPreferredGap([Link])))

.addGroup([Link]([Link])

.addComponent(jScrollPane2, [Link].PREFERRED_SIZE,
[Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE)

.addComponent(jScrollPane1, [Link].PREFERRED_SIZE,
[Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE)

.addComponent(jScrollPane4, [Link].PREFERRED_SIZE,
[Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE))

.addGap(24, 24, 24)

.addGroup([Link]([Link])

.addComponent(jButton1)
.addComponent(jButton2))

.addContainerGap(111, Short.MAX_VALUE))

);

pack();

}// </editor-fold>

private void jButton1ActionPerformed([Link] evt) {

AddToSet();

Uniunea();

[Link]([Link]());

private void jButton2ActionPerformed([Link] evt) {

AddToSet();

Intersectia();

[Link]([Link]());

public static void main(String args[]) {

[Link](new Runnable() {

public void run() {

new lab7().setVisible(true);

});

}
// Variables declaration - do not modify

private [Link] jButton1;

private [Link] jButton2;

private [Link] jLabel1;

private [Link] jLabel2;

private [Link] jLabel3;

private [Link] jLabel4;

private [Link] jScrollPane1;

private [Link] jScrollPane2;

private [Link] jScrollPane4;

private [Link] jTextArea1;

private [Link] jTextArea2;

private [Link] jTextArea4;

// End of variables declaration

You might also like