diff --git a/Laboratorium_1_Java/.gitignore b/Laboratorium_1_Java/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/Laboratorium_1_Java/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/Laboratorium_1_Java/.idea/.gitignore b/Laboratorium_1_Java/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/Laboratorium_1_Java/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/Laboratorium_1_Java/.idea/compiler.xml b/Laboratorium_1_Java/.idea/compiler.xml new file mode 100644 index 0000000..a1757ae --- /dev/null +++ b/Laboratorium_1_Java/.idea/compiler.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Laboratorium_1_Java/.idea/misc.xml b/Laboratorium_1_Java/.idea/misc.xml new file mode 100644 index 0000000..47478b9 --- /dev/null +++ b/Laboratorium_1_Java/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Laboratorium_1_Java/.idea/modules.xml b/Laboratorium_1_Java/.idea/modules.xml new file mode 100644 index 0000000..ac34180 --- /dev/null +++ b/Laboratorium_1_Java/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Laboratorium_1_Java/.idea/uiDesigner.xml b/Laboratorium_1_Java/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/Laboratorium_1_Java/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Laboratorium_1_Java/Laboratorium_1_Java.iml b/Laboratorium_1_Java/Laboratorium_1_Java.iml new file mode 100644 index 0000000..4751e6d --- /dev/null +++ b/Laboratorium_1_Java/Laboratorium_1_Java.iml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Laboratorium_1_Java/src/Main.java b/Laboratorium_1_Java/src/Main.java new file mode 100644 index 0000000..b3e5d6d --- /dev/null +++ b/Laboratorium_1_Java/src/Main.java @@ -0,0 +1,59 @@ +import java.util.*; + +public class Main { + public static void main(String[] args) { + zadanie_1_1(); + + Student s1 = new Student("Marian", "Kiepski", 22, "Informatyka", 2.5); + Student s2 = new Student("Jan", "Kowalski", 19, "Mechanika i budowa maszyn",4.5); + Student s3 = new Student("Tomasz", "Lewandowski", 23, "Elektrotechnika",4.76); + + System.out.println(s1); + System.out.println(s2); + System.out.println(s3); + + } + + public static void zadanie_1_1() + { + List przedmioty = Arrays.asList( + "Zaawansowane programowanie w Javie", "Procesy wytwarzania oprogramowania", "Komponentowe podejście do wytwarzania aplikacji", + "Seminarium dyplomowe", "Projekt zespołowy", "Architektura i programowanie w .NET", "Integracja systemów", "programowanie aplikacji w chmurze obliczeniowej", + "Interakcja człowiek komputer" + ); + + System.out.println("Lista przedmiotów z tego i poprzedniego semestru:"); + for (int i = 0; i < przedmioty.size(); i++) + { + System.out.println(przedmioty.get(i)); + } + + boolean isExist = przedmioty.stream().anyMatch(element -> element.toLowerCase().contains("zaaw")); + System.out.println("Lista przedmiotów posiada elementy zawierające 'zaaw': " + isExist); + + Map oceny = new HashMap<>(); + Random random = new Random(); + for (String przedmiot : przedmioty) { + int ocena = random.nextInt(4) + 2; + oceny.put(przedmiot, ocena); + } + for (Map.Entry entry : oceny.entrySet()) { + System.out.printf("Przedmiot: %s, Ocena: %d%n", entry.getKey(), entry.getValue()); + } + /*Map ocenyZliczone = oceny.stream() + /.collect(Collectors.groupingBy(ocena -> ocena, Collectors.counting())); + + + ocenyZliczone.forEach((ocena, ilosc) -> { + System.out.println("Ocena: " + ocena + ", Ilość: " + ilosc); + });*/ + } + + + private static int przypiszOcene() { + return (int) (Math.random()*5); + } + + + +} \ No newline at end of file diff --git a/Laboratorium_1_Java/src/Student.java b/Laboratorium_1_Java/src/Student.java new file mode 100644 index 0000000..7b76342 --- /dev/null +++ b/Laboratorium_1_Java/src/Student.java @@ -0,0 +1,14 @@ +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class Student { + private String imie; + private String nazwisko; + private int wiek; + private String kierunek; + private double srednia; +} diff --git a/Laboratorium_1_Java/src/ZgadywanieLiczby.java b/Laboratorium_1_Java/src/ZgadywanieLiczby.java new file mode 100644 index 0000000..376e66f --- /dev/null +++ b/Laboratorium_1_Java/src/ZgadywanieLiczby.java @@ -0,0 +1,57 @@ +import java.util.Random; +import java.util.Scanner; + +public class ZgadywanieLiczby { + private int tajnaLiczba; + private int proby; + + public ZgadywanieLiczby() { + Random random = new Random(); + tajnaLiczba = random.nextInt(100) + 1; // Losuje liczbę od 1 do 100 + proby = 0; + } + + public int pobierzWejscieUzytkownika() { + Scanner scanner = new Scanner(System.in); + int liczba = 0; + boolean poprawnaLiczba = false; + + while (!poprawnaLiczba) { + System.out.print("Zgadnij liczbę (1-100): "); + if (scanner.hasNextInt()) { + liczba = scanner.nextInt(); + if (liczba >= 1 && liczba <= 100) { + poprawnaLiczba = true; + } else { + System.out.println("Proszę podać liczbę w zakresie od 1 do 100."); + } + } else { + System.out.println("Proszę podać poprawną liczbę."); + scanner.next(); + } + } + return liczba; + } + + public void graj() { + System.out.println("Witaj w grze w zgadywanie liczby!"); + while (true) { + int zgadywanaLiczba = pobierzWejscieUzytkownika(); + proby++; + + if (zgadywanaLiczba < tajnaLiczba) { + System.out.println("Za mało! Spróbuj jeszcze raz."); + } else if (zgadywanaLiczba > tajnaLiczba) { + System.out.println("Za dużo! Spróbuj jeszcze raz."); + } else { + System.out.printf("Gratulacje! Zgadłeś liczbę %d w %d próbach.%n", tajnaLiczba, proby); + break; + } + } + } + + public static void main(String[] args) { + ZgadywanieLiczby gra = new ZgadywanieLiczby(); + gra.graj(); + } +}