Programovanie (2) v Jave
1-INF-166, letný semester 2023/24

Prednášky · Pravidlá · Softvér · Testovač
· Vyučujúcich predmetu možno kontaktovať mailom na adresách uvedených na hlavnej stránke. Hromadná mailová adresa zo zimného semestra v letnom semestri nefunguje.
· JavaFX: cesta k adresáru lib je v počítačových učebniach /usr/share/openjfx/lib.


Riešenia testu č. 4

Z Programovanie
Skočit na navigaci Skočit na vyhledávání

Úloha č. 1

btnLarger.setOnAction(event -> {
    circle.setRadius(circle.getRadius() + 10);
    if (circle.getRadius() == 100) {
        btnLarger.setDisable(true);
    }
    if (circle.getRadius() == 20) {
        btnSmaller.setDisable(false);
    }
});

btnSmaller.setOnAction(event -> {
    circle.setRadius(circle.getRadius() - 10);
    if (circle.getRadius() == 10) {
        btnSmaller.setDisable(true);
    }
    if (circle.getRadius() == 90) {
        btnLarger.setDisable(false);
    }
});

Random random = new Random();
circle.setOnMouseClicked(event -> {
    circle.setFill(Color.color(random.nextDouble(), random.nextDouble(), random.nextDouble()));
});

Úloha č. 2

package graphs;

public class CompleteBipartiteGraphs {

    public static boolean isCompleteBipartiteGraph(UndirectedGraph g) {
        int n = g.getVertexCount();
        if (n == 0) {
            return true;
        }
        for (int u = 0; u <= n - 1; u++) {
            for (int v = 0; v <= n - 1; v++) {
                if (g.hasEdge(u, v) != (g.hasEdge(u, 0) != g.hasEdge(v, 0))) {
                    return false;
                }
            }
        }
        return true;
    }

}

Úloha č. 3

package graphs;

import java.util.*;

public class FixedSizeCliques {
    private UndirectedGraph g;
    private int size;

    private int cliqueCount;
    private List<Set<Integer>> cliques;

    private LinkedList<Integer> currentVertices;

    public FixedSizeCliques(UndirectedGraph g, int size) {
        this.g = g;
        this.size = size;

        cliques = new LinkedList<>();
        currentVertices = new LinkedList<>();
        search(0);
    }

    private boolean isClique(Collection<Integer> vertices) {
        for (int u : vertices) {
            for (int v : vertices) {
                if (u != v && !g.hasEdge(u, v)) {
                    return false;
                }
            }
        }
        return true;
    }

    private void search(int k) {
        if (k == size && isClique(currentVertices)) {
            cliques.add(Collections.unmodifiableSet(new HashSet<>(currentVertices)));
            cliqueCount++;
        } else {
            int last = -1;
            if (k > 0) {
                last = currentVertices.get(k - 1);
            }
            for (int v = last + 1; v <= g.getVertexCount() - 1; v++) {
                currentVertices.add(v);
                search(k + 1);
                currentVertices.removeLast();
            }
        }
    }

    public int cliqueCount() {
        return cliqueCount;
    }

    public List<Set<Integer>> getCliques() {
        return Collections.unmodifiableList(cliques);
    }
}