diff --git a/src/H071221098/pertemuan_1/.vscode/settings.json b/src/H071221098/pertemuan_1/.vscode/settings.json new file mode 100644 index 0000000..c995aa5 --- /dev/null +++ b/src/H071221098/pertemuan_1/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.debug.settings.onBuildFailureProceed": true +} \ No newline at end of file diff --git a/src/H071221098/pertemuan_1/Assignment_1_1.java b/src/H071221098/pertemuan_1/Assignment_1_1.java new file mode 100644 index 0000000..69de2d1 --- /dev/null +++ b/src/H071221098/pertemuan_1/Assignment_1_1.java @@ -0,0 +1,28 @@ +package H071221098.pertemuan_1; +import java.util.Scanner; + +public class Assignment_1_1 { + public static void main(String[] args) { + String nim; + Scanner keyboard = new Scanner(System.in); //in untuk pengimputan karena yg di input pake int + System.out.print("Masukkan akhiran NIM: "); + nim = keyboard.nextLine(); //variabel keyboard untuk pengimputan , nextIn itu untuk kondisitipe data int + int urutan = Integer.parseInt(nim.substring(nim.length()-3)); + if (urutan % 7 == 0) { + System.out.println("Soal: no 7"); } else //if else kondisi + if (urutan % 7 == 1) { + System.out.println("Soal: no 1");} else + if (urutan % 7 == 2) { + System.out.println("Soal: no 2");} else + if (urutan % 7 == 3) { + System.out.println("Soal: no 3");} else + if (urutan % 7 == 4) { + System.out.println("Soal: no 4");} else + if (urutan % 7 == 5) { + System.out.println("Soal: no 5");} else + if (urutan % 7 == 6) { + System.out.println("Soal: no 6");} + keyboard.close(); //harus di close supaya tidak berjalan terus kode nya + } + +} \ No newline at end of file diff --git a/src/H071221098/pertemuan_1/Assignment_1_2.java b/src/H071221098/pertemuan_1/Assignment_1_2.java new file mode 100644 index 0000000..985f249 --- /dev/null +++ b/src/H071221098/pertemuan_1/Assignment_1_2.java @@ -0,0 +1,32 @@ +package H071221098.pertemuan_1; +import java.util.Scanner; + +public class Assignment_1_2 { + public static void main(String[] args) { + Scanner userInput = new Scanner(System.in) ; + int bilBulat,bilDesimal,n,i; + + bilBulat = 0; + bilDesimal = 0; + + try{ + System.out.println("Masukkan Jumlah Bilangan :"); + n = userInput.nextInt(); + userInput.nextLine(); + + for(i = 0; i < n; i++) { + double num = userInput.nextDouble(); //mencari nilai yang double / float klo di python + if (num % 1 == 0 ) { + bilBulat++; + } else { + bilDesimal++; + } + } + System.out.println(bilBulat + " Bilangan Bulat"); + System.out.println(bilDesimal + " Bilangan Desimal"); + userInput.close() ; + } catch (Exception e) { + System.out.println("Input Harus Berupa Angka"); + } + } +} \ No newline at end of file diff --git a/src/H071221098/pertemuan_1/Assignment_1_3.java b/src/H071221098/pertemuan_1/Assignment_1_3.java new file mode 100644 index 0000000..bb06849 --- /dev/null +++ b/src/H071221098/pertemuan_1/Assignment_1_3.java @@ -0,0 +1,25 @@ +package H071221098.pertemuan_1; +import java.util.Scanner; + +public class Assignment_1_3 { + public static void main(String[] args) { + Scanner input= new Scanner (System.in); + + try{ + System.out.println("Nama :"); + String name = input.nextLine(); + + System.out.println("Age :"); + int age = input.nextInt(); + input.nextLine(); //baris + + System.out.println("Hobby :"); + String hobby = input.nextLine(); + + System.out.println("Nama saya " + name + "," + age + " Tahun ,hobby " + hobby + "."); + } catch (Exception e) { + System.out.println("Umur harus berupa angka"); + }finally{input.close();} + + } +} diff --git a/src/H071221098/pertemuan_1/Assignment_1_4.java b/src/H071221098/pertemuan_1/Assignment_1_4.java new file mode 100644 index 0000000..ea82a7e --- /dev/null +++ b/src/H071221098/pertemuan_1/Assignment_1_4.java @@ -0,0 +1,18 @@ +package H071221098.pertemuan_1; +import java.util.Scanner; + +public class Assignment_1_4 { + public static void main(String[] args) { + Scanner inp = new Scanner(System.in); + System.out.print("Masukkan Judul Film : "); + String kalimat = inp.nextLine(); + String[] kata = kalimat.toLowerCase().split(" "); //split spasi setiap kalimat + String kalimatBaru = ""; + for (int i = 0; i < kata.length; i++) { + kalimatBaru += kata[i].substring(0, 1).toUpperCase() + kata[i].substring(1) + " " ; //"Spasi tiap kalimat" + } + System.out.println("Judul film setelah diubah : " + kalimatBaru); //tidak perlu trim + inp.close(); + } +} + diff --git a/src/H071221098/pertemuan_1/Assignment_1_5.java b/src/H071221098/pertemuan_1/Assignment_1_5.java new file mode 100644 index 0000000..06855b9 --- /dev/null +++ b/src/H071221098/pertemuan_1/Assignment_1_5.java @@ -0,0 +1,57 @@ +package H071221098.pertemuan_1; +import java.util.Scanner; + +public class Assignment_1_5 { + public static void main(String[] args) { + Scanner ip = new Scanner(System.in); + String a = ip.next(); + String hari = a.substring(0, 2); + System.out.print(Integer.parseInt(hari)); //untuk ubah 03 mnjdi 3 + String bulan = a.substring(3, 5); + int month = Integer.parseInt(bulan); //parseint untuk mengubah tipe data string ke integer + if (month == 1) { + System.out.print(" Januari "); + } + else if (month == 2) { + System.out.print(" Februari "); + } + else if (month == 3) { + System.out.print(" Maret "); + } + else if (month == 4) { + System.out.print(" April "); + } + else if (month == 5) { + System.out.print(" Mei "); + } + else if (month == 6) { + System.out.print(" Juni "); + } + else if (month == 7) { + System.out.print(" Juli "); + } + else if (month == 8) { + System.out.print(" Agustus "); + } + else if (month == 9) { + System.out.print(" September "); + } + else if (month == 10) { + System.out.print(" Oktober "); + } + else if (month == 11) { + System.out.print(" November "); + } + else if (month == 12) { + System.out.print(" Desember "); + } + String tahun = a.substring(6, 8); + int year = Integer.parseInt (tahun); + if (year <= 23) { + System.out.print("20" + tahun); + } + else { + System.out.print("19" + tahun); + } ip.close(); + } +} \ No newline at end of file diff --git a/src/H071221098/pertemuan_1/Assignment_1_6.java b/src/H071221098/pertemuan_1/Assignment_1_6.java new file mode 100644 index 0000000..8b4c28f --- /dev/null +++ b/src/H071221098/pertemuan_1/Assignment_1_6.java @@ -0,0 +1,24 @@ +package H071221098.pertemuan_1; +import java.util.Scanner; + +public class Assignment_1_6 { + public static void main(String[] args) { + Scanner input = new Scanner (System.in); + + try{ + System.out.println("Menghitung Luas Lingkaran "); + System.out.println("Masukkan Jari-jari Lingkaran"); + double r = input.nextDouble(); // supaya bisa input bilangan desimal + + String luas = String.format ("%.2f" , (Math.PI * r *r)) ; //angka blkg koma 2 + + System.out.println("Luas Lingkaran = " + luas); + + } catch (Exception e) { + System.out.println("Input Harus Berupa Angka"); + + } + input.close(); + } + +} diff --git a/src/H071221098/pertemuan_1/Assignment_1_7.java b/src/H071221098/pertemuan_1/Assignment_1_7.java new file mode 100644 index 0000000..04223c0 --- /dev/null +++ b/src/H071221098/pertemuan_1/Assignment_1_7.java @@ -0,0 +1,22 @@ +package H071221098.pertemuan_1; +import java.util.Scanner; + +public class Assignment_1_7 { + public static void main(String[] args) { + String [] namaKota = {"Makassar" , "Jakarta" , "Medan" , "Manado" , "Surabaya"} ; + Scanner input = new Scanner (System.in) ; + System.out.println("Masukkan nama kota yang dicari :"); + String cari = input.nextLine() ; + input.close() ; + + System.out.println(findIndex(namaKota, cari)); //untuk mencaari indeks kota yg ingin dicari + } + public static int findIndex (String[] array, String teks) { + for (int i = 0; i < array.length; i++) { + if (array[i].equalsIgnoreCase(teks)) { // method ini digunakan untuk membandingkan dua strings secara leksikal dengan mengabaikan case sensitive + return i ; + } + } + return -1 ; + } +} diff --git a/src/H071221098/pertemuan_1/Assignment_1_8.java b/src/H071221098/pertemuan_1/Assignment_1_8.java new file mode 100644 index 0000000..03b6646 --- /dev/null +++ b/src/H071221098/pertemuan_1/Assignment_1_8.java @@ -0,0 +1,34 @@ +package H071221098.pertemuan_1; +import java.util.Scanner; + +public class Assignment_1_8 { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + // Input satu bilangan + try { + System.out.print("Masukkan satu bilangan : "); + int bilangan = scanner.nextInt(); + + + int[][] array2D = {{1,2,3}, {4,5,6}, {7,8,9}}; //list dalam list + boolean found = false; + + for (int i = 0; i < array2D.length; i++) { //perulangan dalam perulangan + for (int j = 0; j < array2D[i].length; j++) { + if (array2D[i][j] == bilangan) { + System.out.println("Bilangan " + bilangan + " ditemukan pada indeks [" + i + "][" + j + "]"); + found = true; + } + } + } + if (!found) { + System.out.println("Bilangan " + bilangan + " tidak ditemukan pada array 2D"); + } + } catch (Exception e) { + System.out.println("Inputan harus berupa angka"); + + } + scanner.close(); + } + } \ No newline at end of file diff --git a/src/H071221098/pertemuan_2/Assignment_2_1.java b/src/H071221098/pertemuan_2/Assignment_2_1.java new file mode 100644 index 0000000..fa334f3 --- /dev/null +++ b/src/H071221098/pertemuan_2/Assignment_2_1.java @@ -0,0 +1,44 @@ +package H071221098.pertemuan_2; +class Makassar { + String wisata ; //atribut + String makanan ; + String musik ; + + void setWisata (String wisata) { + this.wisata = wisata; + } + void setMakanan (String makanan) { + this.makanan = makanan; + + } + void setMusik (String musik) { + this.musik = musik; + + + } + + String getWisata () { //method + return wisata; + } + String getMakanan () { + return makanan; + } + String getMusik () { + return musik; + } + +} + +public class Assignment_2_1 { + public static void main(String[] args) { //main nya + Makassar ip = new Makassar (); + ip.setWisata("Pantai Losari"); + ip.setMakanan("Coto Makassar") ; + ip.setMusik("Gandrang Bulo"); + + System.out.println("Tempat Wisata: " + ip.getWisata()); + System.out.println("Makanan Khas: " + ip.getMakanan()); + System.out.println("Alat Musik Tradisional: " + ip.getMusik()); + + } +} \ No newline at end of file diff --git a/src/H071221098/pertemuan_2/Assignment_2_2.java b/src/H071221098/pertemuan_2/Assignment_2_2.java new file mode 100644 index 0000000..bbc5c02 --- /dev/null +++ b/src/H071221098/pertemuan_2/Assignment_2_2.java @@ -0,0 +1,45 @@ +package H071221098.pertemuan_2; +class Person { + public String name; //atribut + public int age; + public boolean isMale; + + public void setName (String name){ //memthodd set name digunakan untuk mengatur nilai dari atribut name + this.name = name; + } + public String getName () { //untuk mendapatkan nilai dari atribut name + return name; + } + public void setAge (int age) { //method setage digunakan untuk mengatur nilai dari atribut age + this.age = age; + } + public int getAge () { //untuk mendapatkan nilai dari atribut age + return age; + } + public void setGender (String gender) { //digunakan u/mengatur jenis kelamin dengan menerima parameter sebuah string gender + this.isMale = gender == "male"; //mengubah nilai ismale menjadi true jika gender sm dengan male san false jika tidak + } + public String getGender (){ //mendapatkan nilai jenis kelamin dalam bentung string dengan memeriksa nilai atribut isMale + if (isMale) { + return "male"; + } + else { + return "female"; + } + + } +} + +public class Assignment_2_2{ + public static void main(String[] args) { + Person orang = new Person (); + orang.setName("Ojan"); + orang.setAge(19); + orang.setGender("male"); + + System.out.println("Nama: " + orang.getName()); + System.out.println("Umur: " + orang.getAge()); + System.out.println("Jenis kelamin: " + orang.getGender()); + } +} + diff --git a/src/H071221098/pertemuan_2/Assignment_2_3.java b/src/H071221098/pertemuan_2/Assignment_2_3.java new file mode 100644 index 0000000..47f6bc4 --- /dev/null +++ b/src/H071221098/pertemuan_2/Assignment_2_3.java @@ -0,0 +1,72 @@ +package H071221098.pertemuan_2; +class Produk{ + String id; //ini atribut + String nama; + int stok; + int harga; + + + public boolean isAvailable(){ + if (stok > 0) { + return true; + + } + return false; + } + + + public void displayProduk() { + System.out.println("Nama produk : " + nama); + System.out.println("ID Produk : " + id); + System.out.println("Stok produk : " + stok); + System.out.println("Harga produk : " + harga); + if (isAvailable()){ + System.out.println ("Produk Tersedia"); + + } + else{ + System.out.println ("produk tidak tersedia"); + } + } + + + public String getId(){ + return id; + } + public String getNama(){ + return nama; + } + public int getStok(){ + return stok; + } + public int getHarga(){ + return harga; + } + } + + public class Assignment_2_3{ + public static void main(String[] args) { + Produk produk1 = new Produk(); + Produk produk2 = new Produk(); + + produk1.id = "H0001"; + produk1.nama = "Baju kaos"; + produk1.stok = 1; + produk1.harga = 50000; + + produk1.stok = produk1.getStok() - 1; + + produk2.id = "H0002"; + produk2.nama = "Celana pendek"; + produk2.stok = 12; + produk2.harga = 35000; + + produk1.displayProduk(); + produk1.isAvailable(); //untuk pemanggilan + System.out.println(""); + produk2.displayProduk(); + produk2.isAvailable(); + + + } + } \ No newline at end of file diff --git a/src/H071221098/pertemuan_2/Assignment_2_4.java b/src/H071221098/pertemuan_2/Assignment_2_4.java new file mode 100644 index 0000000..6c578a1 --- /dev/null +++ b/src/H071221098/pertemuan_2/Assignment_2_4.java @@ -0,0 +1,21 @@ +package H071221098.pertemuan_2; + +class Cuboid { + double height; + double width; + double length; + + double getVolume(){ //untuk menghitung dan mengembalikan nilai volume dari cuuboid. + return height*width*length; + } +} + +public class Assignment_2_4{ + public static void main(String[] args) { + Cuboid cuboid = new Cuboid(); + cuboid.height = 12; + cuboid.width = 25; + cuboid.length = 15; + System.out.printf("Volume: %.2f", cuboid.getVolume()); + } +} \ No newline at end of file diff --git a/src/H071221098/pertemuan_2/Assignment_2_5.java b/src/H071221098/pertemuan_2/Assignment_2_5.java new file mode 100644 index 0000000..97de43c --- /dev/null +++ b/src/H071221098/pertemuan_2/Assignment_2_5.java @@ -0,0 +1,46 @@ +package H071221098.pertemuan_2; + +class Mahasiswa{ + String nama; + String nim; + Alamat alamat; //Alamat ini punya atribut sendiri utk dpt alamatLengkap + + public String getNama(){ + return nama; + } + + public String getNim(){ + return nim; + } + + public Alamat getAlamat(){ + return alamat; + } +} + +class Alamat{ + String jalan; + String kota; + + public String getAlamatLengkap(){ + return jalan + ", " + kota; + } +} + +public class Assignment_2_5 { + public static void main(String[] args) { + Alamat alamat = new Alamat(); + alamat.jalan = "Perintis Kemerdekaan 12"; + alamat.kota = "Makassar"; + + Mahasiswa mahasiswa = new Mahasiswa(); + mahasiswa.alamat = alamat; + mahasiswa.nama = "Fauzan"; + mahasiswa.nim = "H071221098"; + + System.out.println("Nama : "+ mahasiswa.getNama()); + System.out.println("NIM : "+ mahasiswa.getNim()); + Alamat alamat2 = mahasiswa.getAlamat(); + System.out.println("Alamat : "+ alamat2.getAlamatLengkap()); + } +} \ No newline at end of file diff --git a/src/H071221098/pertemuan_3/Assignment_3_1.java b/src/H071221098/pertemuan_3/Assignment_3_1.java new file mode 100644 index 0000000..6326009 --- /dev/null +++ b/src/H071221098/pertemuan_3/Assignment_3_1.java @@ -0,0 +1,75 @@ +package H071221098.pertemuan_3; +class Benelli{ + //atribut + String Jenis; + String Warna; + int Harga; + Person pemilik; + // //public supaya dapat diakses dari class lain + // public Benelli (){} + + + //constructor + + public Benelli (String Jenis, String Warna, int Harga, Person pemilik){ + this.Jenis = Jenis; + this.Warna = Warna; + this.Harga = Harga; + this.pemilik = pemilik; + } + + public Benelli (String Jenis, String Warna, Person pemilik){ + this.Jenis = Jenis; + this.Warna = Warna; + this.Harga =0; + this.pemilik= pemilik; + } + +//get set method +String getJenisString(){ + return Jenis; +} + +int getharga(){ + return Harga; +} + +String getwarna(){ + return Warna; +} + +public void setharga(int Harga ){ + this.Harga = Harga ; +} + + + //behavior +public void tampilkanDetail(){ + System.out.println("Jenis produk : " + Jenis ); + System.out.println("Warna produk : " + Warna); + System.out.println("Harga produk : " + Harga); + System.out.println("Nama pemilik: " + pemilik.nama); +} + + + public void harga () { + if (this.Harga >= 32500000) { + System.out.println(" Benelli Patagonian Eagle"); + } else if (this.Harga < 325000000) { + System.out.println("Benelli 152 "); + } else { + System.out.println("Benelli Evo 200"); + } + +}} + + +public class Assignment_3_1 { + public static void main(String[] args) { + Person person = new Person ("Fauzan", "Laki-Laki", 19); + Benelli Benelli = new Benelli("Patagonian eagle", "Hitam", 49000000, person); + Benelli.tampilkanDetail(); + Benelli.harga(); + } +} + diff --git a/src/H071221098/pertemuan_3/Assignment_3_2.java b/src/H071221098/pertemuan_3/Assignment_3_2.java new file mode 100644 index 0000000..a76fa78 --- /dev/null +++ b/src/H071221098/pertemuan_3/Assignment_3_2.java @@ -0,0 +1,55 @@ +package H071221098.pertemuan_3; +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); //absolute + } + + // Lengkapi + + public Player (String name,int attackPower,int defense){ + this.name = name; + this.hp = 100; + this.attackPower = attackPower; + this.defense = defense; + } + + public Player (String name,int defense){ + this.name = name; + this.hp = 100; + this.defense = defense; + } + + 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 Assignment_3_2 { + 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/H071221098/pertemuan_3/Assignment_3_3.java b/src/H071221098/pertemuan_3/Assignment_3_3.java new file mode 100644 index 0000000..4620a9f --- /dev/null +++ b/src/H071221098/pertemuan_3/Assignment_3_3.java @@ -0,0 +1,151 @@ + +package H071221098.pertemuan_3; +import java.util.ArrayList; +import java.util.Scanner; + +class User { + private String name; + private int balance; + + public User(String name, int balance){ + this.name = name; + this.balance = balance; + } + public void setName(String name) { + this.name = name; + } + public String getName() { + return name; + } + public int getBalance() { + return balance; + } + public void reduceBalance(int balance) { + this.balance = this.balance - balance; + } + public void userCard(){ + System.out.println("-----card-----"); + System.out.println(this.getName()); + System.out.println(this.getBalance()); + System.out.println("--------------"); + } +} + +class Product { + private String name; + private int price; + private int stock; + + public Product(String name, int price, int stock) { + this.name = name; + this.price = price; + this.stock = stock; + } + public Product(String name, String price, int stock) { + this.name = name; + this.stock = stock; + + if (price.contains("k")) { + price = price.replace("k", ""); //mengganti k menjadi string kosong + this.price = Integer.parseInt(price) * 1000; //harga di x 1000 + } else { + this.price = Integer.parseInt(price); + } + } + public void setName(String name) { + this.name = name; + } + public String getName() { + return name; + } + public int getPrice() { + return price; + } + public int getStock() { + return stock; + } + public void sell() { + stock--; + } +} +class Store { + public String name; + public ArrayList products; + + public Store(String name, ArrayList product){ + this.name = name; + this.products = product; + } + + //behavior + public void addProduct(Product product) { + products.add(product); + } + //thiss + public void listProducts() { + System.out.printf("Selamat Datang di %s%n", this.name); + System.out.println("Daftar Produk :"); + for (int i = 0; i < products.size(); i++) { + Product product = products.get(i); + System.out.println((i + 1) + ". " + product.getName() + " - Rp." + product.getPrice() + " | stok " + product.getStock()); + } + } + public void buyProduct(User user, int productIndex) { + Product product = products.get(productIndex); + if (user.getBalance() >= product.getPrice()) { + user.reduceBalance(product.getPrice()); + product.sell(); + + if (product.getStock() == 0) { + products.remove(productIndex); + } + System.out.println(user.getName() + " berhasil membeli " + product.getName()); + } else { + System.out.println("Maaf, saldo tidak cukup untuk membeli produk ini."); + } + } +} +public class Assignment_3_3 { + public static void main(String[] args) { + // Inisialisasi data user + User user = new User("Ojan", 50000); + // Inisialisasi data store + ArrayList product = new ArrayList<>(); + product.add(new Product("Nasi Campur Ayam", "15k", 3)); + product.add(new Product("Salad Buah", "12k", 2)); + product.add(new Product("Es Teh", 5000, 5)); + + Store toko = new Store("Kudapan", product); + + // Objek Scanner untuk input dari user + Scanner input = new Scanner(System.in); + + // Looping untuk melakukan transaksi pembelian produk + while (true) { + user.userCard(); + toko.listProducts(); + System.out.println("0. Keluar"); + System.out.print("> "); + int pilihan = input.nextInt(); + + // Kode untuk membeli produk + if (pilihan >= 1 && pilihan <= toko.products.size()) { + while (true) { + // Konfirmasi pembelian + System.out.println("Apakah anda yakin ingin membeli?"); + System.out.println("1. Konfirmasi"); + System.out.println("2. Batal"); + System.out.print("> "); + int konfirmasi = input.nextInt(); + if (konfirmasi == 1 ){ + toko.buyProduct(user, pilihan-1); + break; + } else { + break; + } + } + } else {break;} + } + input.close(); + } +} diff --git a/src/H071221098/pertemuan_3/Person.java b/src/H071221098/pertemuan_3/Person.java new file mode 100644 index 0000000..b4a7848 --- /dev/null +++ b/src/H071221098/pertemuan_3/Person.java @@ -0,0 +1,12 @@ +package H071221098.pertemuan_3; +public class Person { + public String nama; + public int umur; + public String gender; + + public Person (String nama, String gender, int umur){ + this.nama = nama; + this.gender = gender; + this.umur = umur; + } +} diff --git a/src/H071221098/pertemuan_4/Main.java b/src/H071221098/pertemuan_4/Main.java new file mode 100644 index 0000000..5939000 --- /dev/null +++ b/src/H071221098/pertemuan_4/Main.java @@ -0,0 +1,178 @@ +package H071221098.pertemuan_4; + +import java.util.ArrayList; +import java.util.Scanner; + +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 (listUser.get(i).getUsername().equals(username)){ //untuk membandingkan nilai us tersebut dengan nilain us yg diberikan + 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(); + + /* + * 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 + boolean isPasswordMatch = listUser.get(userIndex).getPassword().equals(password); + if (isPasswordMatch) { + System.out.println("Berhasil Login"); + Main.showDetailUser(listUserProfile.get(userIndex)); + /* + * TODO + * panggil method showDetailUser dan kirimkan data Profile User yang login + * + */ + showDetailUser(listUserProfile.get(userIndex)); + 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(); + 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.setNickName(StringUtils.generateNickname(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) { + /* + * TODO * + * Tampilkan semua data profile user yang login + */ + System.out.println("-------------------------"); + System.out.println("SELAMAT DATANG!!"); + System.out.println("-------------------------"); + System.out.println("Nama Lengkap: " + profile.getFullName()); + System.out.println("Nama Panggilan: " + profile.getNickName()); + System.out.println("Umur: " + profile.getAge()); + System.out.println("Hobby: " + profile.GetHobby()); + } + +} diff --git a/src/H071221098/pertemuan_4/MainFood.java b/src/H071221098/pertemuan_4/MainFood.java new file mode 100644 index 0000000..35bdc6c --- /dev/null +++ b/src/H071221098/pertemuan_4/MainFood.java @@ -0,0 +1,21 @@ +package product; + +public class MainFood { + public static void main(String[] args) { + Food food1 = new Food(); + food1.setName("Nasi Goreng"); + food1.setType("Makanan Berat"); + food1.setPrice(20000); + food1.setRating (10) ; + food1.displayInfo(); + + Food food2 = new Food("kentang", "ringan", 10000, 10); + System.out.println(food2.getName()); + System.out.println(food2.getType()); + System.out.println(food2.getPrice()); + System.out.println(food2.getRating()); + + SelfUtils.displaySelfData(); + } + +} diff --git a/src/H071221098/pertemuan_4/Profile.java b/src/H071221098/pertemuan_4/Profile.java new file mode 100644 index 0000000..89bb58e --- /dev/null +++ b/src/H071221098/pertemuan_4/Profile.java @@ -0,0 +1,43 @@ +package H071221098.pertemuan_4; +public class Profile { + private String fullName; + private int age; + private String hobby; + private String nickName; + + public Profile(String fullName, int age, String hobby, String nickName) { + this.fullName = fullName; + this.age = age; + this.hobby = hobby; + this.nickName = nickName; + } + public Profile() {} + + public String getFullName() { + return fullName; + } + public void setFullName(String fullName) { + this.fullName = fullName; + } + public int getAge() { + return age; + } + public void setAge(int age) { + this.age = age; + } + public String GetHobby(){ + return hobby; + } + public void setHobby(String hobby){ + this.hobby = hobby; + } + + public String getNickName(){ + return nickName; + } + + public void setNickName (String nickName){ + this.nickName = nickName; + } + +} diff --git a/src/H071221098/pertemuan_4/StringUtils.java b/src/H071221098/pertemuan_4/StringUtils.java new file mode 100644 index 0000000..41e2327 --- /dev/null +++ b/src/H071221098/pertemuan_4/StringUtils.java @@ -0,0 +1,25 @@ +package H071221098.pertemuan_4; +public class StringUtils { + public static String generateNickname(String fullName){ //generateNickname digunakan untuk mengambil nama panggilan dari sebuah nama lengkap + String[] nameParts = fullName.split(" "); //memecah fullname menjadi beberapa bagian menggunakan split dan memasukkannya ke dalam array nameparts + + if (nameParts.length ==1) { //memeriksa apakah hanya memiliki satu elemen + return fullName; //jika iya maka fullName tersebut sudah merupakan sebuah nickname sehingga method akan mengembalikan fullName + }else{ + return nameParts[1]; //jika tidak, maka method akan mengambil elemen kedua dari nameParts (indeks 1) yang seharusnya merupakan nama belakang, lalu mengembalikannya sebagai nickname. + } + } + + /* + 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) + */ +} + diff --git a/src/H071221098/pertemuan_4/User.java b/src/H071221098/pertemuan_4/User.java new file mode 100644 index 0000000..c2eeee8 --- /dev/null +++ b/src/H071221098/pertemuan_4/User.java @@ -0,0 +1,28 @@ +package H071221098.pertemuan_4; +public class User { + private String username; + private String password; + /* + * TODO: + * Tambahkan attribute, method, atau constructor + * yang dibutuhkan di kelas user + */ + + public User(String username, String password){ + this.username = username; + this.password = password; + } + + public String getUsername() { + return username; + } + public void setUsername(String username) { + this.username = username; + } + public String getPassword() { + return password; + } + public void setPassword(String password) { + this.password = password; + } +} diff --git a/src/H071221098/pertemuan_4/product/Food.java b/src/H071221098/pertemuan_4/product/Food.java new file mode 100644 index 0000000..c7461b6 --- /dev/null +++ b/src/H071221098/pertemuan_4/product/Food.java @@ -0,0 +1,47 @@ +package H071221098.pertemuan_4.product; +public class Food{ + public Food(){} + public Food(String name, String type, int price, int rating){ + this.name = name; + this.type = type; + this.price = price; + this.rating = rating; + } + private String name; + private String type; + private int price; + private int rating; + + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + public int getPrice() { + return price; + } + public void setPrice(int price) { + this.price = price; + } + public int getRating() { + return rating; + } + public void setRating(int rating) { + this.rating = rating; + } + + public void displayInfo(){ + System.out.println(name); + System.out.println(type); + System.out.println(price); + System.out.println(rating); + +} +} \ No newline at end of file diff --git a/src/H071221098/pertemuan_4/product/MainFood.java b/src/H071221098/pertemuan_4/product/MainFood.java new file mode 100644 index 0000000..14da83f --- /dev/null +++ b/src/H071221098/pertemuan_4/product/MainFood.java @@ -0,0 +1,21 @@ +package H071221098.pertemuan_4.product; + +public class MainFood { + public static void main(String[] args) { + Food food1 = new Food(); + food1.setName("Nasi Goreng"); + food1.setType("Makanan Berat"); + food1.setPrice(20000); + food1.setRating (10) ; + food1.displayInfo(); + + Food food2 = new Food("kentang", "ringan", 10000, 10); + System.out.println(food2.getName()); + System.out.println(food2.getType()); + System.out.println(food2.getPrice()); + System.out.println(food2.getRating()); + + SelfUtils.displaySelfData(); + } + +} diff --git a/src/H071221098/pertemuan_4/product/SelfUtils.java b/src/H071221098/pertemuan_4/product/SelfUtils.java new file mode 100644 index 0000000..2fcbe95 --- /dev/null +++ b/src/H071221098/pertemuan_4/product/SelfUtils.java @@ -0,0 +1,8 @@ +package H071221098.pertemuan_4.product; + +public class SelfUtils { + public static void displaySelfData (){ + System.out.println("Muhammad Fauzan Bachtiar"); + System.out.println("pria"); +} +} \ No newline at end of file diff --git a/src/H071221098/pertemuan_5/Anggota.java b/src/H071221098/pertemuan_5/Anggota.java new file mode 100644 index 0000000..ddeb08e --- /dev/null +++ b/src/H071221098/pertemuan_5/Anggota.java @@ -0,0 +1,69 @@ +package H071221098.pertemuan_5; +public class Anggota { + private String nama; + private int umur; + private String gender; + + public Anggota (String nama, int umur, String gender){ + this.nama = nama ; + this.umur = umur; + this.gender = gender; + } + public String getName() { + return nama; + } + + public void setName(String nama) { + this.nama = nama; + } + + public int getAge() { + return umur; + } + + public void setAge(int umur) { + this.umur = umur; + } + + public String getGender() { + return gender; + } + + public void setGender(String gender) { + this.gender = gender; + } +} + +class PengurusInti extends Anggota{ + private String jabatan; + + public PengurusInti(String nama, int umur, String gender, String jabatan){ + super(nama, umur, gender); + this.jabatan = jabatan; + } + public String getJabatan() { + return jabatan; + } + + public void setJabatan(String jabatan) { + this.jabatan = jabatan; + } +} + +class KordinatorBidangStaff extends Anggota{ + private String bidang; + + public KordinatorBidangStaff(String nama, int umur, String gender, String bidang){ + super(nama, umur, gender); + this.bidang = bidang; + } + public String getBidang() { + return bidang; + } + + public void setBidang(String bidang) { + this.bidang = bidang; + } +} + + diff --git a/src/H071221098/pertemuan_5/Bangun.java b/src/H071221098/pertemuan_5/Bangun.java new file mode 100644 index 0000000..a6bcff1 --- /dev/null +++ b/src/H071221098/pertemuan_5/Bangun.java @@ -0,0 +1,101 @@ +package H071221098.pertemuan_5; +public class Bangun { +} +class Kubus extends Bangun { + int sisi; + int getvolumekubus() { + return sisi*sisi*sisi; + } + int getluasPermukaankubus() { + return 6*(sisi*sisi); + } +} +class Balok extends Bangun { + int panjang; + int lebar; + int tinggi; + + int getvolumebalok() { + return panjang*lebar*tinggi; + } + int getluasPermukaanbalok() { + return 2*((panjang*lebar)+(panjang*tinggi)+(lebar*tinggi)); + } +} +class Bola extends Bangun { + int jari; + double getvolumebola() { + return 4*Math.PI*(jari*jari); + } + double getluasPermukaanbola() { + return (4/3)*Math.PI*(jari*jari*jari); + } +} +class Tabung extends Bangun { + int jari; + int tinggi; + + double getvolumetabung() { + return Math.PI*(jari*jari)*tinggi; + } + double getluasPermukaantabung() { + return (2*Math.PI*jari*tinggi) + (2*Math.PI*(jari*jari)); + } +} +class Persegi extends Bangun { + int sisi; + + int getluasgpersegi() { + return sisi*sisi; + } + int getkelilingpersegi() { + return 4*sisi; + } +} +class persegiPanjang extends Bangun { + int panjang; + int lebar; + + int getluaspersegiPanjang() { + return panjang*lebar; + } + int getkelilingpersegiPanjang() { + return 2*(panjang+lebar); + } +} +class Lingkaran extends Bangun { + int jari; + + double getluaslingkaran() { + return Math.PI*(jari*jari); + } + double getkelilinglingkaran() { + return 2*Math.PI*jari; + } +} +class Segitiga extends Bangun { + int alas; + int tinggi; + int sisi; + + int getluassegitiga() { + return 1/2*(alas*tinggi); + } + int getkelilingsegitiga() { + return 3*sisi; + } +} +class Trapesium extends Bangun { + int alas1; + int alas2; + int tinggi; + int rusuk1; + int rusuk2; + + int getluastrapesium() { + return 1/2*(alas1+alas2)*tinggi; + } + int getkelilingtrapesium() { + return rusuk1+rusuk2+alas1+alas2; + } +} diff --git a/src/H071221098/pertemuan_5/Main.java b/src/H071221098/pertemuan_5/Main.java new file mode 100644 index 0000000..6b1a992 --- /dev/null +++ b/src/H071221098/pertemuan_5/Main.java @@ -0,0 +1,139 @@ +package H071221098.pertemuan_5; +import java.util.Scanner; + +public class Main { + + public static void main(String[] args) { + int pilihan = 0; + Scanner inp = new Scanner(System.in); + + 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.println(); + System.out.println("==== BANGUN DATAR ====="); + System.out.println("5. PERSEGI"); + System.out.println("6. PERSEGI PANJANG"); + System.out.println("7. LINGKARAN"); + System.out.println("8. SEGITIGA"); + System.out.println("9. TRAPESIUM"); + System.out.println(); + System.out.println("10. Keluar"); + System.out.print("Silahkan masukkan pilihan : "); + pilihan = inp.nextInt(); + while (pilihan != 10) { + if (pilihan == 1) { + Scanner input = new Scanner(System.in); + Kubus a = new Kubus(); + System.out.print("Masukkan panjang sisi kubus : "); + a.sisi = input.nextInt(); + System.out.println("Volume kubus : " + a.getvolumekubus()); + System.out.println("Luas Permukaan kubus : " + a.getluasPermukaankubus()); + input.close(); + } + else if (pilihan == 2) { + Scanner input = new Scanner(System.in); + Balok a = new Balok(); + System.out.print("Masukkan panjang balok : "); + a.panjang = input.nextInt(); + System.out.print("Masukkan lebar balok : "); + a.lebar = input.nextInt(); + System.out.print("Masukkan tinggi balok : "); + a.tinggi = input.nextInt(); + System.out.println("Volume balok : " + a.getvolumebalok()); + System.out.println("Luas Permukaan balok : " + a.getluasPermukaanbalok()); + input.close(); + } + else if (pilihan == 3) { + Scanner input = new Scanner(System.in); + Bola a = new Bola(); + System.out.print("Masukkan jari jari bola : "); + a.jari = input.nextInt(); + System.out.println("Volume bola : " + a.getvolumebola()); + System.out.println("Luas Permukaan bola : " + a.getluasPermukaanbola()); + input.close(); + } + else if (pilihan == 4) { + Scanner input = new Scanner(System.in); + Tabung a = new Tabung(); + System.out.print("Masukkan jari jari tabung : "); + a.jari = input.nextInt(); + System.out.print("Masukkan tinggi tabung : "); + a.tinggi = input.nextInt(); + System.out.println("Volume tabung : " + a.getvolumetabung()); + System.out.println("Luas Permukaan tabung : " + a.getluasPermukaantabung()); + input.close(); + } + else if (pilihan == 5) { + Scanner input = new Scanner(System.in); + Persegi a = new Persegi(); + System.out.print("Masukkan sisi : "); + a.sisi = input.nextInt(); + System.out.println("luas persegi : " + a.getluasgpersegi()); + System.out.println("keliling persegi : " + a.getkelilingpersegi()); + input.close(); + } + else if (pilihan == 6) { + Scanner input = new Scanner(System.in); + persegiPanjang a = new persegiPanjang(); + System.out.print("Masukkan panjang : "); + a.panjang = input.nextInt(); + System.out.print("Masukkan lebar : "); + a.lebar = input.nextInt(); + System.out.println("luas persegi : " + a.getluaspersegiPanjang()); + System.out.println("keliling persegi : " + a.getkelilingpersegiPanjang()); + input.close(); + } + else if (pilihan == 7) { + Scanner input = new Scanner(System.in); + Lingkaran a = new Lingkaran(); + System.out.print("Masukkan jari jari : "); + a.jari = input.nextInt(); + System.out.println("luas lingkaran : " + a.getluaslingkaran()); + System.out.println("keliling lingkaran : " + a.getkelilinglingkaran()); + input.close(); + } + else if (pilihan == 8) { + Scanner input = new Scanner(System.in); + Segitiga a = new Segitiga(); + System.out.print("Masukkan alas : "); + a.alas = input.nextInt(); + System.out.print("Masukkan tinggi : "); + a.tinggi = input.nextInt(); + System.out.print("Masukkan sisi : "); + a.sisi = input.nextInt(); + System.out.println("luas segitiga : " + a.getluassegitiga()); + System.out.println("keliling segitiga : " + a.getkelilingsegitiga()); + input.close(); + } + else if (pilihan == 9) { + Scanner input = new Scanner(System.in); + Trapesium a = new Trapesium(); + System.out.print("Masukkan alas atas : "); + a.alas1 = input.nextInt(); + System.out.print("Masukkan alas bawah : "); + a.alas2 = input.nextInt(); + System.out.print("Masukkan rusuk kiri : "); + a.rusuk1 = input.nextInt(); + System.out.print("Masukkan rusuk kanan : "); + a.rusuk2 = input.nextInt(); + System.out.print("Masukkan tinggi : "); + a.tinggi = input.nextInt(); + System.out.println("luas trapesium : " + a.getluastrapesium()); + System.out.println("keliling trapesium : " + a.getkelilingtrapesium()); + input.close(); + } + else { + System.out.println("Pilihan salah"); + } + break; + } + + inp.close(); + + + + } +} \ No newline at end of file diff --git a/src/H071221098/pertemuan_5/MainAnggota.java b/src/H071221098/pertemuan_5/MainAnggota.java new file mode 100644 index 0000000..29dc946 --- /dev/null +++ b/src/H071221098/pertemuan_5/MainAnggota.java @@ -0,0 +1,17 @@ +package H071221098.pertemuan_5; +public class MainAnggota { + public static void main(String[] args) { //method yang dapat dipakai tanpa harus mendeklarasikan suatu class + PengurusInti pengurusInti = new PengurusInti("Ojan", 19, "Laki-Laki", "Ketua"); + System.out.println("Nama : " + pengurusInti.getName()); + System.out.println("Umur : " + pengurusInti.getAge()); + System.out.println("Gender : " + pengurusInti.getGender()); + System.out.println("Jabatan : " + pengurusInti.getJabatan()); + + + KordinatorBidangStaff koordinasiBidangStaff = new KordinatorBidangStaff("Sri", 19,"Wanita", "Humas"); + System.out.println("Nama : " + koordinasiBidangStaff.getName()); + System.out.println("Umur : " + koordinasiBidangStaff.getAge()); + System.out.println("Gender : " + koordinasiBidangStaff.getGender()); + System.out.println("Bidang : " + koordinasiBidangStaff.getBidang()); + } +} diff --git a/src/H071221098/pertemuan_6/Assignment_6_1.java b/src/H071221098/pertemuan_6/Assignment_6_1.java new file mode 100644 index 0000000..ecc76b5 --- /dev/null +++ b/src/H071221098/pertemuan_6/Assignment_6_1.java @@ -0,0 +1,78 @@ +package H071221098.pertemuan_6; +abstract class Dog implements Moveable{ + int position; + int averageLenght; + abstract void describe(); + +} + +class Pitbull extends Dog{ + + @Override + public void move() { + position += 3; + System.out.println("Anjing ini bergeser ke sebelah kanan sejauh " + position); + + } + + @Override + void describe() { + System.out.println("Mempunyai otot yang sangar"); + + } + +} + +class SiberianHusky extends Dog{ + + @Override + public void move() { + position += 2; + System.out.println("Anjing ini bergeser ke sebelah kanan sejauh"+ position); + + } + + @Override + void describe() { + System.out.println("Mirip dengan srigala"); + + } + +} + +class Bulldog extends Dog{ + + @Override + public void move() { + position +=1; + System.out.println("Anjing ini bergerak ke sebelah kanan sejauh"+ position); + + } + + @Override + void describe() { + System.out.println("Memiliki pipi yang turun"); + + } + +} + +class GermanShepherd extends Dog{ + + @Override + public void move() { + position += 3; + System.out.println("Anjing ini bergerak ke sebelah kanan sejauh"+ position); + + } + + @Override + void describe() { + System.out.println("Merupakan anjing yang pintar"); + + } + + +} + + diff --git a/src/H071221098/pertemuan_6/Assignment_6_1b.java b/src/H071221098/pertemuan_6/Assignment_6_1b.java new file mode 100644 index 0000000..f0264e0 --- /dev/null +++ b/src/H071221098/pertemuan_6/Assignment_6_1b.java @@ -0,0 +1,40 @@ +package H071221098.pertemuan_6; + +interface Moveable{ + void move(); +} + +class Smartphone implements Moveable{ + int price; + String brand; + + public Smartphone(int price, String brand) { + this.price = price; + this.brand = brand; + } + + @Override + public void move() { + System.out.println("smartphone berpindah"); + + } + +} + +class Car implements Moveable{ + int totalForwardGear; + String color; + int maxSpeed; + + public Car(int totalForwardGear, String color, int maxSpeed) { + this.totalForwardGear = totalForwardGear; + this.color = color; + this.maxSpeed = maxSpeed; + } + + @Override + public void move() { + System.out.println("Mobil sedang berakselerasi"); + + } +} \ No newline at end of file diff --git a/src/H071221098/pertemuan_6/Main.java b/src/H071221098/pertemuan_6/Main.java new file mode 100644 index 0000000..1212cfe --- /dev/null +++ b/src/H071221098/pertemuan_6/Main.java @@ -0,0 +1,16 @@ +package H071221098.pertemuan_6; + +public class Main{ + public static void main(String[] args) { + Pitbull pitbull = new Pitbull(); + System.out.println("========== ANJING =========="); + pitbull.move(); + pitbull.describe(); + System.out.println("\n========== SMARTPHONE =========="); + Smartphone smartphone = new Smartphone(100000,"VIVO"); + smartphone.move(); + System.out.println("\n========= CAR =========="); + Car car = new Car(100,"VIOLET",100000); + car.move(); + } +} diff --git a/src/H071221098/pertemuan_6/diagram.plantuml b/src/H071221098/pertemuan_6/diagram.plantuml new file mode 100644 index 0000000..01cbd4b --- /dev/null +++ b/src/H071221098/pertemuan_6/diagram.plantuml @@ -0,0 +1,49 @@ +@startuml + +Moveable <-- Dog +Dog <-- Pitbull +Dog <-- SiberianHusky +Dog <-- Bulldog +Dog <-- GermanShepherd + +class Dog{ + {static} # position : int + {static} # averageLength : int + + describe() : void +} +class Pitbull{ + + describe() : void +} +class SiberianHusky{ + + describe() : void +} +class Bulldog{ + + describe() : void +} +class GermanShepherd{ + + describe() : void +} + + +Moveable <-- Smartphone +Moveable <-- Car +class Moveable{ + + move() : void + +} + +class Smartphone{ + {static} # price : int + {static} # brand : String + + move() : void + +} + +class Car{ + {static} # totalForwardGear : int + {static} # color : String n + {static} # maxSpeed : int + + move() : void + +} +@enduml \ No newline at end of file diff --git a/src/H071221098/pertemuan_7/Assignment_7_1.java b/src/H071221098/pertemuan_7/Assignment_7_1.java new file mode 100644 index 0000000..188c8f1 --- /dev/null +++ b/src/H071221098/pertemuan_7/Assignment_7_1.java @@ -0,0 +1,85 @@ +package H071221098.pertemuan_7; + +package H071221098.pertemuan_7; +public abstract class Character{ + String name; + public String getName() { + return name; + } + int attackPower; + String attackType; + + public Character(String name, int attackPower, String attackType) { + this.name = name; + this.attackPower = attackPower; + this.attackType = attackType; + } + + public String getAttackType() { + return attackType; + } + + + abstract int attack(); + abstract int attack(String attackType); + +} + +class Fighter extends Character{ + + public Fighter(String name, int attackPower, String attackType) { + super(name, attackPower, attackType); + + } + + @Override + int attack() { + return attackPower; + + } + + @Override + int attack(String attackType) { + if (attackType == "melee") { + return attackPower*2; + + + } + + if (attackType == "ranged") { + return attackPower; + + } + + return 0; + +} +} + +class Mage extends Character{ + + public Mage(String name, int attackPower, String attackType) { + super(name, attackPower, attackType); + + } + + @Override + int attack() { + return attackPower; + + } + + @Override + int attack(String attackType) { + if (attackType == "fire") { + return attackPower*3; + } + + if (attackType == "frost") { + return attackPower*2; + } + return 0; + } + +} + diff --git a/src/H071221098/pertemuan_7/Assignment_7_1_main.java b/src/H071221098/pertemuan_7/Assignment_7_1_main.java new file mode 100644 index 0000000..830068d --- /dev/null +++ b/src/H071221098/pertemuan_7/Assignment_7_1_main.java @@ -0,0 +1,40 @@ +package H071221098.pertemuan_7; + +public class Main { + static void printAttack(Character character){ //overloading + System.out.println("nama: " + character.getName()); + character.attack(); + System.out.println("attack power: "+character.attack()); + character.attack(character.getAttackType()); + System.out.println("attack type: "+ character.getAttackType()); + System.out.println("=".repeat(25)); + } + public static void main(String[] args) { + + // Character fighter1 = new Fighter("Kian santang", 2, "melee"); + // Character fighter2 = new Fighter("boboiboy", 3, "ranged"); + // Character fighter3 = new Fighter("Rafli Dahlan", 100, "melee"); + + // Character mage1 = new Mage("nur", 5, "frost"); + // Character mage2 = new Mage("meimei", 5, "fire"); + + // Character[] player = new Character[5]; + // player[0] = fighter1; + // player[1] = fighter2; + // player[2] = fighter3; + // player[3] = mage1; + // player[4] = mage2; + + Character[] player = new Character[5]; + player[0] = new Fighter("a", 2, "melee"); + player[1] = new Fighter("b", 4, "ranged"); + player[2] = new Mage("c", 2, "fire"); + player[3] = new Fighter("d", 6, "melee"); + player[4] = new Mage("e", 4, "frost"); + + for (int i = 0; i < player.length; i++) { + printAttack(player[i]); + } +} + +} diff --git a/src/H071221098/pertemuan_7/Assignment_7_2.java b/src/H071221098/pertemuan_7/Assignment_7_2.java new file mode 100644 index 0000000..a50ae96 --- /dev/null +++ b/src/H071221098/pertemuan_7/Assignment_7_2.java @@ -0,0 +1,26 @@ +package H071221098.pertemuan_7; + +public class Product { + private String name; + private Type price; + private String expiryDate; + + public Product(String name, Type price, String expiryDate) { + this.name = name; + this.price = price; + this.expiryDate = expiryDate; + } + + public String getName() { + return name; + } + + public Type getPrice() { + return price; + } + + public String getExpiryDate() { + return expiryDate; + } + +} diff --git a/src/H071221098/pertemuan_7/Assignment_7_2_main.java b/src/H071221098/pertemuan_7/Assignment_7_2_main.java new file mode 100644 index 0000000..726bdbc --- /dev/null +++ b/src/H071221098/pertemuan_7/Assignment_7_2_main.java @@ -0,0 +1,13 @@ +package H071221098.pertemuan_7; + +public class Main { + public static void main(String[] args) { + Product product1 = new Product<>("Kinder Joy", "Seribu", "2023-0501"); + Product product2 = new Product<>("Sari Roti", 15000, " 2023-05-20"); + Product product3 = new Product<>("Susu Kurma ", 7.5, " 2023-06-01"); + + System.out.println("Product 1: "+product1.getName() +" - "+ product1.getPrice()+" - "+ product1.getExpiryDate()); + System.out.println("Product 2: "+product2.getName()+" - "+product2.getPrice()+" - "+product2.getExpiryDate()); + System.out.println("Product 3: "+product3.getName()+" - "+product3.getPrice()+" - "+product3.getExpiryDate()); + } +} diff --git a/src/H071221098/pertemuan_7/Assignment_7_3/Burger.java b/src/H071221098/pertemuan_7/Assignment_7_3/Burger.java new file mode 100644 index 0000000..b033014 --- /dev/null +++ b/src/H071221098/pertemuan_7/Assignment_7_3/Burger.java @@ -0,0 +1,10 @@ +package H071221098.pertemuan_7; + +public class Burger implements Food{ + private int harga = 10; + + @Override + public int getPrice() { + return harga; + } +} diff --git a/src/H071221098/pertemuan_7/Assignment_7_3/Food.java b/src/H071221098/pertemuan_7/Assignment_7_3/Food.java new file mode 100644 index 0000000..9c35813 --- /dev/null +++ b/src/H071221098/pertemuan_7/Assignment_7_3/Food.java @@ -0,0 +1,5 @@ +package H071221098.pertemuan_7; + +interface Food { + int getPrice(); +} diff --git a/src/H071221098/pertemuan_7/Assignment_7_3/FoodFactory.java b/src/H071221098/pertemuan_7/Assignment_7_3/FoodFactory.java new file mode 100644 index 0000000..a892189 --- /dev/null +++ b/src/H071221098/pertemuan_7/Assignment_7_3/FoodFactory.java @@ -0,0 +1,15 @@ +package H071221098.pertemuan_7; + +public class FoodFactory { + public static Food getFood(String jenis){ + if (jenis.equalsIgnoreCase("burger")) { + return new Burger(); + } else if (jenis.equalsIgnoreCase("pizza")) { + return new Pizza(); + } else if (jenis.equalsIgnoreCase("steak")) { + return new Steak(); + } else { + return null; + } + } +} diff --git a/src/H071221098/pertemuan_7/Assignment_7_3/Main.java b/src/H071221098/pertemuan_7/Assignment_7_3/Main.java new file mode 100644 index 0000000..2810e14 --- /dev/null +++ b/src/H071221098/pertemuan_7/Assignment_7_3/Main.java @@ -0,0 +1,21 @@ +package H071221098.pertemuan_7; + +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 price: "+total); + } +} diff --git a/src/H071221098/pertemuan_7/Assignment_7_3/Pizza.java b/src/H071221098/pertemuan_7/Assignment_7_3/Pizza.java new file mode 100644 index 0000000..27f7583 --- /dev/null +++ b/src/H071221098/pertemuan_7/Assignment_7_3/Pizza.java @@ -0,0 +1,10 @@ +package H071221098.pertemuan_7; + +public class Pizza implements Food{ + private int harga = 30; + + @Override + public int getPrice() { + return harga; + } +} \ No newline at end of file diff --git a/src/H071221098/pertemuan_7/Assignment_7_3/Restaurant.java b/src/H071221098/pertemuan_7/Assignment_7_3/Restaurant.java new file mode 100644 index 0000000..305d389 --- /dev/null +++ b/src/H071221098/pertemuan_7/Assignment_7_3/Restaurant.java @@ -0,0 +1,13 @@ +package H071221098.pertemuan_7; + +import java.util.List; + +public class Restaurant { + public static int calculateTotal(List orders) { + int total = 0; + for (Food order : orders) { + total += order.getPrice(); + } + return total; + } +} \ No newline at end of file diff --git a/src/H071221098/pertemuan_7/Assignment_7_3/Steak.java b/src/H071221098/pertemuan_7/Assignment_7_3/Steak.java new file mode 100644 index 0000000..0318220 --- /dev/null +++ b/src/H071221098/pertemuan_7/Assignment_7_3/Steak.java @@ -0,0 +1,10 @@ +package H071221098.pertemuan_7; + +public class Steak implements Food{ + private int harga = 25; + + @Override + public int getPrice() { + return harga; + } +} \ No newline at end of file diff --git a/src/H071221098/pertemuan_8/Assigment_8_1.java b/src/H071221098/pertemuan_8/Assigment_8_1.java new file mode 100644 index 0000000..8e5f655 --- /dev/null +++ b/src/H071221098/pertemuan_8/Assigment_8_1.java @@ -0,0 +1,199 @@ +package H071221098.pertemuan_8; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Random; + +public class AppRacer { + public static void main(String[] args) throws InterruptedException { + Tes typeRacer = new Tes(); + typeRacer.setNewWordsToType(); + System.out.println("|| Text to Type ||"); + System.out.println("\"" + typeRacer.getWordsToType() + "\""); + + Typer[] typers = new Typer[3]; + + typers[0] = new Typer("Bot Mansur", 40, typeRacer); + typers[1] = new Typer("Bot ToKu", 32, typeRacer); + typers[2] = new Typer("Bot Yukiao", 30, typeRacer); + + typeRacer.getRaceContestant().addAll(Arrays.asList(typers)); + + typeRacer.startRace(); + } +} + +class Typer extends Thread { + private String botName, wordsTyped; + private double wpm; + private Tes typeRacer; + + public Typer(String botName, double wpm, Tes typeRacer) { + this.botName = botName; + this.wpm = wpm; + this.wordsTyped = ""; + this.typeRacer = typeRacer; + } + + public void setBotName(String botName) { + this.botName = botName; + } + + public void setWpm(int wpm) { + this.wpm = wpm; + } + + public void addWordTyped(String newWordsTyped) { + this.wordsTyped += newWordsTyped + " "; + } + + public String getWordsTyped() { + return wordsTyped; + } + + public String getBotName() { + return botName; + } + + public double getWpm() { + return wpm; + } + + @Override + public void run() { + + String[] wordsToType = typeRacer.getWordsToType().split(" "); + + // TODO (1): Buatlah variable howLongToType yang memuat waktu yang diperlukan + // typer + // untuk menulis 1 kata dalam milisecond + int howLongToType = (int) Math.floor(((60 / this.wpm)) * 1000); + + // TODO (2): Buatlah perulangan untuk menambahkan kata dengan method + // addWordToTyped setelah interval waktu sebanyak howLongToType + for (int i = 0; i < wordsToType.length; i++) { + try { + Thread.sleep(howLongToType); + addWordTyped(wordsToType[i]); + } catch (InterruptedException e) { + System.out.println("Error: " + this.botName); + } + } + + this.addWordTyped("(selesai)"); + // TODO (3): menambahkan typer yang telah selesai mengetik semua kata ke list + // typeRaceTabel yang ada di class typeRacer + typeRacer.addResult(new Result(botName, howLongToType * wordsToType.length)); + } +} + +class Result { + private String name; + private int finishTime; + + public Result(String name, int finishTime) { + this.name = name; + this.finishTime = finishTime; + } + + public String getName() { + return name; + } + + public void setName(String racerName) { + this.name = racerName; + } + + public int getFinishTime() { + return finishTime; + } + + public void setFinishTime(int racerTime) { + this.finishTime = racerTime; + } +} + +class Tes { + private String wordsToType; + private ArrayList raceContestant = new ArrayList<>(); + private ArrayList raceStanding = new ArrayList<>(); + + public String getWordsToType() { + return wordsToType; + } + + public ArrayList getRaceContestant() { + return raceContestant; + } + + // Word by Yusuf Syam, Silahkan diubah jika dirasa kurang bijak + private String[] wordsToTypeList = { + "Menuju tak terbatas dan melampauinya", + "Kehidupan adalah perjalanan yang penuh dengan lika-liku. Jadikan setiap tantangan sebagai kesempatan untuk tumbuh dan berkembang", + "Cinta sejati adalah ketika dua jiwa saling melengkapi, memberi dukungan dan menginspirasi satu sama lain untuk menjadi yang terbaik", + "Hidup adalah anugerah yang berharga. Nikmati setiap momen dan hargai kebahagiaan sederhana di sekitar kita", + "Perubahan adalah satu-satunya konstanta dalam hidup. Yang bertahan adalah mereka yang dapat beradaptasi dengan fleksibilitas", + "Kebersamaan adalah fondasi yang kuat dalam membangun hubungan yang langgeng dan bermakna", + "Masa depan adalah milik mereka yang memiliki imajinasi, tekad, dan kerja keras untuk mewujudkan visi mereka", + "Ketika kita berbagi dengan orang lain, kita tidak hanya mengurangi beban mereka, tetapi juga memperkaya hati kita sendiri", + "Kesuksesan sejati adalah ketika kita mencapai tujuan kita sambil tetap mempertahankan integritas dan empati terhadap orang lain", + "Rasa syukur adalah kunci untuk mengalami kebahagiaan yang sejati dalam hidup. Mencintai apa yang kita miliki adalah kunci kepuasan yang tak ternilai", + }; + + public void setNewWordsToType() { + Random random = new Random(); + int angkaRandom = random.nextInt(10); + wordsToType = wordsToTypeList[angkaRandom]; + } + + // TODO (4) : Buat method addResult yang mana digunakan untuk menambahkan typer + // yangtelah selesai (mengetik semua kata), ke dalam list race standing. + public synchronized void addResult(Result result) { + raceStanding.add(result); + } + + public void printRaceStanding() { + System.out.println("\nKlasemen Akhir Type Racer"); + System.out.println("=========================\n"); + + // TODO (5) : Tampilkan klasemen akhir dari kompetisi, dengan format + // {posisi}. {nama} = {waktu penyelesaian dalam detik} detik + int index = 1; + + for (Result result : raceStanding) { + System.out.printf("%d. %s - %.2f detik\n", index, result.getName(), + result.getFinishTime() / 1000.0); + index += 1; + } + } + + public void startRace() throws InterruptedException { + // TODO (6) : jalankan kompetisi + for (Typer racer : raceContestant) { + racer.start(); + } + + // TODO (7) : selaman semua peserta belum selesai, maka tampilkan + // SS + // Setiap 2 detik + while (raceContestant.size() != raceStanding.size()) { + Thread.sleep(2000); + System.out.println("\nTyping Progress ..."); + System.out.println("================\n"); + + for (Typer racer : raceContestant) { + System.out.printf("- %s\t=> %s\n", racer.getBotName(), racer.getWordsTyped()); + System.out.println("-".repeat(100)); + } + + System.out.println("\n" + "#".repeat(100)); + } + + // TODO (8) : Tampilkan race standing setelah semua typer selesai + for (Typer racer : raceContestant) { + racer.join(); + } + + printRaceStanding(); + } +} diff --git a/src/H071221098/pertemuan_8/Assigment_8_2.java b/src/H071221098/pertemuan_8/Assigment_8_2.java new file mode 100644 index 0000000..c245006 --- /dev/null +++ b/src/H071221098/pertemuan_8/Assigment_8_2.java @@ -0,0 +1,101 @@ +package H071221098.pertemuan_8; + +import java.util.Random; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +public class TugasPraktikum { + + public static void main(String[] args) { + int numData = 4; + + UiThread uiThread = new UiThread(numData); + + ExecutorService executor = Executors.newFixedThreadPool(3); + + uiThread.start(); + + for (int i = 0; i < numData; i++) { + executor.execute(new BackgroundThread(uiThread, TaskTimeHelper.generateRandomTimeExecution())); + } + executor.shutdown(); + } +} + +class UiThread extends Thread { + private int numBackgroundThreads; + private int numThreadsSuccess = 0; + private int numThreadsFailed = 0; + private int timeExecution = 0; + + public UiThread(int numBackgroundThreads) { + this.numBackgroundThreads = numBackgroundThreads; + } + + public void run() { + System.out.println("Start load " + numBackgroundThreads + " Data"); + while ((numThreadsSuccess + numThreadsFailed) < numBackgroundThreads) { + try { + Thread.sleep(1000); + timeExecution++; + System.out.printf("Loading... (%ds)\n", timeExecution); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + System.out.println("\nTask Finish."); + System.out.println("Time Execution : " + timeExecution + "s"); + if (numThreadsFailed == 0) { + System.out.println("All data is successfully loaded"); + } else if (numThreadsSuccess == 0) { + System.out.println("All data failed to load"); + } else { + System.out.println( + numThreadsSuccess + " Data Successfully loaded & " + numThreadsFailed + " Data failed to load"); + } + } + + public synchronized void incrementNumThreadsSuccess() { + this.numThreadsSuccess++; + } + + public synchronized void incrementNumThreadsFailed() { + this.numThreadsFailed++; + } +} + +class BackgroundThread extends Thread { + private UiThread uiThread; + private int timeExecution; + + public BackgroundThread(UiThread uiThread, int timeExecution) { + this.uiThread = uiThread; + this.timeExecution = timeExecution; + } + + public void run() { + try { + for (int i = 1; i <= timeExecution; i++) { + TimeUnit.SECONDS.sleep(1); + if (i * 1000 > 2000) { + System.out.println("Request Timeout"); + uiThread.incrementNumThreadsFailed(); + return; + } + } + uiThread.incrementNumThreadsSuccess(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + +} + +class TaskTimeHelper { + static int generateRandomTimeExecution() { + Random random = new Random(); + int randomNumber = random.nextInt(6) + 1; + return randomNumber; + } +} diff --git a/src/H071221098/pertemuan_9/helloapp/.gitattributes b/src/H071221098/pertemuan_9/helloapp/.gitattributes new file mode 100644 index 0000000..097f9f9 --- /dev/null +++ b/src/H071221098/pertemuan_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/H071221098/pertemuan_9/helloapp/.gitignore b/src/H071221098/pertemuan_9/helloapp/.gitignore new file mode 100644 index 0000000..1b6985c --- /dev/null +++ b/src/H071221098/pertemuan_9/helloapp/.gitignore @@ -0,0 +1,5 @@ +# Ignore Gradle project-specific cache directory +.gradle + +# Ignore Gradle build output directory +build diff --git a/src/H071221098/pertemuan_9/helloapp/.vscode/settings.json b/src/H071221098/pertemuan_9/helloapp/.vscode/settings.json new file mode 100644 index 0000000..b84f89c --- /dev/null +++ b/src/H071221098/pertemuan_9/helloapp/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "java.configuration.updateBuildConfiguration": "interactive", + "java.compile.nullAnalysis.mode": "automatic" +} \ No newline at end of file diff --git a/src/H071221098/pertemuan_9/helloapp/app/build.gradle b/src/H071221098/pertemuan_9/helloapp/app/build.gradle new file mode 100644 index 0000000..e2bc527 --- /dev/null +++ b/src/H071221098/pertemuan_9/helloapp/app/build.gradle @@ -0,0 +1,38 @@ +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/H071221098/pertemuan_9/helloapp/app/src/main/java/helloapp/App.java b/src/H071221098/pertemuan_9/helloapp/app/src/main/java/helloapp/App.java new file mode 100644 index 0000000..ad6eb75 --- /dev/null +++ b/src/H071221098/pertemuan_9/helloapp/app/src/main/java/helloapp/App.java @@ -0,0 +1,193 @@ +package helloapp; + +import org.w3c.dom.events.Event; + +import javafx.application.Application; +import javafx.geometry.Pos; +import javafx.scene.Scene; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.scene.layout.StackPane; +import javafx.scene.layout.VBox; +import javafx.scene.paint.Color; +import javafx.scene.text.Font; +import javafx.scene.text.Text; +import javafx.scene.layout.HBox; +import javafx.stage.Stage; +import javafx.scene.control.Button; + + +public class App extends Application { + private Stage stage; + + @Override + public void start(Stage primaryStage) { + stage = primaryStage; + showFirstScene(); + stage.show(); + stage.setTitle("MY CALCULATOR"); + Image icon = new Image("C:/Users/ASUS/Downloads/475497.png"); + primaryStage.getIcons().add(icon); + + } + + private void showFirstScene(){ + VBox vbox = new VBox(); + vbox.setAlignment(Pos.CENTER); + vbox.setStyle("-fx-background-color: #FFA500; "); + Label label = new Label("MY CALCULATOR"); + label.setStyle("-fx-font-weight: bold; -fx-font-size: 40px; "); + + ImageView imageView = new ImageView(); + String imagePath ="C:/Users/ASUS/Downloads/475497.png"; + Image image = new Image(imagePath); + imageView.setImage(image);; + + Button button = new Button("Mulai"); + button.setFont(Font.font("Arial", 30)); + button.setStyle("-fx-background-color: #FFC0CB; -fx-background-radius: 10;"); + button.setOnAction(event -> showSecScene()); + + vbox.getChildren().add(label); + vbox.getChildren().add(imageView); + vbox.getChildren().add(button); + + Scene scene1 = new Scene(vbox, 400, 300); + stage.setScene(scene1); + stage.show(); + stage.setFullScreen(true); + + } + + private void showSecScene(){ + VBox vbox = new VBox(); + vbox.setAlignment(Pos.CENTER); + Text text = new Text("PILIH MENU"); + text.setStyle("-fx-font-weight: bold; -fx-font-size: 40px; "); + Button button = new Button("Kalkulator 1"); + button.setFont(Font.font("Arial", 30)); + Label label = new Label(); + button.setOnAction(event -> showThirdScene()); + Button button1 = new Button("Kalkulator 2"); + button1.setFont(Font.font("Arial", 30)); + button1.setOnAction(event -> showFourthScene()); + vbox.setStyle("-fx-background-color: #FFC0CB"); + + vbox.getChildren().add(text); + vbox.getChildren().add(button); + vbox.getChildren().add(label); + vbox.getChildren().add(button1); + + Scene scene2 = new Scene(vbox, 400, 300); + stage.setScene(scene2); + stage.show(); + stage.setFullScreen(true); + } + + private void showThirdScene(){ + VBox vbox = new VBox(); + vbox.setAlignment(Pos.CENTER); + Text text = new Text("PENJUMLAHAN"); + TextField tfield = new TextField(); + TextField tfield1 = new TextField(); + Text text1 = new Text("Hasil"); + Label label = new Label(); + Button button = new Button("Clear"); + button.setOnAction(event ->{ + tfield.clear(); + tfield1.clear(); + }); + Button button1 = new Button("Calculate"); + button1.setOnAction(event -> { + try { + String input1 = tfield.getText(); + int nilai1 = Integer.parseInt(input1); + String input2 = tfield1.getText(); + int nilai2 = Integer.parseInt(input2); + + int hasil = nilai1 + nilai2; + label.setText(""+ hasil); + } catch (Exception e) { + label.setText("Inputan tidak valid"); + } + }); + Button button2 = new Button("Back To Home"); + button2.setOnAction(event ->{ + showSecScene(); + }); + vbox.setStyle("-fx-background-color: #800080;"); + + vbox.getChildren().add(text); + vbox.getChildren().add(tfield); + vbox.getChildren().add(tfield1); + vbox.getChildren().add(text1); + vbox.getChildren().add(label); + vbox.getChildren().add(button); + vbox.getChildren().add(button1); + vbox.getChildren().add(button2); + + Scene scene3 = new Scene(vbox, 400, 300); + stage.setScene(scene3); + stage.show(); + stage.setFullScreen(true); + + } + private void showFourthScene(){ + VBox vbox = new VBox(); + vbox.setAlignment(Pos.CENTER); + Text text = new Text("Pengurangan"); + TextField tfield = new TextField(); + TextField tfield1 = new TextField(); + Text text1 = new Text("Hasil"); + Label label = new Label(); + Button button = new Button("Clear"); + button.setOnAction(event ->{ + tfield.clear(); + tfield1.clear(); + }); + Button button1 = new Button("Calculate"); + button1.setOnAction(event -> { + try { + String input1 = tfield.getText(); + int nilai1 = Integer.parseInt(input1); + String input2 = tfield1.getText(); + int nilai2 = Integer.parseInt(input2); + + int hasil = nilai1 - nilai2; + label.setText(""+ hasil); + } catch (Exception e) { + label.setText("Inputan tidak valid"); + } + }); + Button button2 = new Button("Back To Home"); + button2.setOnAction(event ->{ + showSecScene(); + }); + vbox.setStyle("-fx-background-color: #00BFFF;"); + + vbox.getChildren().add(text); + vbox.getChildren().add(tfield); + vbox.getChildren().add(tfield1); + vbox.getChildren().add(text1); + vbox.getChildren().add(label); + vbox.getChildren().add(button); + vbox.getChildren().add(button1); + vbox.getChildren().add(button2); + + Scene scene4 = new Scene(vbox, 400, 300); + stage.setScene(scene4); + stage.show(); + stage.setFullScreen(true); + + } + + + + + public static void main(String[] args) { + launch(); + } + +} \ No newline at end of file diff --git a/src/H071221098/pertemuan_9/helloapp/app/src/test/java/helloapp/AppTest.java b/src/H071221098/pertemuan_9/helloapp/app/src/test/java/helloapp/AppTest.java new file mode 100644 index 0000000..bfaa288 --- /dev/null +++ b/src/H071221098/pertemuan_9/helloapp/app/src/test/java/helloapp/AppTest.java @@ -0,0 +1,14 @@ +/* + * This Java source file was generated by the Gradle 'init' task. + */ +package helloapp; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +class AppTest { + @Test void appHasAGreeting() { + App classUnderTest = new App(); + assertNotNull(classUnderTest.getGreeting(), "app should have a greeting"); + } +} diff --git a/src/H071221098/pertemuan_9/helloapp/gradle/wrapper/gradle-wrapper.properties b/src/H071221098/pertemuan_9/helloapp/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..37aef8d --- /dev/null +++ b/src/H071221098/pertemuan_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/H071221098/pertemuan_9/helloapp/gradlew b/src/H071221098/pertemuan_9/helloapp/gradlew new file mode 100644 index 0000000..aeb74cb --- /dev/null +++ b/src/H071221098/pertemuan_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/H071221098/pertemuan_9/helloapp/gradlew.bat b/src/H071221098/pertemuan_9/helloapp/gradlew.bat new file mode 100644 index 0000000..93e3f59 --- /dev/null +++ b/src/H071221098/pertemuan_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/H071221098/pertemuan_9/helloapp/settings.gradle b/src/H071221098/pertemuan_9/helloapp/settings.gradle new file mode 100644 index 0000000..18dd0f6 --- /dev/null +++ b/src/H071221098/pertemuan_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')