This commit is contained in:
Gašper Dobrovoljc 2024-06-01 13:23:09 +02:00
parent 75eb6fa962
commit 13db841de3
No known key found for this signature in database
GPG Key ID: 0E7E037018CFA5A5
5 changed files with 340 additions and 0 deletions

56
src/DN11.java Normal file
View File

@ -0,0 +1,56 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class DN11 {
public static void main(String[] args) {
var frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("VELIKE ČRKE");
frame.setSize(600, 400);
frame.setLocationRelativeTo(null);
frame.setLayout(new GridBagLayout());
var textArea1 = new JTextArea();
var gbc = new GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = 0;
gbc.weightx = 1;
gbc.weighty = 1;
gbc.fill = GridBagConstraints.BOTH;
gbc.insets = new Insets(10, 10, 10, 10);
frame.add(new JScrollPane(textArea1), gbc);
var button = new JButton("--> pretvori");
gbc = new GridBagConstraints();
gbc.gridx = 2;
gbc.gridy = 0;
gbc.weightx = 0;
gbc.weighty = 0;
gbc.fill = GridBagConstraints.NONE;
frame.add(button, gbc);
var textArea2 = new JTextArea();
gbc = new GridBagConstraints();
gbc.gridx = 3;
gbc.gridy = 0;
gbc.weightx = 1;
gbc.weighty = 1;
gbc.fill = GridBagConstraints.BOTH;
gbc.insets = new Insets(10, 10, 10, 10);
frame.add(new JScrollPane(textArea2), gbc);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
textArea2.setText(textArea1.getText().toUpperCase());
}
});
frame.setVisible(true);
}
}

189
src/Kviz4.java Normal file
View File

