diff --git a/src/H071221104/Pertemuan_1/No1.java b/src/H071221104/Pertemuan_1/No1.java new file mode 100644 index 0000000..c2e7d64 --- /dev/null +++ b/src/H071221104/Pertemuan_1/No1.java @@ -0,0 +1,22 @@ +package H071221104.Pertemuan_1; + +import java.util.Scanner; + +public class No1 { + public static void main(String[] args) { + int nim; + Scanner key = new Scanner(System.in); + System.out.print("Masukkan angka terakhir NIM: "); + nim = key.nextInt(); + if (nim % 7 == 0){System.out.print("Soal no:7");} + else {System.out.println("soal nomor :"+ nim % 7);} + // else if (nim % 7 == 1){System.out.print("Soal no:1");} + // else if(nim % 7 == 2){System.out.print("Soal no:2");} + // else if(nim % 7 == 3){System.out.print("Soal no:3");} + // else if(nim % 7 == 4){System.out.print("Soal no:4");} + // else if(nim % 7 == 5){System.out.print("Soal no:5");} + // else if(nim % 7 == 6){System.out.print("Soal no:6");} + + key.close(); + } +} diff --git a/src/H071221104/Pertemuan_1/No2.java b/src/H071221104/Pertemuan_1/No2.java new file mode 100644 index 0000000..93de987 --- /dev/null +++ b/src/H071221104/Pertemuan_1/No2.java @@ -0,0 +1,43 @@ +package H071221104.Pertemuan_1; + +import java.util.Scanner; + +public class No2 { + + public static void main(String[] args) { + Scanner inp = new Scanner(System.in); + try { + System.out.print("Masukkan jumlah bilangan: "); + int n = inp.nextInt(); + + int desimal = 0; + int bulat = 0; + + for (int i = 0; i < n; i++) { + // for (int i = 0; i < n; i++) adalah sebuah perulangan dalam bahasa pemrograman + // java. + // Arti dari perulangan ini adalah "untuk nilai awal i sama dengan 0; lakukan + // perintah-perintah di dalam blok perulangan ini selama i kurang dari nilai n; + // setiap kali perintah-perintah di dalam blok perulangan selesai dieksekusi, + // tambahkan 1 ke nilai i". + // Dalam konteks ini, n adalah sebuah variabel atau konstanta yang menyatakan + // jumlah iterasi atau pengulangan yang ingin dilakukan. + + // System.out.print("Masukkan bilangan ke-" + (i + 1) + ": "); + double num = inp.nextDouble(); + + if (num % 1 == 0) { + bulat++; + } else { + desimal++; + } + } + + System.out.println(bulat + " Bilangan Bulat"); + System.out.println(desimal + " Bilangan Desimal"); + inp.close(); + } catch (Exception e) { + System.out.println("Hanya bisa menerima angka"); + } + } +} diff --git a/src/H071221104/Pertemuan_1/No3.java b/src/H071221104/Pertemuan_1/No3.java new file mode 100644 index 0000000..f8f4207 --- /dev/null +++ b/src/H071221104/Pertemuan_1/No3.java @@ -0,0 +1,23 @@ +package H071221104.Pertemuan_1; + +import java.util.Scanner; + +public class No3 { + public static void main(String[] args) { + Scanner inp = new Scanner(System.in); + try { + System.out.print("Name : "); + String a = inp.nextLine(); + System.out.print("Umur : "); + int b = inp.nextInt(); + inp.nextLine(); + System.out.print("Hobby : "); + String c = inp.nextLine(); + System.out.println("Nama Saya " + a + ", " + b + " Tahun, " + "Hobby " + c); + } catch (Exception e) { + System.out.println("inputan umur harus berupa angka"); + } + inp.close(); + } + +} diff --git a/src/H071221104/Pertemuan_1/No4.java b/src/H071221104/Pertemuan_1/No4.java new file mode 100644 index 0000000..f4c7523 --- /dev/null +++ b/src/H071221104/Pertemuan_1/No4.java @@ -0,0 +1,22 @@ +package H071221104.Pertemuan_1; + +import java.util.Scanner; + +public class No4 { + public static void main(String[] args) { + Scanner inp = new Scanner(System.in); + System.out.print("Masukkan kalimat: "); + String kalimat = inp.nextLine(); + String[] kata = kalimat.toLowerCase().split(" "); + String kalimatBaru = ""; + for (int i = 0; i < kata.length; i++) { + kalimatBaru += kata[i].substring(0, 1).toUpperCase() + kata[i].substring(1) + " "; + } + System.out.println(kalimatBaru.trim()); + inp.close(); + } +} + + + + diff --git a/src/H071221104/Pertemuan_1/No5.java b/src/H071221104/Pertemuan_1/No5.java new file mode 100644 index 0000000..207ed2b --- /dev/null +++ b/src/H071221104/Pertemuan_1/No5.java @@ -0,0 +1,54 @@ +package H071221104.Pertemuan_1; + +import java.util.Scanner; + +public class No5 { + public static void main(String[] args) { + Scanner inp = new Scanner(System.in); + String tanggal = inp.nextLine(); + String [] arraytanggal = tanggal.split("-"); + // System.out.println(arraytanggal); + int [] arraytanggal2 = new int [3]; + for (int i = 0; i < arraytanggal.length; i++) { + arraytanggal2[i] = Integer.parseInt(arraytanggal[i]); + inp.close(); + } + int tahun = arraytanggal2[2]; + String tahun2 = ""; + if (tahun >= 0 && tahun < 30){ + tahun2 = "20" + arraytanggal[2]; + } else { + tahun2 = "19" + arraytanggal[2]; + } + System.out.println(arraytanggal2[0] + " " + konversiBulan(arraytanggal2[1])+ " " + tahun2); + } + public static String konversiBulan(int angka){ + if (angka == 1) { + return "Januari"; + } else if (angka == 2) { + return "Februari"; + } else if (angka == 3) { + return "Maret"; + } else if (angka == 4) { + return "April"; + } else if (angka == 5) { + return "Mei"; + } else if (angka == 6) { + return "Juni"; + } else if (angka == 7) { + return "Juli"; + } else if (angka == 8) { + return "Agustus"; + } else if (angka == 9) { + return "September"; + } else if (angka == 10) { + return "Oktober"; + } else if (angka == 11) { + return "November"; + } else if (angka == 12) { + return "Desember"; + } else { + return ""; + } + } +} diff --git a/src/H071221104/Pertemuan_1/No6.java b/src/H071221104/Pertemuan_1/No6.java new file mode 100644 index 0000000..135e19a --- /dev/null +++ b/src/H071221104/Pertemuan_1/No6.java @@ -0,0 +1,20 @@ +package H071221104.Pertemuan_1; + +import java.util.Scanner; + +public class No6 { + public static void main(String[] args) { + Scanner inp = new Scanner(System.in); + try { + System.out.print("Masukkan jari-jari lingkaran: "); + double jariJari = inp.nextDouble(); + + double luasLingkaran = Math.PI * Math.pow(jariJari, 2); + System.out.printf("Luas lingkaran adalah: %.2f", luasLingkaran); + } catch (Exception e) { + System.out.println("Hanya menerima angka"); + } + inp.close(); + } + +} diff --git a/src/H071221104/Pertemuan_1/No7.java b/src/H071221104/Pertemuan_1/No7.java new file mode 100644 index 0000000..004d0f7 --- /dev/null +++ b/src/H071221104/Pertemuan_1/No7.java @@ -0,0 +1,27 @@ +package H071221104.Pertemuan_1; + +import java.util.Scanner; +public class No7 { + static String[] buah = {"Anggur", "Apel", "Belimbing", "Durian", "Rambutan", "Pisang", "Jeruk", "Semangka", "Nanas", +"Salak", "manggis"}; +public static void main(String[] args) { + Scanner inp = new Scanner(System.in); + System.out.print("Key: "); + String inputBuah = inp.next(); + int indexBuah = findIndex(inputBuah); + System.out.println(indexBuah); + inp.close(); +} +static int findIndex(String inputBuah){ + inputBuah = inputBuah.toLowerCase(); + int result = -1; + for (int i = 0; i < buah.length; i++) { + String buah1 = buah[i]; + buah1 = buah1.toLowerCase(); + if (buah1.equals(inputBuah)){ + result = i; + } + }; + return result; +} +} \ No newline at end of file diff --git a/src/H071221104/Pertemuan_1/No8.java b/src/H071221104/Pertemuan_1/No8.java new file mode 100644 index 0000000..178ac54 --- /dev/null +++ b/src/H071221104/Pertemuan_1/No8.java @@ -0,0 +1,28 @@ +package H071221104.Pertemuan_1; + +import java.util.Scanner; + +public class No8 { + public static void main(String[] args) { + int[][] angka = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9, }, { 10, 11 }, { 12 }, { 13, 14, 15, 16 } }; + Scanner inp = new Scanner(System.in); + + try { + System.out.print("Input angka yang ingin di cari : "); + int inputAngka = inp.nextInt(); + + for (int i = 0; i < angka.length; i++) { + for (int j = 0; j < angka[i].length; j++) { + int angka1 = angka[i][j]; + if (angka1 == inputAngka) { + System.out.println("Found" + inputAngka + " at [" + i + "][" + j + "]"); + break; + } + } + } + } catch (Exception e) { + System.out.println("Input harus berupa data integer (angka)"); + } + inp.close(); + } +} diff --git a/src/H071221104/Praktikum _2/Cuboid.java b/src/H071221104/Praktikum _2/Cuboid.java new file mode 100644 index 0000000..ed32dee --- /dev/null +++ b/src/H071221104/Praktikum _2/Cuboid.java @@ -0,0 +1,21 @@ +package Semester2.Praktikum.Pertemuan2; + +public class Cuboid { + double height; + double width ; + double length ; + + double getVolume(){ + return height * width * length; + } +} + +class Volume{ + public static void main(String[] args) { + Cuboid a = new Cuboid(); + a.height = 3; + a.width = 30; + a.length = 50; + System.out.printf("Volume = %.2f", a.getVolume()); + } +} \ No newline at end of file diff --git a/src/H071221104/Praktikum _2/Main.java b/src/H071221104/Praktikum _2/Main.java new file mode 100644 index 0000000..9942f2a --- /dev/null +++ b/src/H071221104/Praktikum _2/Main.java @@ -0,0 +1,41 @@ +package Semester2.Praktikum.Pertemuan2; +class Alamat{ + String jalan; + String kota; + String getAlamatLengkap(){ + return jalan + "," + kota; + } +} + +class Mahasiswa{ + Alamat alamat; + String nama; + String nim; + + String getNama(){ + return nama; + } + String getNim(){ + return nim; + } + Alamat getAlamat(){ + return alamat; + } +} + +public class Main { + public static void main(String[] args) { + Alamat alamat = new Alamat(); + alamat.jalan = "Pallangga"; + alamat.kota = "Makassar"; + + Mahasiswa mahasiswa = new Mahasiswa(); + mahasiswa.alamat = alamat; + mahasiswa.nama = "Rafli"; + mahasiswa.nim = "H071221104"; + + System.out.println("Nama: " + mahasiswa.getNama()); + System.out.println("NIM: " + mahasiswa.getNim()); + System.out.println("Alamat: " + mahasiswa.getAlamat().getAlamatLengkap()); + } +} diff --git a/src/H071221104/Praktikum _2/Person.java b/src/H071221104/Praktikum _2/Person.java new file mode 100644 index 0000000..985f1fb --- /dev/null +++ b/src/H071221104/Praktikum _2/Person.java @@ -0,0 +1,46 @@ +package Semester2.Praktikum.Pertemuan2; +import java.util.Scanner; +public class Person { + String name; + int age; + boolean isMale; + + public void setAge(int age) { + this.age = age; + } + public int getAge() { + return age; + } + public void setGender(boolean isMale) { + this.isMale = isMale; + } + public String getGender (){ + if (isMale == true){ + return "Male"; + } return "Female"; + } + public void setName(String name) { + this.name = name; + } + public String getName() { + return name; + } +} +class Orang { + public static void main(String[] args) { + Person person = new Person(); + Scanner input = new Scanner(System.in); + System.out.print("Nama: "); + person.name = input.nextLine(); + System.out.print("Are you Male? true or false: "); + person.isMale = input.nextBoolean(); + System.out.print("Umur: "); + person.age = input.nextInt(); + input.close(); + System.out.println("Nama: " + person.getName() ); + System.out.println("Gender: " + person.getGender()); + System.out.println("Umur: " + person.getAge()); + } +} + + diff --git a/src/H071221104/Praktikum _2/no1.java b/src/H071221104/Praktikum _2/no1.java new file mode 100644 index 0000000..7fb281e --- /dev/null +++ b/src/H071221104/Praktikum _2/no1.java @@ -0,0 +1,36 @@ +package Semester2.Praktikum.Pertemuan2; + +public class no1 { + String nama; + int health; + int mana; + int att; + int armor; +} +class Hero { + //Method + static void detailHero() { + //Atribut + no1 bimasakti = new no1(); + bimasakti.nama = "Bimasakti"; + bimasakti.health = 300; + bimasakti.mana = 100; + bimasakti.att = 50; + bimasakti.armor = 200; + + System.out.println("Nama Hero: " + bimasakti.nama); + System.out.println("Health: " + bimasakti.health); + System.out.println("Mana: " + bimasakti.mana); + System.out.println("Attack: " + bimasakti.att); + System.out.println("Armor: " + bimasakti.armor); + } + static void slogan(){ + System.out.println("'Akulah lambang dari kebenaran' "); + } + //Maiin Method + public static void main(String[] args) { + detailHero(); + slogan(); + } +} + diff --git a/src/H071221104/Praktikum _2/produk.java b/src/H071221104/Praktikum _2/produk.java new file mode 100644 index 0000000..4681e65 --- /dev/null +++ b/src/H071221104/Praktikum _2/produk.java @@ -0,0 +1,38 @@ +package Semester2.Praktikum.Pertemuan2; +public class produk { + String nama; + int id; + int harga; + int stok; + public void cekBarang(){ + System.out.println("Nama produk: " + nama); + System.out.println("Id: " + id); + System.out.println("Harga produk: " + harga); + System.out.println("Stok: " + stok); + } + public void cekStok(){ + if(stok > 0){ + System.out.println("Stok tersedia"); + } else { System.out.println("Stok tidak tersedia"); + + } + } +} +class cek{ + public static void main(String[] args) { + produk a = new produk(); + produk b = new produk(); + a.id = 1234; + a.nama = "Yakult"; + a.stok = 0; + a.harga = 2500; + b.id = 1334; + b.nama = "Nabati"; + b.stok = 5; + b.harga = 5000; + a.cekBarang(); + a.cekStok(); + b.cekBarang(); + b.cekStok(); + } +} \ No newline at end of file diff --git a/src/H071221104/Praktikum _4/Live coding/Main.java b/src/H071221104/Praktikum _4/Live coding/Main.java new file mode 100644 index 0000000..4bae3c7 --- /dev/null +++ b/src/H071221104/Praktikum _4/Live coding/Main.java @@ -0,0 +1,32 @@ +public class Main { + public static void main(String[]args){ + + + Player player = new Player (); + + player.setNama("jamal"); + player.setLevel(15); + player.setHealth(10); + player.setMana(200); + player.setExp(50); + + player.displayInfo(); + + Player player2 = new Player("jamil", 12, 11,300,60); +System.out.println(player2.getNama()); +System.out.println(player2.getLevel()); +System.out.println(player2.getHealth()); +System.out.println(player2.getMana()); +System.out.println(player2.getExp()); + + + } + +} + + + + + + + diff --git a/src/H071221104/Praktikum _4/Live coding/Player.java b/src/H071221104/Praktikum _4/Live coding/Player.java new file mode 100644 index 0000000..773001d --- /dev/null +++ b/src/H071221104/Praktikum _4/Live coding/Player.java @@ -0,0 +1,69 @@ +public class Player{ + String nama; + int level; + int health; + int mana; + int exp; + + public Player(String nama, int level, int health, int mana, int exp) { + this.nama = nama; + this.level = level; + this.health = health; + this.mana = mana; + this.exp = exp; + } + + public String getNama() { + return nama; + } + + public void setNama(String nama) { + this.nama = nama; + } + + public int getLevel() { + return level; + } + + public void setLevel(int level) { + this.level = level; + } + + public int getHealth() { + return health; + } + + public void setHealth(int health) { + this.health = health; + } + + public int getMana() { + return mana; + } + + public void setMana(int mana) { + this.mana = mana; + } + + public int getExp() { + return exp; + } + + public void setExp(int exp) { + this.exp = exp; + } + + public Player(){} + + public void displayInfo(){ + System.out.println(nama); + System.out.println(level); + System.out.println(health); + System.out.println(mana); + System.out.println(exp); + + + } + + +} \ No newline at end of file diff --git a/src/H071221104/Praktikum _4/login_app/Main.java b/src/H071221104/Praktikum _4/login_app/Main.java new file mode 100644 index 0000000..13e954d --- /dev/null +++ b/src/H071221104/Praktikum _4/login_app/Main.java @@ -0,0 +1,194 @@ +// package login_app; + +import java.util.ArrayList; +import java.util.Scanner; + +import models.Profile; +import models.User; +import utils.StringUtils; + +public class Main { + private static ArrayList listUser = new ArrayList<>(); + private static ArrayList listUserProfile = new ArrayList<>(); + private static Scanner sc = new Scanner(System.in); + + public static void main(String[] args) { + // Memanggil method runApp(); + runApp(); + } + + private static void runApp() { + // Menu Utama Aplikasi + System.out.println("-------------------------"); + System.out.println("Aplikasi Login Sederhana"); + System.out.println("-------------------------"); + System.out.println("1. Login"); + System.out.println("2. Register"); + System.out.print("> "); + + // Menginput pilihan menu + int selectMenu = sc.nextInt(); + sc.nextLine(); + switch (selectMenu) { + case 1: + // Membuka Halaman Login + showLoginMenu(); + break; + case 2: + // Membuka Halaman Register + showRegisterMenu(); + default: + // Mengulang Pemanggilan Menu Utama + runApp(); + } + } + + private static void showLoginMenu() { + // Halaman Login + System.out.println("-------------------------"); + System.out.println("Login"); + // Menginput Username dan Menyimpannya di attribute username; + System.out.println("Masukkan Username"); + System.out.print("> "); + + String username = sc.next(); + // Membuat variabel userIndex yang mana nanti akan menampung index dari user + int userIndex = -1; + for (int i = 0; i < listUser.size(); i++) { + /* + * TODO + * Buatlah sebuah perkondisian (IF) yang akan + * Mengecek apakah user index ke i dari listUser memiliki username yang sama + * dengan username yang + * diinput. + * Jika ada ganti userIndex dengan Index dari User Tersebut, kemudian hentikan + * perulangan + */ + + if (username.equals(listUser.get(i).getUsername())){ + userIndex = i; + break; + } + } + // Saat userIndex tidak sama dengan -1 atau userIndexnya ditemukan + if (userIndex != -1) { + // Menginput Password + System.out.println("Password"); + System.out.print("> "); + String password = sc.next(); + Boolean isPasswordMatch = password.equals(listUser.get(userIndex).getPassword()); + + + /* + * TODO + * Mengecek apakah password dari User yang login berdasarkan username + * sama dengan password yang diinput sebelumnya, kemudian simpan + * hasilnya di variabel isPasswordMatch + */ + + // Jika passwordnya sama maka berhasil login + if (isPasswordMatch) { + System.out.println("Berhasil Login"); + Profile profile = new Profile(); + // profile.setFullName(fullName); + // profile.setAge(age); + // profile.setHobby(hobby); + + /* + * TODO + * panggil method showDetailUser dan kirimkan data Profile User yang login + * + */ + showDetailUser(profile); + System.exit(0); + } else { + // saat password salah akan menampikan password salah + System.out.println("Password Salah"); + } + } + } + + private static void showRegisterMenu() { + System.out.println("-------------------------"); + System.out.println("REGISTER"); + + // Menginput username dan password + System.out.println("Username"); + System.out.print("> "); + String username = sc.nextLine(); + System.out.println("Password"); + System.out.print("> "); + String password = sc.nextLine(); + + /* + * TODO + * Buatlah atau Instance objek User baru, dan tambahkan + * username dan password yang diinput sebelumnya secara langsung + * saat instance User + */ + User user = new User(username, password); + + /* + * TODO + * Buatlah atau Instance objek Profile baru + */ + Profile profile = new Profile(); + + // Menginput Data Profile + System.out.println("Nama Lengkap"); + System.out.print("> "); + String fullName = sc.nextLine(); + profile.setFullName(fullName); + System.out.println("Umur"); + System.out.print("> "); + int age = sc.nextInt(); + sc.nextLine(); + System.out.println("Hobby"); + System.out.print("> "); + String hobby = sc.nextLine(); + + /* + * TODO + * Berikan nilai fullName, age, dan hobby ke objek profile yang telah + * di Instance sebelumnya. Nilai ini diperoleh dari data profile yang + * diinput sebelumnya + */ + profile.setFullName(fullName); + profile.setAge(age); + profile.setHobby(hobby); + + + /* + * TODO + * Berikan nilai nickName ke objek profile, + * Nilai ini diperoleh menggunakan static method yang dibuat di class + * StringUtils, dengan mengirimkan fullName yang diinput sebelumnya + */ + + // Menambahkan user yang dibuat ke list user + listUser.add(user); + // Menambahkan profile user yang dibuat ke list profile + listUserProfile.add(profile); + System.out.println("-------------------------"); + System.out.println("Berhasil Membuat User Baru!!"); + runApp(); + } + + private static void showDetailUser(Profile profile) { + String name = StringUtils.nickname(listUserProfile.get(0).getFullName()); + + // StringUtils stringUtils = new StringUtils(); + + /* + * TODO * + * Tampilkan semua data profile user yang login + */ + System.out.println("------------------------------"); + System.out.println("SELAMAT DATANG !!"); + System.out.println("------------------------------"); + System.out.println("Nama : " + listUserProfile.get(0).getFullName()); + System.out.println("Nickname : "+ name); + System.out.println("Umur : " + listUserProfile.get(0).getAge()); + System.out.println("Hobby : " + listUserProfile.get(0).getHobby()); + } +} diff --git a/src/H071221104/Praktikum _4/login_app/models/Profile.java b/src/H071221104/Praktikum _4/login_app/models/Profile.java new file mode 100644 index 0000000..bcce1eb --- /dev/null +++ b/src/H071221104/Praktikum _4/login_app/models/Profile.java @@ -0,0 +1,33 @@ +package models; + +public class Profile { + private String fullName, hobby; + private int age; + + public void setFullName(String fullName) { + this.fullName = fullName; + } + public void setHobby(String hobby) { + this.hobby = hobby; + } + public void setAge(int age) { + this.age = age; + } + public String getHobby() { + return hobby; + } + public String getFullName() { + return fullName; + } + public int getAge() { + return age; + } + public Profile(){ + } + + /* + * TODO: + * Tambahkan attribute, method, atau constructor + * yang dibutuhkan di kelas user + */ +} diff --git a/src/H071221104/Praktikum _4/login_app/models/User.java b/src/H071221104/Praktikum _4/login_app/models/User.java new file mode 100644 index 0000000..415a7d7 --- /dev/null +++ b/src/H071221104/Praktikum _4/login_app/models/User.java @@ -0,0 +1,25 @@ +package models; + +public class User { + private String username; + private String password; + public String getUsername() { + return username; + } + public String getPassword() { + return password; + } + public User(String username, String password){ + this.username = username; + this.password = password; + } + + + + + /* + * TODO: + * Tambahkan attribute, method, atau constructor + * yang dibutuhkan di kelas user + */ +} diff --git a/src/H071221104/Praktikum _4/login_app/utils/StringUtils.java b/src/H071221104/Praktikum _4/login_app/utils/StringUtils.java new file mode 100644 index 0000000..17f04b5 --- /dev/null +++ b/src/H071221104/Praktikum _4/login_app/utils/StringUtils.java @@ -0,0 +1,26 @@ +package utils; + +import models.Profile; + +public class StringUtils { + Profile profile = new Profile(); + /* + TODO + * Buatlah sebuah method static yang akan + * mengembalikan nickName berdasarkan fullName yang diberikan + * aturan pembuatan nickName adalah : + * 1. Jika fullName hanya 1 kata maka nickName = fullName + * (ex: FullName = Agus, maka NickName = Agus) + * 2. Jika fullName lebih dari 1 kata maka nickName adalah kata kedua dari + * fullName + * (ex: FullName = Eurico Devon, maka NickName = Devon) + */ + public static String nickname(String name){ + // Profile profile = new Profile(); + // String str = profile.getFullName(); + String[] arr = name.split(" "); + String arr2 = arr[1]; + // System.out.println(arr2); + return arr2; + } +} diff --git a/src/H071221104/Praktikum_3/Belanja.java b/src/H071221104/Praktikum_3/Belanja.java new file mode 100644 index 0000000..6195839 --- /dev/null +++ b/src/H071221104/Praktikum_3/Belanja.java @@ -0,0 +1,67 @@ +package Semester2.Praktikum.Pertemuan3; + +import java.util.ArrayList; +import java.util.Scanner; +class User { + User (){} + String name; + int balance; + public String getName() { + return name; + } + public int getBalance() { + return balance; + } +} + +class Product { + String name; + int price; + int stock; + public String getName() { + return name; + } + public int getPrice() { + return price; + } + public int getStock() { + return stock; + } + Product (String name, int price, int stock) { + this.name = name; + this.price = price; + this.stock = stock; + } +} + +class Store { + String name; + Store (String name){ + this.name = name; + } +public class Belanja { + public static void main(String[] args) { + Store store = new Store("Sisfo Computer"); + ArrayList daftarBarang = new ArrayList<>(); + daftarBarang.add("HP Pavilion Gaming 15"); + daftarBarang.add("ASUS VivoBook 15 A516MAO N4020"); + daftarBarang.add("Lenovo IdeaPad S145"); + + ArrayList hargaBarang = new ArrayList<>(); + hargaBarang.add(2000); + hargaBarang.add(4000); + hargaBarang.add(1500); + + ArrayList stokBarang = new ArrayList<>(); + stokBarang.add(15); + stokBarang.add(4); + stokBarang.add(2); + System.out.println("Selamat datang di " + store.name); + System.out.println("Daftar Produk:"); + for (int i = 0; i < daftarBarang.size(); i++) { + System.out.println((i + 1) + ". " + daftarBarang.get(i) + " - $" + hargaBarang.get(i) + "| Stok " + stokBarang.get(i)); + } + } + } +} + diff --git a/src/H071221104/Praktikum_3/Main.java b/src/H071221104/Praktikum_3/Main.java new file mode 100644 index 0000000..3df3a97 --- /dev/null +++ b/src/H071221104/Praktikum_3/Main.java @@ -0,0 +1,48 @@ +package Semester2.Praktikum.Pertemuan3; + +class Player{ + private String name; + private int hp; + private int attackPower; + private int defense; + + public Player(){} + + public void getDamage(Player enemy) { + hp = hp-Math.abs(enemy.getAttackPower()-defense); + } + public Player(String name, int attackPower, int defense){ + this.name = name; + this.attackPower = attackPower; + this.defense = defense; + this.hp = 100; + } + public Player(String name, int defense){ + this.name = name; + this.defense = defense; + this.hp = 100; + } + public void setAttackPower(int attackPower){ + this.attackPower = attackPower; + } + public void status() { + System.out.println(name + " status"); + System.out.println("HP = " + hp); + System.out.println("Defense = " + defense); + System.out.println("Attack = " + attackPower + "\n"); + } + int getAttackPower() { + return attackPower; + } +} + +public class Main { + public static void main(String [] args) { + Player player1= new Player("Mino", 30, 15); + Player player2= new Player("Hilda", 10); + player2.setAttackPower(35); + player1.getDamage(player2); + player1.status(); + player2.status(); + } +} \ No newline at end of file diff --git a/src/H071221104/Praktikum_3/MainClass.java b/src/H071221104/Praktikum_3/MainClass.java new file mode 100644 index 0000000..e072aea --- /dev/null +++ b/src/H071221104/Praktikum_3/MainClass.java @@ -0,0 +1,143 @@ +package Semester2.Praktikum.Pertemuan3; +import java.util.ArrayList; +import java.util.Scanner; +class User { + String name; + int balance; + int pilihan; + int konfirmasi; + int transaksi; + public String getName() { + return name; + } + public int getBalance() { + return balance; + } +} + +class Product { + String name; + int price; + int stock; + public String getName() { + return name; + } + public int getPrice() { + return price; + } + public int getStock() { + return stock; + } + Product (String name, int price, int stock) { + this.name = name; + this.price = price; + this.stock = stock; + } +} + +class Store { + String name; + int harga = 0; +} + +public class MainClass { + public static void main(String[] args) { + ArrayList product = new ArrayList<>(); + Store store = new Store(); + User user = new User(); + Scanner input = new Scanner(System.in); + do { + Product produk1 = new Product("HP Pavilion Gaming 15", 2000, 15); + Product produk2 = new Product("ASUS VivoBook 15 A516MAO N4020", 4000, 4); + Product produk3 = new Product("Lenovo IdeaPad S145", 1500, 2); + System.out.print("Masukkan nama pengguna: "); + user.name = input.nextLine(); + System.out.print("Masukkan jumlah uang yang dimiliki: "); + user.balance = input.nextInt(); + System.out.println("----------CARD----------"); + System.out.println(user.name); + System.out.println(user.balance); + System.out.println("------------------------"); + System.out.println("Selamat Datang di " + store.name); + System.out.println("Daftar Produk"); + System.out.println("1." + produk1.name + " - $" + produk1.price + " | Stok " + produk1.stock ); + System.out.println("2." + produk2.name + " - $" + produk2.price + " | Stok " + produk2.stock ); + System.out.println("3." + produk3.name + " - $" + produk3.price + " | Stok " + produk3.stock ); + System.out.println("0.Keluar"); + System.out.print("> "); + } while (user.pilihan != 0); + user.pilihan = input.nextInt(); + do { + if (user.pilihan == 1){ + user.balance = user.balance - produk1.price; + if (user.balance >= 0){ + System.out.println("Apakah anda yakin ingin membeli: "); + System.out.println(produk1.name + ", " + "dengan Harga $" + produk1.price); + System.out.println("1. Konfirmasi"); + System.out.println("2. Batal"); + System.out.print("> "); + user.konfirmasi = input.nextInt(); + if (user.konfirmasi == 1){ + product.add(produk1.nama); + produk1.stock -= 1; + store.harga += produk1.price; + System.out.println(user.name + " berhasil membeli " + produk1.name + "."); + System.out.println("---------------"); + System.out.println("Lanjutkan Transaksi?"); + System.out.println("1. Iya"); + System.out.println("2. Tidak"); + System.out.print("> "); + user.transaksi = input.nextInt(); + } + } else { + System.out.println("uang anda tidak cukup"); + } + } else if (user.pilihan == 2){ + if (user.balance >= produk2.price){ + System.out.println("Apakah anda yakin ingin membeli: "); + System.out.println(produk2.name + ", " + "dengan Harga $" + produk2.price); + System.out.println("1. Konfirmasi"); + System.out.println("2. Batal"); + System.out.print("> "); + user.konfirmasi = input.nextInt(); + if (user.konfirmasi == 1){ + System.out.println(user.name + " berhasil membeli " + produk2.name + "."); + System.out.println("---------------"); + System.out.println("Lanjutkan Transaksi?"); + System.out.println("1. Iya"); + System.out.println("2. Tidak"); + System.out.print("> "); + user.transaksi = input.nextInt(); + } + } else { + System.out.println("Uang anda tidak cukup"); + } + } else if (user.pilihan == 3){ + if (user.balance >= produk1.price){ + System.out.println("Apakah anda yakin ingin membeli: "); + System.out.println(produk3.name + ", " + "dengan Harga $" + produk3.price); + System.out.println("1. Konfirmasi"); + System.out.println("2. Batal"); + System.out.print("> "); + user.konfirmasi = input.nextInt(); + if (user.konfirmasi == 1){ + System.out.println(user.name + " berhasil membeli " + produk3.name + "."); + System.out.println("---------------"); + System.out.println("Lanjutkan Transaksi?"); + System.out.println("1. Iya"); + System.out.println("2. Tidak"); + System.out.print("> "); + user.transaksi = input.nextInt(); + } + } else { + System.out.println("Uang anda tidak cukup"); + } + } + input.close(); + } while(user.transaksi == 2); + System.out.println("Anda membeli produk: "); + System.out.println(product); + System.out.println("Dengan harga: " + store.harga); + } +} + diff --git a/src/H071221104/Praktikum_3/Panggil.java b/src/H071221104/Praktikum_3/Panggil.java new file mode 100644 index 0000000..3a6b3fe --- /dev/null +++ b/src/H071221104/Praktikum_3/Panggil.java @@ -0,0 +1,54 @@ +import java.util.ArrayList; +import java.util.Scanner; + +class User { + private String name; + private int balance; + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public int getBalance() { + return balance; + } + public void setBalance(int balance) { + this.balance = balance; + } + User (String name, int balance){ + this.name = name; + this.balance = balance; + } +} +class Product { + private String name; + private int price; + private int stock; + public String getName() { + return name; + } + public int getPrice() { + return price; + } + public int getStock() { + return stock; + } +} +class Store { + private String name; + private String products; + Store(String name){ + this.name = name; + } +} + + +public class Panggil { + public static void main(String[] args) { + ArrayList produk = new Arraylist(); + produk.add("HP Pavilion Gaming 15"); + produk.add("ASUS VivoBook 15 A516MAO N4020"); + produk.add("Lenovo IdeaPad S145"); + } +} diff --git a/src/H071221104/Praktikum_3/ProgramBelanja.java b/src/H071221104/Praktikum_3/ProgramBelanja.java new file mode 100644 index 0000000..35c9b33 --- /dev/null +++ b/src/H071221104/Praktikum_3/ProgramBelanja.java @@ -0,0 +1,105 @@ +package Semester2.Praktikum.Pertemuan3; +import java.util.ArrayList; +import java.util.Scanner; + +class Barang { + private String nama; + private int harga; + private int stok; + + public Barang(String nama, int harga, int stok) { + this.nama = nama; + this.harga = harga; + this.stok = stok; + } + + public String getNama() { + return nama; + } + + public int getHarga() { + return harga; + } + + public int getStok() { + return stok; + } + + public void kurangiStok(int jumlah) { + stok -= jumlah; + } + + public String toString() { + return nama + " (Rp" + harga + ") - Stok: " + stok; + } +} + +class Pembeli { + private int uang; + + public Pembeli(int uang) { + this.uang = uang; + } + + public int getUang() { + return uang; + } + + public boolean kurangiUang(int harga) { + if (uang >= harga) { + uang -= harga; + return true; + } else { + return false; + } + } +} + +public class ProgramBelanja { + public static void main(String[] args) { + ArrayList daftarBarang = new ArrayList<>(); + daftarBarang.add(new Barang("Buku", 10000, 5)); + daftarBarang.add(new Barang("Pensil", 2000, 10)); + daftarBarang.add(new Barang("Penghapus", 3000, 7)); + daftarBarang.add(new Barang("Spidol", 5000, 3)); + + Scanner input = new Scanner(System.in); + + System.out.print("Masukkan uang Anda: "); + int uang = input.nextInt(); + Pembeli pembeli = new Pembeli(uang); + + int pilihan; + do { + System.out.println("\nDaftar Barang:"); + for (int i = 0; i < daftarBarang.size(); i++) { + System.out.println((i + 1) + ". " + daftarBarang.get(i)); + } + + System.out.println("0. Selesai belanja"); + + System.out.println("\nUang Anda: Rp" + pembeli.getUang()); + + System.out.print("Pilih barang yang ingin dibeli: "); + pilihan = input.nextInt(); + + if (pilihan > 0 && pilihan <= daftarBarang.size()) { + Barang barangDipilih = daftarBarang.get(pilihan - 1); + if (barangDipilih.getStok() > 0 && pembeli.kurangiUang(barangDipilih.getHarga())) { + barangDipilih.kurangiStok(1); + System.out.println("Barang berhasil dibeli!"); + } else { + System.out.println("Barang tidak dapat dibeli."); + } + } else if (pilihan != 0) { + System.out.println("Pilihan tidak valid."); + } + } while (pilihan != 0); + + System.out.println("\nBarang yang tersedia:"); + for (Barang barang : daftarBarang) { + System.out.println(barang); + } + System.out.println("Uang Anda: Rp" + pembeli.getUang()); + } +} \ No newline at end of file diff --git a/src/H071221104/Praktikum_3/Super.java b/src/H071221104/Praktikum_3/Super.java new file mode 100644 index 0000000..77d9110 --- /dev/null +++ b/src/H071221104/Praktikum_3/Super.java @@ -0,0 +1,55 @@ +package Semester2.Praktikum.Pertemuan3; +public class Super { + public static void main(String[] args) { + Hero hero = new Hero(); + hero.role = "Assasin"; + hero.type = "Attacker"; + + SungJin sungJin = new SungJin("Sung Jin Wo", 150, 500); + sungJin.roletype = hero; + + //Sebelum menggunakan spesial skill + System.out.println("Before:"); + sungJin.getStat(); + System.out.println("Type: " + hero.getRoleType()); + + //Setelah menggunakan spesial skill + System.out.println("\nAfter: "); + sungJin.SpesialSkill(); + sungJin.getStat(); + System.out.println("Type: " + hero.getRoleType()); + } +} +class Hero{ + String role; + String type; + String getRoleType(){ + return role + ", " + type; + } +} +class SungJin{ + Hero roletype; + String nama; + int power; + int health; + public SungJin() {} + + public SungJin(String nama) { + this.nama = nama; + } + public SungJin(String nama, int power, int health){ + this.nama = nama; + this.power = power; + this.health = health; + } + + public void getStat(){ + System.out.println("nama: " + nama); + System.out.println("Power: " + power); + System.out.println("Health: " + health); + } + public void SpesialSkill(){ + this.power += 50; + this.health += 100; + } +} diff --git a/src/H071221104/Praktikum_3/no3/Product.java b/src/H071221104/Praktikum_3/no3/Product.java new file mode 100644 index 0000000..32116bf --- /dev/null +++ b/src/H071221104/Praktikum_3/no3/Product.java @@ -0,0 +1,24 @@ +public class Product { + private String name; + private int price; + private int stock; + public String getName() { + return name; + } + public int getPrice() { + return price; + } + public int getStock() { + return stock; + } + public Product(String name, int price, int stock){ + this.name = name; + this.price = price; + this.stock = stock; + } + + public int itemSell(){ + this.stock -= 1; + return this.stock; + } +} diff --git a/src/H071221104/Praktikum_3/no3/Store.java b/src/H071221104/Praktikum_3/no3/Store.java new file mode 100644 index 0000000..84a1b3e --- /dev/null +++ b/src/H071221104/Praktikum_3/no3/Store.java @@ -0,0 +1,55 @@ +import java.util.ArrayList; + +public class Store { + String name; + + ArrayList products = new ArrayList<>(); + ArrayList productsStock = new ArrayList<>(); + ArrayList productsPrice = new ArrayList<>(); + + public Store(String name){ + this.name = name; + } + + public void addProduct(Product prod){ + products.add(prod.getName()); + productsPrice.add(prod.getPrice()); + productsStock.add(prod.getStock()); + } + + public void showProduct(){ + System.out.println("Daftar produk : "); + + for (int i = 0; i < products.size(); i+=1){ + System.out.printf("%d. %s - $%d | Stok %d \n", i+1, products.get(i), productsPrice.get(i), productsStock.get(i)); + } + } + + public void transaksi(int prodNum, User user){ + Product prod = new Product(products.get(prodNum), productsPrice.get(prodNum), productsStock.get(prodNum)); + + if (prod.getStock() > 0){ + if(user.getBalance() >= prod.getPrice()){ + user.balance -= prod.getPrice(); + + prod.itemSell(); + productsStock.set(prodNum, prod.getStock()); + + if (prod.getStock() <= 0) { + products.remove(prod.getName()); + productsPrice.remove(Integer.valueOf(prod.getPrice())); + productsStock.remove(Integer.valueOf(prod.getStock())); + } + System.out.printf("%s Berhasil membeli %s \n", user.getName(), products.get(prodNum)); + } else { + System.out.println("Barang gagal dibeli, uang anda tidak cukup"); + } + } else { + System.out.println("Maaf stock untuk barang ini tidak tersedia"); + } + } + + public String getName(){ + return this.name; + } +} diff --git a/src/H071221104/Praktikum_3/no3/StoreOri.java b/src/H071221104/Praktikum_3/no3/StoreOri.java new file mode 100644 index 0000000..0e4e14e --- /dev/null +++ b/src/H071221104/Praktikum_3/no3/StoreOri.java @@ -0,0 +1,86 @@ +import java.util.Scanner; + +public class StoreOri { + public static void main(String[] args) { + Store store = new Store("Toko Ashiapp"); + User user = new User("Orii", 3000); + + Product produk1 = new Product("Ipong", 1000, 5); + Product produk2 = new Product("Oddo", 500, 3); + Product produk3 = new Product("Vovo", 750, 2); + + store.addProduct(produk1); + store.addProduct(produk2); + store.addProduct(produk3); + + runStore(store, user); + } + + public static void runStore(Store store, User user){ + Scanner inp = new Scanner(System.in); + + user.showCard(); + System.out.println("Selamat datang di " + store.getName()); + store.showProduct(); + System.out.println("0. Keluar"); + + try { + int responOption = inp.nextInt(); + int responProd = responOption - 1; + + if (responOption == 0){ + System.out.println("=============================="); + System.out.printf("Sisa uang anda : %d \n", user.getBalance()); + System.out.println("Terima kasih telah berbelanja"); + System.out.println("=============================="); + inp.close(); + return; + } + if (responOption < 0){ + responOption = 0; + } + + if (responOption > store.products.size()){ + System.out.println("=============================="); + System.out.println("Maaf opsi tidak ada"); + System.out.println("=============================="); + runStore(store, user); + } + + System.out.println("Apakah anda yakin ingin membeli :"); + System.out.printf("%s dengan harga $%d ? \n", store.products.get(responProd), store.productsPrice.get(responProd)); + System.out.println("1. Konfirmasi"); + System.out.println("2. Batal"); + System.out.print(">. "); + int responKonfir = inp.nextInt(); + + if (responKonfir == 1){ + store.transaksi(responKonfir, user); + System.out.println("Lanjutkan transaksi ??"); + System.out.println("1. Iya"); + System.out.println("2. Tidak"); + System.out.print(">. "); + int responKonfirAction = inp.nextInt(); + + if (responKonfirAction == 1){ + runStore(store, user); + } else { + System.out.println("=============================="); + System.out.printf("Sisa uang anda : %d \n", user.getBalance()); + System.out.println("Terima kasih telah berbelanja"); + System.out.println("=============================="); + inp.close(); + return; + } + } else if (responKonfir == 2){ + runStore(store, user); + } + } catch (Exception e) { + System.out.println("Maaf input hanya berupa bilangan bulat"); + System.out.println("Byeee ~~~~~"); + inp.close(); + return; + } + inp.close(); + } +} diff --git a/src/H071221104/Praktikum_3/no3/User.java b/src/H071221104/Praktikum_3/no3/User.java new file mode 100644 index 0000000..15703ee --- /dev/null +++ b/src/H071221104/Praktikum_3/no3/User.java @@ -0,0 +1,23 @@ +public class User { + private String name; + int balance; + public String getName() { + return name; + } + public int getBalance() { + return balance; + } + + public User(String name, int balance){ + this.name = name; + this.balance = balance; + } + + public void showCard(){ + System.out.println("========== CARD =========="); + System.out.println("Nama : " + getName()); + System.out.println("Balance : " + getBalance()); + System.out.println("========== CARD =========="); + } +} + diff --git a/src/H071221104/Praktikum_5/no1/Bangun.java b/src/H071221104/Praktikum_5/no1/Bangun.java new file mode 100644 index 0000000..81e18b2 --- /dev/null +++ b/src/H071221104/Praktikum_5/no1/Bangun.java @@ -0,0 +1,142 @@ +import java.util.Scanner; +public class Bangun { + Kubus kubus = new Kubus(); + Balok balok = new Balok(); + Bola bola = new Bola(); + Tabung tabung = new Tabung(); + Persegi persegi = new Persegi(); + PersegiPanjang persegiPanjang = new PersegiPanjang(); + Lingkaran lingkaran = new Lingkaran(); + Segitiga segitiga = new Segitiga(); + Trapesium trapesium = new Trapesium(); + BangunDatar bangunDatar = new BangunDatar(); + BangunRuang bangunRuang = new BangunRuang(); + int pilih,pilih2,pilih3; + public void showMenu(){ + Scanner inp = new Scanner(System.in); + System.out.println("1. ==== BANGUN RUANG ===="); + System.out.println("2. ==== BANGUN DATAR ===="); + System.out.print("Pilih : "); + int pilih = inp.nextInt(); + // inp.close(); + if (pilih == 1){ + System.out.println("==== BANGUN RUANG ===="); + System.out.println("1. KUBUS"); + System.out.println("2. BALOK"); + System.out.println("3. BOLA"); + System.out.println("4. TABUNG"); + System.out.print("Pilih : "); + int pilih2 = inp.nextInt(); + if (pilih2 == 1){ + System.out.println("1. Luas"); + System.out.println("2. Volume"); + System.out.print("Pilih : "); + int pilih3 = inp.nextInt(); + if (pilih3 == 1){ + kubus.luas(); + } else { + kubus.volume(); + } + // inp.close(); + } else if (pilih2 == 2){ + System.out.println("1. Luas"); + System.out.println("2. Volume"); + System.out.print("Pilih : "); + int pilih3 = inp.nextInt(); + if (pilih3 == 1){ + balok.luas(); + } else { + balok.volume(); + } + // inp.close(); + } else if (pilih2 == 3){ + System.out.println("1. Luas"); + System.out.println("2. Volume"); + System.out.print("Pilih : "); + int pilih3 = inp.nextInt(); + if (pilih3 == 1){ + bola.luas(); + } else { + bola.volume(); + } + // inp.close(); + } else if (pilih2 == 4){ + System.out.println("1. Luas"); + System.out.println("2. Volume"); + System.out.print("Pilih : "); + int pilih3 = inp.nextInt(); + if (pilih3 == 1){ + tabung.luas(); + } else { + tabung.volume(); + } + // inp.close(); + } + } else if(pilih == 2){ + System.out.println("==== BANGUN DATAR ===="); + System.out.println("1. PERSEGI"); + System.out.println("2. PERSEGI PANJANG"); + System.out.println("3. LINGKARAN"); + System.out.println("4. SEGITIGA"); + System.out.println("5. TRAPESIUM"); + System.out.print("Pilih : "); + int pilih2 = inp.nextInt(); + if (pilih2 == 1){ + System.out.println("1. Luas"); + System.out.println("2. Keliling"); + System.out.print("Pilih : "); + int pilih3 = inp.nextInt(); + if (pilih3 == 1){ + persegi.luas(); + } else { + persegi.keliling(); + } + // inp.close(); + } else if (pilih2 == 2){ + System.out.println("1. Luas"); + System.out.println("2. Keliling"); + System.out.print("Pilih : "); + int pilih3 = inp.nextInt(); + if (pilih3 == 1){ + persegiPanjang.luas(); + } else { + persegiPanjang.keliling(); + } + // inp.close(); + } else if (pilih2 == 3){ + System.out.println("1. Luas"); + System.out.println("2. Keliling"); + System.out.print("Pilih : "); + int pilih3 = inp.nextInt(); + if (pilih3 == 1){ + lingkaran.luas(); + } else { + lingkaran.keliling(); + } + // inp.close(); + } else if (pilih2 == 4){ + System.out.println("1. Luas"); + System.out.println("2. Keliling"); + System.out.print("Pilih : "); + int pilih3 = inp.nextInt(); + if (pilih3 == 4){ + segitiga.luas(); + } else { + segitiga.keliling(); + } + // inp.close(); + } else if (pilih2 == 5){ + System.out.println("1. Luas"); + System.out.println("2. Keliling"); + System.out.print("Pilih : "); + int pilih3 = inp.nextInt(); + if (pilih3 == 1){ + trapesium.luas(); + } else { + trapesium.keliling(); + } + // inp.close(); + } + } inp.close(); + } +} diff --git a/src/H071221104/Praktikum_5/no1/BangunDatar.java b/src/H071221104/Praktikum_5/no1/BangunDatar.java new file mode 100644 index 0000000..9038734 --- /dev/null +++ b/src/H071221104/Praktikum_5/no1/BangunDatar.java @@ -0,0 +1,116 @@ +import java.util.Scanner; +public class BangunDatar{ + public void luas(){ + System.out.println("Menampilkan luas bangun datar"); + } + public void keliling(){ + System.out.println("menampilkan keliling bangun datar"); + } +} + +class Persegi extends BangunDatar{ + int s; + Scanner inp = new Scanner(System.in); + public void luas(){ + System.out.print("Masukkan panjang sisi : "); + int s = inp.nextInt(); + System.out.println("Luas persegi adalah : " + s*s); + } + + public void keliling(){ + System.out.print("Masukkan panjang sisi : "); + int s = inp.nextInt(); + System.out.println("Keliling persegi adalah : " + 4*s); + super.keliling(); + inp.close(); + } +} + +class PersegiPanjang extends BangunDatar{ + int p,l; + Scanner inp = new Scanner(System.in); + public void luas(){ + System.out.println("Masukkan panjang : "); + int p = inp.nextInt(); + System.out.println("Masukkan lebar : "); + int l = inp.nextInt(); + System.out.println("Luas Persegi Panjang adalah : " + p*l); + } + public void keliling(){ + System.out.println("Masukkan panjang : "); + int p = inp.nextInt(); + System.out.println("Masukkan lebar : "); + int l = inp.nextInt(); + System.out.println("Keliling Persegi panjang adalah : " + (2*p) + (2*l)); + super.keliling(); + inp.close(); + } +} + +class Lingkaran extends BangunDatar{ + double pi = 3.14; + int r,d; + Scanner inp = new Scanner(System.in); + public void luas(){ + System.out.println("Masukkan Jari-jari : "); + int r = inp.nextInt(); + System.out.println("Luas lingkaran : " + pi*r*r); + } + + public void keliling(){ + System.out.println("Masukkan diameter : " ); + int d = inp.nextInt(); + System.out.println("Keliling lingkarang adalah : " + pi*d); + super.keliling(); + inp.close(); + } +} + +class Segitiga extends BangunDatar{ + int a,t,s1,s2,s3; + Scanner inp = new Scanner(System.in); + public void luas(){ + System.out.println("Masukkan alas : "); + int a = inp.nextInt(); + System.out.println("Masukkan tinggi : "); + int t = inp.nextInt(); + System.out.println("Luas segitiga adalah : " + 0.5*a*t); + } + public void keliling(){ + System.out.println("Masukkan sisi 1 : "); + int s1 = inp.nextInt(); + System.out.println("Masukkan sisi 2 : "); + int s2 = inp.nextInt(); + System.out.println("Masukkan sisi 3 : "); + int s3 = inp.nextInt(); + System.out.println("Keliling segitiga adalah : " + s1+s2+s3); + super.keliling(); + inp.close(); + } +} + +class Trapesium extends BangunDatar{ + int a,b,c,d,t,s1,s2,s3,s4; + Scanner inp = new Scanner(System.in); + public void luas(){ + System.out.println("Masukkan sisi a : "); + int a = inp.nextInt(); + System.out.println("Masukkan sisi b : "); + int b = inp.nextInt(); + System.out.println("Masukkan tinggi : "); + int t = inp.nextInt(); + System.out.println("Luas trapesium adalah : " + 0.5*t*(a+b)); + } + public void keliling(){ + System.out.println("Masukkan sisi 1 : "); + int s1 = inp.nextInt(); + System.out.println("Masukkan sisi 2 : "); + int s2 = inp.nextInt(); + System.out.println("Masukkan sisi 3 : "); + int s3 = inp.nextInt(); + System.out.println("Masukkan sisi 4 : "); + int s4 = inp.nextInt(); + System.out.println("Keliling trapesium adalah : " + (s1+s2+s3+s4)); + super.keliling(); + } +} diff --git a/src/H071221104/Praktikum_5/no1/BangunRuang.java b/src/H071221104/Praktikum_5/no1/BangunRuang.java new file mode 100644 index 0000000..c5f703f --- /dev/null +++ b/src/H071221104/Praktikum_5/no1/BangunRuang.java @@ -0,0 +1,147 @@ +import java.util.Scanner; +public class BangunRuang{ + public void luas(){ + System.out.println("meanmpilkan luas bangun ruang"); + } + public void volume(){ + System.out.println("Menampilkan volume bangun ruang"); + } +} + +class Kubus extends BangunRuang{ + // private int s,r; + Scanner inp = new Scanner(System.in); + public void luas(){ + System.out.print("Masukkan sisi : "); + int s = inp.nextInt(); + System.out.println("Luas kubus adalah : " + 6*(s*s)); + } + public void volume(){ + System.out.print("Masukkan panjang rusuk : "); + int r = inp.nextInt(); + System.out.println("Volume kubus adalah : " + 12*r); + super.volume(); + } +} + +class Balok extends BangunRuang{ + // private int p,l,t; + Scanner inp = new Scanner(System.in); + public void luas(){ + System.out.print("Masukkan panjang : "); + int p = inp.nextInt(); + System.out.print("Masukkan lebar : "); + int l = inp.nextInt(); + System.out.print("Masukkan tinggi : "); + int t = inp.nextInt(); + System.out.println("Luas balok adalah : " + 2*(p*l)+2*(l*t)+2*(p*t)); + } + public void volume(){ + System.out.print("Masukkan panjang : "); + int p = inp.nextInt(); + System.out.print("Masukkan lebar : "); + int l = inp.nextInt(); + System.out.print("Masukkan tinggi : "); + int t = inp.nextInt(); + System.out.print("Volume balok adalah : " + 4 * (p+l+t)); + super.volume(); + inp.close(); + } +} + +class Bola extends BangunRuang{ + private double pi = 3.14; + Scanner inp = new Scanner(System.in); + public void luas(){ + System.out.print("Masukkan diameter : "); + int d = inp.nextInt(); + System.out.println("Luas bola adalah : " + pi*(d*d)); + } + public void volume(){ + System.out.print("Masukkan jari-jari : "); + int r = inp.nextInt(); + System.out.println("Volume bola adalah : " + 4/3 * pi * (r*r*r)); + super.volume(); + inp.close(); + } +} + +class Tabung extends BangunRuang{ + private double pi = 3.14; + Scanner inp = new Scanner(System.in); + public void luas(){ + System.out.print("Masukkan jari-jari : "); + int r = inp.nextInt(); + System.out.print("Masukkan tinggi : "); + int t = inp.nextInt(); + System.out.println("Luas tabung adalah : " + 2 * pi * r * (r+t)); + } + public void volume(){ + System.out.print("Masukkan jari-jari : "); + int r = inp.nextInt(); + System.out.print("Masukkan tinggi : "); + int t = inp.nextInt(); + System.out.println("Volume tabung adalah : " + pi * (r*r) * t); + super.volume(); + inp.close(); + } + + public void showMenu(){ + Kubus kubus = new Kubus(); + Balok balok = new Balok(); + Bola bola = new Bola(); + Tabung tabung = new Tabung(); + System.out.println("==== BANGUN RUANG ===="); + System.out.println("1. KUBUS"); + System.out.println("2. BALOK"); + System.out.println("3. BOLA"); + System.out.println("4. TABUNG"); + System.out.print("Pilih : "); + int pilih2 = inp.nextInt(); + if (pilih2 == 1){ + System.out.println("1. Luas"); + System.out.println("2. Volume"); + System.out.print("Pilih : "); + int pilih3 = inp.nextInt(); + if (pilih3 == 1){ + kubus.luas(); + } else { + kubus.volume(); + } + inp.close(); + } else if (pilih2 == 2){ + System.out.println("1. Luas"); + System.out.println("2. Volume"); + System.out.print("Pilih : "); + int pilih3 = inp.nextInt(); + if (pilih3 == 1){ + balok.luas(); + } else { + balok.volume(); + } + inp.close(); + } else if (pilih2 == 3){ + System.out.println("1. Luas"); + System.out.println("2. Volume"); + System.out.print("Pilih : "); + int pilih3 = inp.nextInt(); + if (pilih3 == 1){ + bola.luas(); + } else { + bola.volume(); + } + inp.close(); + } else if (pilih2 == 4){ + System.out.println("1. Luas"); + System.out.println("2. Volume"); + System.out.print("Pilih : "); + int pilih3 = inp.nextInt(); + if (pilih3 == 1){ + tabung.luas(); + } else { + tabung.volume(); + } + inp.close(); + } + } +} \ No newline at end of file diff --git a/src/H071221104/Praktikum_5/no1/Main.java b/src/H071221104/Praktikum_5/no1/Main.java new file mode 100644 index 0000000..0379f99 --- /dev/null +++ b/src/H071221104/Praktikum_5/no1/Main.java @@ -0,0 +1,8 @@ +// import java.util.Scanner; +public class Main{ + public static void main(String[] args) { + Bangun bangun = new Bangun(); + // BangunRuang bangunRuang = new BangunRuang(); + bangun.showMenu(); + } +} \ No newline at end of file diff --git a/src/H071221104/Praktikum_5/no2/Kordinator.java b/src/H071221104/Praktikum_5/no2/Kordinator.java new file mode 100644 index 0000000..710923a --- /dev/null +++ b/src/H071221104/Praktikum_5/no2/Kordinator.java @@ -0,0 +1,5 @@ +public class Kordinator extends Sisfo{ + public void suara(){ + System.out.println("Aku sebagai Kordinator Bidang"); + } +} diff --git a/src/H071221104/Praktikum_5/no2/Main.java b/src/H071221104/Praktikum_5/no2/Main.java new file mode 100644 index 0000000..e3f88b8 --- /dev/null +++ b/src/H071221104/Praktikum_5/no2/Main.java @@ -0,0 +1,15 @@ +public class Main { + public static void main(String[] args) { + Sisfo sisfo = new Sisfo(); + Kordinator kordinator = new Kordinator(); + Staf staf = new Staf(); + Pengurus pengurus = new Pengurus(); + kordinator.suara(); + pengurus.suara(); + staf.suara(); + sisfo.slogan(); + kordinator.slogan(); + staf.slogan(); + + } +} \ No newline at end of file diff --git a/src/H071221104/Praktikum_5/no2/Pengurus.java b/src/H071221104/Praktikum_5/no2/Pengurus.java new file mode 100644 index 0000000..82f712a --- /dev/null +++ b/src/H071221104/Praktikum_5/no2/Pengurus.java @@ -0,0 +1,5 @@ +public class Pengurus extends Sisfo{ + public void suara(){ + System.out.println("Aku sebagai Pengurus inti"); + } +} diff --git a/src/H071221104/Praktikum_5/no2/Sisfo.java b/src/H071221104/Praktikum_5/no2/Sisfo.java new file mode 100644 index 0000000..23affa5 --- /dev/null +++ b/src/H071221104/Praktikum_5/no2/Sisfo.java @@ -0,0 +1,6 @@ +public class Sisfo { + String name; + public void slogan(){ + System.out.println("========== Sistem Informati, Harga Mati =========="); + } +} diff --git a/src/H071221104/Praktikum_5/no2/Staf.java b/src/H071221104/Praktikum_5/no2/Staf.java new file mode 100644 index 0000000..9826951 --- /dev/null +++ b/src/H071221104/Praktikum_5/no2/Staf.java @@ -0,0 +1,5 @@ +public class Staf extends Sisfo{ + public void suara(){ + System.out.println("Aku sebagai Staf"); + } +} diff --git a/src/H071221104/Praktikum_5/no3/Class diagram no1.drawio.png b/src/H071221104/Praktikum_5/no3/Class diagram no1.drawio.png new file mode 100644 index 0000000..8e45de4 Binary files /dev/null and b/src/H071221104/Praktikum_5/no3/Class diagram no1.drawio.png differ diff --git a/src/H071221104/Praktikum_5/no3/Class diagram no2.drawio.png b/src/H071221104/Praktikum_5/no3/Class diagram no2.drawio.png new file mode 100644 index 0000000..8d1a2f1 Binary files /dev/null and b/src/H071221104/Praktikum_5/no3/Class diagram no2.drawio.png differ diff --git a/src/H071221104/Praktikum_6/Main.java b/src/H071221104/Praktikum_6/Main.java new file mode 100644 index 0000000..c09f443 --- /dev/null +++ b/src/H071221104/Praktikum_6/Main.java @@ -0,0 +1,153 @@ +interface Dog{ + void move(); + void describe(); +} + +abstract class Alat { + abstract void move(); +} + +class Pitbul implements Dog{ + private int position = 0; + private int averageLength; + + @Override + public void describe(){ + System.out.println("Ciri-ciri : Anjing Pitbul memiliki tubuh yang berotot dan gagah"); + } + @Override + public void move() { + position += 3; + System.out.println("Pitbul berada di posisi " + position); + } +} + +class Siberian_Husky implements Dog{ + private int position = 0; + private int averageLength; + + @Override + public void move() { + position += 2; + System.out.println("Siberian Husky berada di posisi " + position); + } + + @Override + public void describe() { + System.out.println("Ciri-ciri : Anjing Siberian Husky adalah anjing yang sangat energik dan ramah"); + } +} + +class Bulldog implements Dog { + private int position = 0; + private int averageLength; + @Override + public void describe(){ + System.out.println("Ciri-ciri : Anjing Bulldog memiliki ekstra kulit yang jatuh berlipat"); + } + @Override + public void move(){ + position += 1; + System.out.println("Bulldog berada di posisi " + position); + } +} + +class German_Shepherd implements Dog{ + private int position = 0; + private int averageLength; + @Override + public void describe(){ + System.out.println("Anjing German Shepherd memiliki struktur tulang yang solid"); + } + + @Override + public void move(){ + position += 3; + System.out.println("German Shepherd berada di posisi " + position); + } +} + +class Smartphone extends Alat{ + private int price; + private String brand; + public Smartphone(int price, String brand){ + this.price = price; + this.brand = brand; + } + public int getPrice() { + return price; + } + public void setPrice(int price) { + this.price = price; + } + public String getBrand() { + return brand; + } + public void setBrand(String brand) { + this.brand = brand; + } + @Override + public void move() { + System.out.println("Smartphone berpindah"); + } + public void showDetail(){ + System.out.println("Brand : " + getBrand()); + System.out.println("Price : " + getPrice()); + } +} + +class Car extends Alat{ + private int totalForwardGear; + private String color; + private int maxSpeed; + public Car (int totalForwardGear, String color, int maxSpeed){ + this.totalForwardGear = totalForwardGear; + this.color = color; + this.maxSpeed = maxSpeed; + } + public int getTotalForwardGear() { + return totalForwardGear; + } + public void setTotalForwardGear(int totalForwardGear) { + this.totalForwardGear = totalForwardGear; + } + public String getColor() { + return color; + } + public void setColor(String color) { + this.color = color; + } + public int getMaxSpeed() { + return maxSpeed; + } + public void setMaxSpeed(int maxSpeed) { + this.maxSpeed = maxSpeed; + } + + @Override + public void move(){ + System.out.println("Mobil sedang berakselerasi"); + } + + public void showDetail(){ + System.out.println("Color : " + getColor()); + System.out.println("Total Forward Gear : " + getTotalForwardGear()); + System.out.println("Max Speed : " + getMaxSpeed() + "km/h"); + } +} +public class Main { + public static void main(String[] args) { + Smartphone smartphone = new Smartphone(500, "Nokia"); + Pitbul pitbul = new Pitbul(); + Car car = new Car(5, "Black", 200); + System.out.println("========== DOG =========="); + pitbul.describe(); + pitbul.move(); + System.out.println("\n========== ALAT =========="); + car.move(); + car.showDetail(); + System.out.println("\n========== ALAT =========="); + smartphone.showDetail(); + smartphone.move(); + } +} \ No newline at end of file diff --git a/src/H071221104/Praktikum_6/diagram class.drawio b/src/H071221104/Praktikum_6/diagram class.drawio new file mode 100644 index 0000000..dd4f761 --- /dev/null +++ b/src/H071221104/Praktikum_6/diagram class.drawio @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/H071221104/Praktikum_6/diagram class.png b/src/H071221104/Praktikum_6/diagram class.png new file mode 100644 index 0000000..6c8089b Binary files /dev/null and b/src/H071221104/Praktikum_6/diagram class.png differ diff --git a/src/H071221104/Praktikum_6/diagram class.svg b/src/H071221104/Praktikum_6/diagram class.svg new file mode 100644 index 0000000..75c05ac --- /dev/null +++ b/src/H071221104/Praktikum_6/diagram class.svg @@ -0,0 +1,4 @@ + + + +Interface Dog+describe() : void+move() : voidPitbul+ position: int + averageLength: int+describe(): void+move() : voidGerman Shepherd+ position: int + averageLength: int+describe(): void+move() : voidBulldog+ position: int + averageLength: int+describe(): void+move() : voidSiberian Husky+ position: int + averageLength: int+describe(): void+move() : voidAbstract Alat+move() : voidSmartphone+ price: int + brand: String+move() : voidAlat+ totalForwardGear: int +:color: String+ maxSpeed: int+move() : void \ No newline at end of file diff --git a/src/H071221104/Praktikum_6/diagram dipa.svg b/src/H071221104/Praktikum_6/diagram dipa.svg new file mode 100644 index 0000000..92b417c --- /dev/null +++ b/src/H071221104/Praktikum_6/diagram dipa.svg @@ -0,0 +1,4 @@ + + + +abstract Dogy+describe() : void+move() : voidPitbul+ position: int + averageLength: int+describe(): void+move() : voidGerman Shepherd+ position: int + averageLength: int+describe(): void+move() : voidBulldog+ position: int + averageLength: int+describe(): void+move() : voidSiberian Husky+ position: int + averageLength: int+describe(): void+move() : voidinterface Teknologi+move() : voidSmartphone+ price: int + brand: String+move() : voidAlat+ totalForwardGear: int +:color: String+ maxSpeed: int+move() : void \ No newline at end of file diff --git a/src/H071221104/Praktikum_7/no1/Character.java b/src/H071221104/Praktikum_7/no1/Character.java new file mode 100644 index 0000000..875a9ef --- /dev/null +++ b/src/H071221104/Praktikum_7/no1/Character.java @@ -0,0 +1,13 @@ +abstract public class Character { + private String name; + + public Character (String name){ + this.name = name; + } + public String getName() { + return this.name; + } + abstract int attack(); + abstract int attack(String type); + abstract void printAttack(Character character); +} diff --git a/src/H071221104/Praktikum_7/no1/Fighter.java b/src/H071221104/Praktikum_7/no1/Fighter.java new file mode 100644 index 0000000..ec69a5d --- /dev/null +++ b/src/H071221104/Praktikum_7/no1/Fighter.java @@ -0,0 +1,31 @@ +public class Fighter extends Character{ + private int attackPower; + private String type; + + public String getType() { + return type; + } + public Fighter(int attackPower,String name, String type){ + super(name); + this.attackPower = attackPower; + this.type = type; + } + @Override + public int attack() { + return this.attackPower; + } + @Override + public int attack(String type){ + if(getType().equals("melee")){ + return this.attackPower*2; + } else if (getType().equals("ranged")){ + return this.attackPower; + } else { + return this.attackPower; + } + } + @Override + void printAttack(Character character) { + System.out.println(character.getName() + " attacked with power " + character.attack(getType())); + } +} diff --git a/src/H071221104/Praktikum_7/no1/Mage.java b/src/H071221104/Praktikum_7/no1/Mage.java new file mode 100644 index 0000000..5020448 --- /dev/null +++ b/src/H071221104/Praktikum_7/no1/Mage.java @@ -0,0 +1,34 @@ +public class Mage extends Character{ + private int attackPower; + private String type; + public String getType() { + return type; + } + + public Mage(int attackPower,String name, String type){ + super(name); + this.attackPower = attackPower; + this.type = type; + + } + + @Override + public int attack(){ + return this.attackPower; + } + @Override + public int attack(String type){ + if(getType().equals("frost")){ + return this.attackPower*2; + } else if (getType().equals("fire")){ + return this.attackPower*3; + } else { + return this.attackPower; + } + } + + @Override + void printAttack(Character character) { + System.out.println(character.getName() + " attacked with power " + character.attack(getType())); + } +} diff --git a/src/H071221104/Praktikum_7/no1/Main.java b/src/H071221104/Praktikum_7/no1/Main.java new file mode 100644 index 0000000..b73182e --- /dev/null +++ b/src/H071221104/Praktikum_7/no1/Main.java @@ -0,0 +1,20 @@ +public class Main{ + public static void main(String[] args) { + Character fighter1 = new Fighter(100, "Udin", "attack"); + Character fighter2 = new Fighter(100, "Salma", "melee"); + Fighter fighter3 = new Fighter(100, "Jamal", "ranged"); + Mage mage1 = new Mage(300, "Nabila", "frost"); + Mage mage2 = new Mage(300, "Vina", "fire"); + + Character[] characters = new Character[5]; + characters[0] = fighter1; + characters[1] = mage1; + characters[2] = fighter2; + characters[3] = fighter3; + characters[4] = mage2; + System.out.println("=".repeat(25)); + for (Character character : characters) { + character.printAttack(character); + } + } +} \ No newline at end of file diff --git a/src/H071221104/Praktikum_7/no2/Main.java b/src/H071221104/Praktikum_7/no2/Main.java new file mode 100644 index 0000000..b1cb861 --- /dev/null +++ b/src/H071221104/Praktikum_7/no2/Main.java @@ -0,0 +1,10 @@ +public class Main{ + public static void main(String[] args) { + Product productInteger = new Product<>(10000, "Kinder Joy", "2020-05-01"); + Product productString = new Product<>("Rp 15.000", "Sari Roti", "2023-05-20"); + Product productDouble = new Product<>(7.5, "Susu Kurma", "2023-06-01"); + System.out.println("Product 1: " +productInteger.getName() + " - "+ productInteger.getPrice() + " - " + productInteger.getExpiryDate()); + System.out.println("Product 2: " +productString.getName() + " - "+ productString.getPrice() + " - " + productString.getExpiryDate()); + System.out.println("Product 3: " +productDouble.getName() + " - "+ productDouble.getPrice() + " - " + productDouble.getExpiryDate()); + } +} diff --git a/src/H071221104/Praktikum_7/no2/Product.java b/src/H071221104/Praktikum_7/no2/Product.java new file mode 100644 index 0000000..e81081c --- /dev/null +++ b/src/H071221104/Praktikum_7/no2/Product.java @@ -0,0 +1,34 @@ +public class Product { + private T price; + private String name, expiryDate; + + public T getPrice() { + return price; + } + + public void setPrice(T price) { + this.price = price; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getExpiryDate() { + return expiryDate; + } + + public void setExpiryDate(String expiryDate) { + this.expiryDate = expiryDate; + } + + public Product(T price, String name, String expiryDate){ + this.name = name; + this.price = price; + this.expiryDate = expiryDate; + } +} \ No newline at end of file diff --git a/src/H071221104/Praktikum_7/no3/Burger.java b/src/H071221104/Praktikum_7/no3/Burger.java new file mode 100644 index 0000000..58a9b5a --- /dev/null +++ b/src/H071221104/Praktikum_7/no3/Burger.java @@ -0,0 +1,7 @@ +public class Burger implements Food{ + private int price =10; + @Override + public int getPrice() { + return price; + } +} diff --git a/src/H071221104/Praktikum_7/no3/Food.java b/src/H071221104/Praktikum_7/no3/Food.java new file mode 100644 index 0000000..514f1a6 --- /dev/null +++ b/src/H071221104/Praktikum_7/no3/Food.java @@ -0,0 +1,3 @@ +interface Food { + int getPrice(); +} diff --git a/src/H071221104/Praktikum_7/no3/FoodFactory.java b/src/H071221104/Praktikum_7/no3/FoodFactory.java new file mode 100644 index 0000000..5dfd4fe --- /dev/null +++ b/src/H071221104/Praktikum_7/no3/FoodFactory.java @@ -0,0 +1,14 @@ +public class FoodFactory{ + public static Food getFood(String type){ + switch (type) { + case "burger": + return new Burger(); + case "pizza": + return new Pizza(); + case "steak": + return new Steak(); + default: + return null; + } + } +} \ No newline at end of file diff --git a/src/H071221104/Praktikum_7/no3/Main.java b/src/H071221104/Praktikum_7/no3/Main.java new file mode 100644 index 0000000..510089e --- /dev/null +++ b/src/H071221104/Praktikum_7/no3/Main.java @@ -0,0 +1,20 @@ +import java.util.ArrayList; +import java.util.List; + +public class Main { + public static void main(String[] args) { + Food burger = FoodFactory.getFood("burger"); + Food pizza = FoodFactory.getFood("pizza"); + Food steak = FoodFactory.getFood("steak"); + + List foods = new ArrayList(); + foods.add(burger); + foods.add(pizza); + foods.add(steak); + + int total = Restaurant.calculateTotal(foods); + + System.out.println("Total : " + total ); + + } +} diff --git a/src/H071221104/Praktikum_7/no3/Pizza.java b/src/H071221104/Praktikum_7/no3/Pizza.java new file mode 100644 index 0000000..90e115b --- /dev/null +++ b/src/H071221104/Praktikum_7/no3/Pizza.java @@ -0,0 +1,7 @@ +public class Pizza implements Food{ + private int price = 15; + @Override + public int getPrice() { + return price; + } +} diff --git a/src/H071221104/Praktikum_7/no3/Restaurant.java b/src/H071221104/Praktikum_7/no3/Restaurant.java new file mode 100644 index 0000000..ff5b3c4 --- /dev/null +++ b/src/H071221104/Praktikum_7/no3/Restaurant.java @@ -0,0 +1,11 @@ +import java.util.List; + +public class Restaurant { + public static int calculateTotal(List foods) { + int total = 0; + for (Food food : foods) { + total += food.getPrice(); + } + return total; + } +} diff --git a/src/H071221104/Praktikum_7/no3/Steak.java b/src/H071221104/Praktikum_7/no3/Steak.java new file mode 100644 index 0000000..344e4dc --- /dev/null +++ b/src/H071221104/Praktikum_7/no3/Steak.java @@ -0,0 +1,7 @@ +public class Steak implements Food{ + private int price = 20; + @Override + public int getPrice() { + return price; + } +} diff --git a/src/H071221104/Praktikum_9/helloapp/.gitattributes b/src/H071221104/Praktikum_9/helloapp/.gitattributes new file mode 100644 index 0000000..097f9f9 --- /dev/null +++ b/src/H071221104/Praktikum_9/helloapp/.gitattributes @@ -0,0 +1,9 @@ +# +# https://help.github.com/articles/dealing-with-line-endings/ +# +# Linux start script should use lf +/gradlew text eol=lf + +# These are Windows script files and should use crlf +*.bat text eol=crlf + diff --git a/src/H071221104/Praktikum_9/helloapp/.gitignore b/src/H071221104/Praktikum_9/helloapp/.gitignore new file mode 100644 index 0000000..1b6985c --- /dev/null +++ b/src/H071221104/Praktikum_9/helloapp/.gitignore @@ -0,0 +1,5 @@ +# Ignore Gradle project-specific cache directory +.gradle + +# Ignore Gradle build output directory +build diff --git a/src/H071221104/Praktikum_9/helloapp/app/bin/main/style.css b/src/H071221104/Praktikum_9/helloapp/app/bin/main/style.css new file mode 100644 index 0000000..03e4245 --- /dev/null +++ b/src/H071221104/Praktikum_9/helloapp/app/bin/main/style.css @@ -0,0 +1,4 @@ +#code1 { + -fx-font-family: "Arial"; + -fx-font-size: 20px; +} \ No newline at end of file diff --git a/src/H071221104/Praktikum_9/helloapp/app/build.gradle b/src/H071221104/Praktikum_9/helloapp/app/build.gradle new file mode 100644 index 0000000..437e009 --- /dev/null +++ b/src/H071221104/Praktikum_9/helloapp/app/build.gradle @@ -0,0 +1,39 @@ +plugins { + id 'application' + id 'org.openjfx.javafxplugin' version '0.0.13' +} + +repositories { + // Use Maven Central for resolving dependencies. + mavenCentral() +} + +dependencies { + // Use JUnit Jupiter for testing. + testImplementation 'org.junit.jupiter:junit-jupiter:5.9.1' + + // This dependency is used by the application. + implementation 'com.google.guava:guava:31.1-jre' +} + +// Apply a specific Java toolchain to ease working on different environments. +java { + toolchain { + languageVersion = JavaLanguageVersion.of(17) + } +} + +javafx { + version = "17" + modules = [ 'javafx.controls' ] +} + +application { + // Define the main class for the application. + mainClass = 'helloapp.App' +} + +tasks.named('test') { + // Use JUnit Platform for unit tests. + useJUnitPlatform() +} diff --git a/src/H071221104/Praktikum_9/helloapp/app/src/main/java/helloapp/App.java b/src/H071221104/Praktikum_9/helloapp/app/src/main/java/helloapp/App.java new file mode 100644 index 0000000..75ed5af --- /dev/null +++ b/src/H071221104/Praktikum_9/helloapp/app/src/main/java/helloapp/App.java @@ -0,0 +1,21 @@ +package helloapp; + +import javafx.application.Application; +import javafx.scene.image.Image; +import javafx.stage.Stage; + +public class App extends Application { + @Override + public void start(Stage primaryStage) { + primaryStage.setResizable(false); + primaryStage.setTitle("Kalkulator Sederhana"); + primaryStage.getIcons().add(new Image("file:D:/Logo_PDI-P.svg.png")); + + HomeScene initScene = new HomeScene(primaryStage); + initScene.show(); + } + + public static void main(String[] args) { + launch(args); + } +} diff --git a/src/H071221104/Praktikum_9/helloapp/app/src/main/java/helloapp/Celcius.java b/src/H071221104/Praktikum_9/helloapp/app/src/main/java/helloapp/Celcius.java new file mode 100644 index 0000000..06e2310 --- /dev/null +++ b/src/H071221104/Praktikum_9/helloapp/app/src/main/java/helloapp/Celcius.java @@ -0,0 +1,80 @@ +package helloapp; + +import javafx.geometry.Insets; +import javafx.geometry.Pos; +import javafx.scene.Scene; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; +import javafx.scene.layout.GridPane; +import javafx.scene.layout.HBox; +import javafx.stage.Stage; + +public class Celcius { + private Stage stage; + + Celcius(Stage stage){ + this.stage = stage; + } + + public void show(){ + Label label1 = new Label("Celcius to Fahrenheit"); + label1.setStyle("-fx-font-family: Verdana; -fx-font-size: 20px; -fx-text-fill: white;"); + Label label2= new Label("Hasil"); + label2.setStyle("-fx-font-family: Verdana; -fx-font-size: 16px; -fx-text-fill: white;"); + Label label3= new Label(); + label3.setStyle("-fx-font-family: Verdana; -fx-font-size: 16px; -fx-text-fill: white;"); + + TextField textField1 = new TextField("input "); + textField1.setPrefWidth(100); + textField1.setPrefHeight(30); + + Button buttonClear = new Button("Clear"); + buttonClear.setOnAction(V ->{ + Celcius celcius = new Celcius(stage); + celcius.show(); + }); + buttonClear.setStyle("-fx-font-family: Tahoma; -fx-font-size: 16px; -fx-background-color: grey; -fx-text-fill: white;"); + buttonClear.setPrefWidth(100); + buttonClear.setPrefHeight(30); + Button buttonCalculate = new Button("Calculate"); + buttonCalculate.setOnAction(v -> { + int input1 = Integer.parseInt(textField1.getText()); + int hasil = (input1 * 9/5) + 32; + String hasilText = String.valueOf(hasil); + label3.setText(hasilText + " F"); + + }); + buttonCalculate.setStyle("-fx-font-family: Tahoma; -fx-font-size: 16px; -fx-background-color: gold; -fx-text-fill: white;"); + buttonCalculate.setPrefWidth(100); + buttonCalculate.setPrefHeight(30); + Button buttonBackHome = new Button("Back to Home"); + buttonBackHome.setOnAction(V ->{ + MenuScene menuScene = new MenuScene(stage); + menuScene.show(); + }); + buttonBackHome.setStyle("-fx-font-family: Tahoma; -fx-font-size: 16px; -fx-background-color: black; -fx-text-fill: white; -fx-border-color: white"); + buttonBackHome.setPrefWidth(200); + buttonBackHome.setPrefHeight(20); + HBox hBox = new HBox(); + hBox.getChildren().add(buttonClear); + hBox.getChildren().add(buttonCalculate); + + GridPane gridPane = new GridPane(); + gridPane.setPadding(new Insets(20)); + gridPane.setHgap(10); + gridPane.setVgap(10); + gridPane.add(label1, 1, 1); + gridPane.add(textField1,1,2); + gridPane.add(label2,1,4); + gridPane.add(label3,1,5); + gridPane.add(hBox, 1, 6); + gridPane.add(buttonBackHome,1,7); + gridPane.setAlignment(Pos.CENTER); + + Scene scene = new Scene(gridPane,350, 600); + gridPane.setStyle("-fx-background-color: darkblue;"); + stage.setScene(scene); + stage.show(); + } +} diff --git a/src/H071221104/Praktikum_9/helloapp/app/src/main/java/helloapp/Fahrenheit.java b/src/H071221104/Praktikum_9/helloapp/app/src/main/java/helloapp/Fahrenheit.java new file mode 100644 index 0000000..b3d1dec --- /dev/null +++ b/src/H071221104/Praktikum_9/helloapp/app/src/main/java/helloapp/Fahrenheit.java @@ -0,0 +1,84 @@ +package helloapp; + +import javafx.stage.Stage; +import javafx.geometry.Insets; +import javafx.geometry.Pos; +import javafx.scene.Scene; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; +import javafx.scene.layout.GridPane; +import javafx.scene.layout.HBox; + +public class Fahrenheit { + private Stage stage; + + Fahrenheit(Stage stage){ + this.stage = stage; + } + + public void show(){ + Label label1 = new Label("Fahrenheit to Celcius"); + label1.setStyle("-fx-font-family: Verdana; -fx-font-size: 20px; -fx-text-fill: white;"); + Label label2= new Label("Hasil"); + label2.setStyle("-fx-font-family: Verdana; -fx-font-size: 16px; -fx-text-fill: white;"); + Label label3= new Label(); + label3.setStyle("-fx-font-family: Verdana; -fx-font-size: 16px; -fx-text-fill: white;"); + + TextField textField1 = new TextField("input "); + textField1.setPrefWidth(100); + textField1.setPrefHeight(30); + + Button buttonClear = new Button("Clear"); + buttonClear.setOnAction(V ->{ + Fahrenheit fahrenheit = new Fahrenheit(stage); + fahrenheit.show(); + }); + buttonClear.setStyle("-fx-font-family: Tahoma; -fx-font-size: 16px; -fx-background-color: grey; -fx-text-fill: white;"); + buttonClear.setPrefWidth(100); + buttonClear.setPrefHeight(30); + Button buttonCalculate = new Button("Calculate"); + buttonCalculate.setOnAction(v -> { + try { + int input1 = Integer.parseInt(textField1.getText()); + int hasil = (input1 -32) * 5/9; + String hasilText = String.valueOf(hasil); + label3.setText(hasilText + " C"); + + } catch (Exception e) { + label3.setText("Hanya berupa angka"); + } + }); + buttonCalculate.setStyle("-fx-font-family: Tahoma; -fx-font-size: 16px; -fx-background-color: gold; -fx-text-fill: white;"); + buttonCalculate.setPrefWidth(100); + buttonCalculate.setPrefHeight(30); + Button buttonBackHome = new Button("Back to Home"); + buttonBackHome.setOnAction(V ->{ + MenuScene menuScene = new MenuScene(stage); + menuScene.show(); + }); + buttonBackHome.setStyle("-fx-font-family: Tahoma; -fx-font-size: 16px; -fx-background-color: black; -fx-text-fill: white; -fx-border-color: white"); + buttonBackHome.setPrefWidth(200); + buttonBackHome.setPrefHeight(20); + HBox hBox = new HBox(); + hBox.getChildren().add(buttonClear); + hBox.getChildren().add(buttonCalculate); + + GridPane gridPane = new GridPane(); + gridPane.setPadding(new Insets(20)); + gridPane.setHgap(10); + gridPane.setVgap(10); + gridPane.add(label1, 1, 1); + gridPane.add(textField1,1,2); + gridPane.add(label2,1,4); + gridPane.add(label3,1,5); + gridPane.add(hBox, 1, 6); + gridPane.add(buttonBackHome,1,7); + gridPane.setAlignment(Pos.CENTER); + + Scene scene = new Scene(gridPane,350, 600); + gridPane.setStyle("-fx-background-color: darkblue;"); + stage.setScene(scene); + stage.show(); + } +} diff --git a/src/H071221104/Praktikum_9/helloapp/app/src/main/java/helloapp/HomeScene.java b/src/H071221104/Praktikum_9/helloapp/app/src/main/java/helloapp/HomeScene.java new file mode 100644 index 0000000..c6c4f39 --- /dev/null +++ b/src/H071221104/Praktikum_9/helloapp/app/src/main/java/helloapp/HomeScene.java @@ -0,0 +1,60 @@ +package helloapp; + +import javafx.geometry.Insets; +import javafx.geometry.Pos; +import javafx.scene.Scene; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.scene.layout.GridPane; +import javafx.scene.layout.StackPane; +import javafx.scene.layout.VBox; +import javafx.stage.Stage; + +public class HomeScene { + private Stage stage; + + public HomeScene(Stage stage){ + this.stage = stage; + } + + public void show() { + Button buttonMulai = new Button("MULAI"); + buttonMulai.setOnAction(V -> { + MenuScene menuScene = new MenuScene(stage); + menuScene.show(); + }); + buttonMulai.setStyle("-fx-font-family: Arial; -fx-font-size: 16px; -fx-text-fill: white; -fx-background-color: gold"); + buttonMulai.setAlignment(Pos.CENTER); + buttonMulai.setPrefWidth(200); + buttonMulai.setPrefHeight(30); + Label label = new Label("Kalkulator Sederhana"); + label.setStyle("-fx-font-family: Arial; -fx-font-size: 20px; -fx-text-fill: white"); + + Image image = new Image("file:D:/Logo_PDI-P.svg.png"); + ImageView imageView = new ImageView(image); + imageView.setFitWidth(200); + imageView.setFitHeight(200); + + VBox vBox = new VBox(); + vBox.getChildren().add(imageView); + vBox.getChildren().add(label); + vBox.getChildren().add(buttonMulai); + vBox.setAlignment(Pos.CENTER); + + GridPane gridPane = new GridPane(); + gridPane.setPadding(new Insets(20)); + gridPane.setHgap(10); + gridPane.setVgap(10); + gridPane.add(imageView,1,1); + gridPane.add(label,1,3); + gridPane.add(buttonMulai,1,4); + gridPane.setAlignment(Pos.CENTER); + + Scene scene = new Scene(new StackPane(gridPane), 350, 600); + gridPane.setStyle("-fx-background-color: darkblue;"); + stage.setScene(scene); + stage.show(); + } +} diff --git a/src/H071221104/Praktikum_9/helloapp/app/src/main/java/helloapp/Kalkulator1.java b/src/H071221104/Praktikum_9/helloapp/app/src/main/java/helloapp/Kalkulator1.java new file mode 100644 index 0000000..969d076 --- /dev/null +++ b/src/H071221104/Praktikum_9/helloapp/app/src/main/java/helloapp/Kalkulator1.java @@ -0,0 +1,86 @@ +package helloapp; + +import javafx.geometry.Insets; +import javafx.geometry.Pos; +import javafx.scene.Scene; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; +import javafx.scene.layout.GridPane; +import javafx.scene.layout.HBox; +import javafx.stage.Stage; + +public class Kalkulator1 { + private Stage stage; + + Kalkulator1(Stage stage){ + this.stage = stage; + } + + public void show(){ + Label label1 = new Label("Kalkulator Pertambahan"); + label1.setStyle("-fx-font-family: Verdana; -fx-font-size: 20px; -fx-text-fill: white;"); + Label label2= new Label("Hasil"); + label2.setStyle("-fx-font-family: Verdana; -fx-font-size: 16px; -fx-text-fill: white;"); + Label label3= new Label(); + label3.setStyle("-fx-font-family: Verdana; -fx-font-size: 16px; -fx-text-fill: white;"); + + + TextField textField1 = new TextField("input 1"); + textField1.setStyle("-fx-background-radius: 5;"); + TextField textField2 = new TextField("input 2"); + textField2.setStyle("-fx-background-radius: 5;"); + + + + Button buttonClear = new Button("Clear"); + buttonClear.setOnAction(V ->{ + Kalkulator1 kalkulator1 = new Kalkulator1(stage); + kalkulator1.show(); + }); + buttonClear.setStyle("-fx-font-family: Tahoma; -fx-font-size: 16px; -fx-background-color: grey; -fx-text-fill: white;"); + buttonClear.setPrefWidth(125); + buttonClear.setPrefHeight(30); + Button buttonCalculate = new Button("Calculate"); + buttonCalculate.setOnAction(v -> { + int input1 = Integer.parseInt(textField1.getText()); + int input2 = Integer.parseInt(textField2.getText()); + int hasil = input1 * input2; + String hasilText = String.valueOf(hasil); + label3.setText(hasilText); + + }); + buttonCalculate.setStyle("-fx-font-family: Tahoma; -fx-font-size: 16px; -fx-background-color: gold; -fx-text-fill: white;"); + buttonCalculate.setPrefWidth(125); + buttonCalculate.setPrefHeight(30); + Button buttonBackHome = new Button("Back to Home"); + buttonBackHome.setOnAction(V ->{ + MenuScene menuScene = new MenuScene(stage); + menuScene.show(); + }); + buttonBackHome.setStyle("-fx-font-family: Tahoma; -fx-font-size: 16px; -fx-background-color: black; -fx-text-fill: white; -fx-border-color: white"); + buttonBackHome.setPrefWidth(250); + buttonBackHome.setPrefHeight(20); + HBox hBox = new HBox(); + hBox.getChildren().add(buttonClear); + hBox.getChildren().add(buttonCalculate); + + GridPane gridPane = new GridPane(); + gridPane.setPadding(new Insets(20)); + gridPane.setHgap(10); + gridPane.setVgap(10); + gridPane.add(label1, 1, 1); + gridPane.add(textField1,1,2); + gridPane.add(textField2, 1,3); + gridPane.add(label2,1,4); + gridPane.add(label3,1,5); + gridPane.add(hBox, 1, 6); + gridPane.add(buttonBackHome,1,7); + gridPane.setAlignment(Pos.CENTER); + + Scene scene = new Scene(gridPane,350, 600); + gridPane.setStyle("-fx-background-color: darkblue;"); + stage.setScene(scene); + stage.show(); + } +} diff --git a/src/H071221104/Praktikum_9/helloapp/app/src/main/java/helloapp/Kalkulator2.java b/src/H071221104/Praktikum_9/helloapp/app/src/main/java/helloapp/Kalkulator2.java new file mode 100644 index 0000000..4b47a59 --- /dev/null +++ b/src/H071221104/Praktikum_9/helloapp/app/src/main/java/helloapp/Kalkulator2.java @@ -0,0 +1,85 @@ +package helloapp; + + +import javafx.geometry.Insets; +import javafx.geometry.Pos; +import javafx.scene.Scene; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; +import javafx.scene.layout.GridPane; +import javafx.scene.layout.HBox; +import javafx.stage.Stage; + +public class Kalkulator2 { + private Stage stage; + + Kalkulator2(Stage stage){ + this.stage = stage; + } + + public void show(){ + Label label1 = new Label("Kalkulator Perkalian"); + label1.setStyle("-fx-font-family: Verdana; -fx-font-size: 20px; -fx-text-fill: white;"); + Label label2= new Label("Hasil"); + label2.setStyle("-fx-font-family: Verdana; -fx-font-size: 16px; -fx-text-fill: white;"); + Label label3= new Label(); + label3.setStyle("-fx-font-family: Verdana; -fx-font-size: 16px; -fx-text-fill: white;"); + + TextField textField1 = new TextField("input 1"); + textField1.setPrefWidth(100); + textField1.setPrefHeight(30); + TextField textField2 = new TextField("input 2"); + + + Button buttonClear = new Button("Clear"); + buttonClear.setOnAction(V ->{ + Kalkulator2 kalkulator2 = new Kalkulator2(stage); + kalkulator2.show(); + }); + buttonClear.setStyle("-fx-font-family: Tahoma; -fx-font-size: 16px; -fx-background-color: grey; -fx-text-fill: white;"); + buttonClear.setPrefWidth(100); + buttonClear.setPrefHeight(30); + Button buttonCalculate = new Button("Calculate"); + buttonCalculate.setOnAction(v -> { + int input1 = Integer.parseInt(textField1.getText()); + int input2 = Integer.parseInt(textField2.getText()); + int hasil = input1 * input2; + String hasilText = String.valueOf(hasil); + label3.setText(hasilText); + + }); + buttonCalculate.setStyle("-fx-font-family: Tahoma; -fx-font-size: 16px; -fx-background-color: gold; -fx-text-fill: white;"); + buttonCalculate.setPrefWidth(100); + buttonCalculate.setPrefHeight(30); + Button buttonBackHome = new Button("Back to Home"); + buttonBackHome.setOnAction(V ->{ + MenuScene menuScene = new MenuScene(stage); + menuScene.show(); + }); + buttonBackHome.setStyle("-fx-font-family: Tahoma; -fx-font-size: 16px; -fx-background-color: black; -fx-text-fill: white; -fx-border-color: white"); + buttonBackHome.setPrefWidth(200); + buttonBackHome.setPrefHeight(20); + HBox hBox = new HBox(); + hBox.getChildren().add(buttonClear); + hBox.getChildren().add(buttonCalculate); + + GridPane gridPane = new GridPane(); + gridPane.setPadding(new Insets(20)); + gridPane.setHgap(10); + gridPane.setVgap(10); + gridPane.add(label1, 1, 1); + gridPane.add(textField1,1,2); + gridPane.add(textField2, 1,3); + gridPane.add(label2,1,4); + gridPane.add(label3,1,5); + gridPane.add(hBox, 1, 6); + gridPane.add(buttonBackHome,1,7); + gridPane.setAlignment(Pos.CENTER); + + Scene scene = new Scene(gridPane,350, 600); + gridPane.setStyle("-fx-background-color: darkblue;"); + stage.setScene(scene); + stage.show(); + } +} diff --git a/src/H071221104/Praktikum_9/helloapp/app/src/main/java/helloapp/MenuScene.java b/src/H071221104/Praktikum_9/helloapp/app/src/main/java/helloapp/MenuScene.java new file mode 100644 index 0000000..972aa0a --- /dev/null +++ b/src/H071221104/Praktikum_9/helloapp/app/src/main/java/helloapp/MenuScene.java @@ -0,0 +1,81 @@ +package helloapp; + +import javafx.geometry.Insets; +import javafx.geometry.Pos; +import javafx.scene.Scene; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.layout.GridPane; +import javafx.stage.Stage; + +public class MenuScene { + private Stage stage; + + MenuScene(Stage stage){ + this.stage = stage; + } + + public void show(){ + Button buttonKalkulator1 = new Button("Kalkulator Pertambahan"); + buttonKalkulator1.setOnAction(V -> { + Kalkulator1 kalkulator1 = new Kalkulator1(stage); + kalkulator1.show(); + }); + buttonKalkulator1.setStyle("-fx-font-family: Arial; -fx-font-size: 16px; -fx-text-fill: black; -fx-background-color: grey;"); + + + Button buttonKalkulator2 = new Button("Kalkulator Perkalian"); + buttonKalkulator2.setOnAction(V -> { + Kalkulator2 kalkulator2 = new Kalkulator2(stage); + kalkulator2.show(); + + }); + buttonKalkulator2.setStyle("-fx-font-family: Arial; -fx-font-size: 16px; -fx-text-fill: black; -fx-background-color: grey;"); + + Button buttonCelcius = new Button("Celcius to Fahrenheit"); + buttonCelcius.setOnAction(V -> { + Celcius celcius = new Celcius(stage); + celcius.show(); + }); + buttonCelcius.setStyle("-fx-font-family: Arial; -fx-font-size: 16px; -fx-text-fill: black; -fx-background-color: grey;"); + + Button buttonFahrenheit = new Button("Fahrenheit to Celcius"); + buttonFahrenheit.setOnAction(V -> { + Fahrenheit fahrenheit = new Fahrenheit(stage); + fahrenheit.show(); + }); + buttonFahrenheit.setStyle("-fx-font-family: Arial; -fx-font-size: 16px; -fx-text-fill: black; -fx-background-color: grey;"); + + Button buttonBack = new Button("Back"); + buttonBack.setOnAction(V -> { + HomeScene homeScene = new HomeScene(stage); + homeScene.show(); + + }); + buttonBack.setStyle("-fx-font-family: Arial; -fx-font-size: 16px; -fx-text-fill: black; -fx-background-color: grey;"); + buttonBack.setAlignment(Pos.CENTER); + + Label label = new Label("PILIH MENU"); + label.setStyle("-fx-font-family: Arial; -fx-font-size: 16px; -fx-text-fill: white;"); + + GridPane gridPane = new GridPane(); + gridPane.setPadding(new Insets(20)); + gridPane.setHgap(10); + gridPane.setVgap(10); + gridPane.add(label,1,1); + gridPane.add(buttonKalkulator1,1,3); + gridPane.add(buttonKalkulator2,1,4); + gridPane.add(buttonCelcius,1,5); + gridPane.add(buttonFahrenheit,1,6); + gridPane.add(buttonBack,1,7); + gridPane.setAlignment(Pos.CENTER); + + + + Scene scene = new Scene(gridPane,350,600); + gridPane.setStyle("-fx-background-color: darkblue;"); + stage.setScene(scene); + stage.show(); + } + +} diff --git a/src/H071221104/Praktikum_9/helloapp/app/src/main/resources/style.css b/src/H071221104/Praktikum_9/helloapp/app/src/main/resources/style.css new file mode 100644 index 0000000..03e4245 --- /dev/null +++ b/src/H071221104/Praktikum_9/helloapp/app/src/main/resources/style.css @@ -0,0 +1,4 @@ +#code1 { + -fx-font-family: "Arial"; + -fx-font-size: 20px; +} \ No newline at end of file diff --git a/src/H071221104/Praktikum_9/helloapp/gradle/wrapper/gradle-wrapper.properties b/src/H071221104/Praktikum_9/helloapp/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..37aef8d --- /dev/null +++ b/src/H071221104/Praktikum_9/helloapp/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip +networkTimeout=10000 +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/src/H071221104/Praktikum_9/helloapp/gradlew b/src/H071221104/Praktikum_9/helloapp/gradlew new file mode 100644 index 0000000..aeb74cb --- /dev/null +++ b/src/H071221104/Praktikum_9/helloapp/gradlew @@ -0,0 +1,245 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/src/H071221104/Praktikum_9/helloapp/gradlew.bat b/src/H071221104/Praktikum_9/helloapp/gradlew.bat new file mode 100644 index 0000000..93e3f59 --- /dev/null +++ b/src/H071221104/Praktikum_9/helloapp/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/src/H071221104/Praktikum_9/helloapp/settings.gradle b/src/H071221104/Praktikum_9/helloapp/settings.gradle new file mode 100644 index 0000000..18dd0f6 --- /dev/null +++ b/src/H071221104/Praktikum_9/helloapp/settings.gradle @@ -0,0 +1,16 @@ +/* + * This file was generated by the Gradle 'init' task. + * + * The settings file is used to specify which projects to include in your build. + * + * Detailed information about configuring a multi-project build in Gradle can be found + * in the user manual at https://docs.gradle.org/8.1.1/userguide/multi_project_builds.html + */ + +plugins { + // Apply the foojay-resolver plugin to allow automatic download of JDKs + id 'org.gradle.toolchains.foojay-resolver-convention' version '0.4.0' +} + +rootProject.name = 'helloapp' +include('app')