@ -0,0 +1,189 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
public class Kviz4 {
public static void main(String[] args) {
System.out.println(Arrays.toString(getVrstica(20)));
}
static java.util.Map<Integer, int[]> cache = new java.util.HashMap<>();
public static int[] getVrstica(int n) {
if (n == 1) {
return new int[]{1};
}
if (cache.containsKey(n)) {
return cache.get(n);
}
int[] vrstica = new int[n];
vrstica[0] = n % 10;
for (int i = 1; i < n; i++) {
vrstica[i] = (vrstica[i - 1] + getVrstica(n - 1)[i - 1]) % 10;
}
cache.put(n, vrstica);
return vrstica;
}
public static void statistikaStavkov(String imeDatoteke) {
class IzjemaManjkajocegaLocila extends Exception {
public IzjemaManjkajocegaLocila(String message) {
super(message);
}
}
try (java.io.BufferedReader br = new java.io.BufferedReader(new java.io.FileReader(imeDatoteke))) {
java.util.Map<Integer, Integer> dolzinaStavkov = new java.util.HashMap<>();
String line;
int stevec = 1; // Za sledenje vrsticam
while ((line = br.readLine()) != null) {
String[] stavki = line.split("[.!?]");
for (String stavek : stavki) {
stavek = stavek.trim();
if (!stavek.isEmpty()) {
if (!stavek.endsWith(".") && !stavek.endsWith("!") && !stavek.endsWith("?")) {
throw new IzjemaManjkajocegaLocila("Stavek na vrstici " + stevec + " se ne konča z ustrezno ločilo.");
}
int dolzina = stavek.split("\\s+").length;
dolzinaStavkov.put(dolzina, dolzinaStavkov.getOrDefault(dolzina, 0) + 1);
}
stevec++;
}
}
// Izpis rezultatov
for (java.util.Map.Entry<Integer, Integer> entry : dolzinaStavkov.entrySet()) {
System.out.println("Stavki dolzine " + entry.getKey() + " se pojavijo: " + entry.getValue() + "x.");
}
} catch (java.io.IOException e) {
System.out.println("Napaka pri branju datoteke.");
} catch (IzjemaManjkajocegaLocila e) {
System.out.println(e.getMessage());
}
}
public static void poisciInIzpisiBarve(String imeDatoteke) {
try (java.io.BufferedReader br = new java.io.BufferedReader(new java.io.FileReader(imeDatoteke))) {
String line;
java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("(^|[^\\-])color: #([0-9a-fA-F]{6})");
while ((line = br.readLine()) != null) {
java.util.regex.Matcher matcher = pattern.matcher(line);
while (matcher.find()) {
String hexColor = matcher.group(2);
int r = Integer.parseInt(hexColor.substring(0, 2), 16);
int g = Integer.parseInt(hexColor.substring(2, 4), 16);
int b = Integer.parseInt(hexColor.substring(4, 6), 16);
// Convert RGB to HSL
float[] hsl = rgbToHsl(r, g, b);
System.out.printf("#%s -> rgb(%d, %d, %d) -> hsl(%d, %d, %d)%n",
hexColor, r, g, b, Math.round(hsl[0]), Math.round(hsl[1]), Math.round(hsl[2]));
}
}
} catch (java.io.IOException e) {
e.printStackTrace();
}
}
private static float[] rgbToHsl(int r, int g, int b) {
float rNorm = r / 255.0f;
float gNorm = g / 255.0f;
float bNorm = b / 255.0f;
float max = Math.max(rNorm, Math.max(gNorm, bNorm));
float min = Math.min(rNorm, Math.min(gNorm, bNorm));
float delta = max - min;
float h = 0;
if (delta != 0) {
if (max == rNorm) {
h = ((gNorm - bNorm) / delta) % 6;
} else if (max == gNorm) {
h = ((bNorm - rNorm) / delta) + 2;
} else {
h = ((rNorm - gNorm) / delta) + 4;
}
h *= 60;
if (h < 0) {
h += 360;
}
}
float l = (max + min) / 2;
float s = 0;
if (delta != 0) {
s = delta / (1 - Math.abs(2 * l - 1));
}
return new float[]{h, s * 100, l * 100};
}
public static void izpisi(String imeDatoteke) {
try (java.io.FileInputStream fis = new java.io.FileInputStream(imeDatoteke);
java.nio.channels.FileChannel channel = fis.getChannel()) {
java.nio.ByteBuffer buffer = java.nio.ByteBuffer.allocate(3);
while (channel.read(buffer) != -1) {
buffer.flip();
int number = buffer.getInt();
System.out.println(formatTelefonskeStevilke(number));
buffer.clear();
}
} catch (java.io.IOException e) {
e.printStackTrace();
}
}
public static void preveri(String stevilka, String imeDatoteke) {
int iskanaStevilka = parseTelefonskaStevilka(stevilka);
try (java.io.FileInputStream fis = new java.io.FileInputStream(imeDatoteke);
java.nio.channels.FileChannel channel = fis.getChannel()) {
java.nio.ByteBuffer buffer = java.nio.ByteBuffer.allocate(3);
while (channel.read(buffer) != -1) {
buffer.flip();
byte[] bytes = new byte[3];
buffer.get(bytes);
int number = ((bytes[1] << 28)) >>> 12 | (bytes[1]) | bytes[2];
System.out.println(number);
if (number == iskanaStevilka) {
System.out.println("Številka " + stevilka + " je v datoteki.");
return;
}
buffer.clear();
}
System.out.println("Številke " + stevilka + " ni v datoteki.");
} catch (java.io.IOException e) {
e.printStackTrace();
}
}
private static String formatTelefonskeStevilke(int number) {
int podrocnaKoda = number / 1000000;
int preostanek = number % 1000000;
int prvaTrojka = preostanek / 1000;
int drugaTrojka = preostanek % 1000;
return String.format("%d / %03d %03d", podrocnaKoda, prvaTrojka, drugaTrojka);
}
private static int parseTelefonskaStevilka(String stevilka) {
String[] parts = stevilka.split("/");
int podrocnaKoda = Integer.parseInt(parts[0].trim());
parts = parts[1].trim().split(" ");
int prvaTrojka = Integer.parseInt(parts[0].trim());
int drugaTrojka = Integer.parseInt(parts[1].trim());
return (podrocnaKoda * 1000000) + (prvaTrojka * 1000) + drugaTrojka;
}
}

1
viri/besedilo1.txt Normal file
View File

@ -0,0 +1 @@
V tekstovni datoteki imamo shranjeno besedilo, sestavljeno iz stavkov, ki so lahko poljubno dolgi (vsebujejo poljubno mnogo besed). Vaša naloga je, da napišete program, ki bo odprl tekstovno datoteko, podano kot parameter ukazne vrstice, prebral celotno vsebino in za podano datoteko izpisal vse najdene dolžine stavkov in število pojavitev stavkov te dolžine (kot ločila med besedami upoštevajte presledke, kot znak za konec stavka pa upoštevajte piko, klicaj oziroma vprašaj. V primeru, da se stavek ne konča s piko, klicajem oziroma vprašajem, pa sprožite izjemo IzjemaManjkajocegaLocila. Definirajte tudi ta razred in ustrezno obravnavajte to izjemo.

1
viri/skrito.dat Normal file
View File

@ -0,0 +1 @@
<źŮá)Q¦':ÜD˝o+vń8f<v<s!ÁĂtŐBbz‰

93
viri/style.css Normal file
View File

@ -0,0 +1,93 @@
html, body {
color: #242729;
font-family: "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", Tahoma, sans-serif;
font-size: 13px;
line-height: 1.30769231
}
body {
box-sizing: border-box;
min-height: 100%;
background: #fafafa
}
body *, body *: before, body *: after {
box-sizing: inherit
}
.s-btn {
position: relative;
padding: .8em;
border: 1px solid transparent;
border-radius: 0;
background-color: transparent;
outline: none;
font-family: inherit;
font-size: inherit;
font-weight: 400;
line-height: 1.15384615;
text-decoration: none;
cursor: pointer;
border-color: rgba(150, 18, 18, 0);
box-shadow: 0 0 0 0 rgba(0, 149, 255, 0);
color: #C31818
}
.s-btn: hover {
border-color: rgba(150, 18, 18, 0)
}
.s-btn: active {
border-color: rgba(104, 13, 13, 0)
}
.s-btn.is-selected {
border-color: rgba(59, 7, 7, 0)
}
.s-btn[disabled] {
border-color: rgba(113, 106, 106, 0.1)
}
.s-btn: hover {
box-shadow: 0 0 0 0 rgba(0, 149, 255, 0)
}
.s-btn: focus {
box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.5), 0 0 0 4px rgba(0, 149, 255, 0.1)
}
.s-btn[disabled] {
box-shadow: none
}
.s-btn, .s-btn: focus {
background-color: rgba(195, 24, 24, 0)
}
.s-btn: hover {
background-color: rgba(200, 19, 19, 0.05)
}
.s-btn: active {
background-color: rgba(211, 8, 8, 0.15)
}
.s-btn.is-selected {
background-color: rgba(217, 2, 2, 0.25)
}
.s-btn[disabled] {
background-color: rgba(110, 110, 110, 0.2)
}
.s-btn, .s-btn: hover, .s-btn: focus, .s-btn.is-selected, .s-btn[disabled] {
background-image: none
}
.s-btn.s-btn__dropdown: after {
border-color: currentColor transparent
}
.s-btn: hover, .s-btn: active {
color: #961212
}
.s-btn: focus, .s-btn.is-selected {
color: #680d0d
}
.s-btn[disabled] {
color: rgba(110, 110, 110, 0.8)
}
.s-btn: hover, .s-btn: focus {
text-decoration: none
}
.s-btn: focus {
outline: none
}
.s-btn[disabled] {
opacity: 1;
cursor: default;
pointer-events: none
}