diff --git a/src/H071221092/Pertemuan_1/No1.java b/src/H071221092/Pertemuan_1/No1.java new file mode 100644 index 0000000..0e048b8 --- /dev/null +++ b/src/H071221092/Pertemuan_1/No1.java @@ -0,0 +1,30 @@ +package H071221092.Pertemuan_1; + +import java.util.Scanner; + +public class No1 { + public static void main(String[] args) { + int nim; + Scanner keyboard = new Scanner(System.in); + System.out.print("Masukkan NIM: "); + nim = keyboard.nextInt(); + + if (nim % 7 == 0) { + System.out.println("Soal: no 7"); + } else if (nim % 7 == 1) { + System.out.println("Soal: no 1"); + } else if (nim % 7 == 2) { + System.out.println("Soal: no 2"); + } else if (nim % 7 == 3) { + System.out.println("Soal: no 3"); + } else if (nim % 7 == 4) { + System.out.println("Soal: no 4"); + } else if (nim % 7 == 5) { + System.out.println("Soal: no 5"); + } else if (nim % 7 == 6) { + System.out.println("Soal: no 6"); + } + keyboard.close(); + } + +} diff --git a/src/H071221092/Pertemuan_1/No2.java b/src/H071221092/Pertemuan_1/No2.java new file mode 100644 index 0000000..2ab92a8 --- /dev/null +++ b/src/H071221092/Pertemuan_1/No2.java @@ -0,0 +1,33 @@ +package H071221092.Pertemuan_1; + +import java.util.Scanner; + +public class No2 { + public static void main(String[] args) { + Scanner userInput = new Scanner(System.in) ; + int bilBulat,bilDesimal,n,i; + + bilBulat = 0; + bilDesimal = 0; + + try{ + System.out.print("Masukkan Jumlah Bilangan :"); + n = userInput.nextInt(); + userInput.nextLine(); + + for(i = 0; i < n; i++) { + double num = userInput.nextDouble(); //untuk mencari nilai yang double / float 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/H071221092/Pertemuan_1/No3.java b/src/H071221092/Pertemuan_1/No3.java new file mode 100644 index 0000000..e64f8e4 --- /dev/null +++ b/src/H071221092/Pertemuan_1/No3.java @@ -0,0 +1,26 @@ +package H071221092.Pertemuan_1; + +import java.util.Scanner; + +public class No3 { + public static void main(String[] args) { + Scanner input= new Scanner (System.in); + + try{ + System.out.print("Name : "); + String name = input.nextLine(); + + System.out.print("Age : "); + int age = input.nextInt(); + input.nextLine(); //baris + + System.out.print("Hobby : "); + String hobby = input.nextLine(); + + System.out.print("Nama saya " + name + ", " + age + " Tahun, hobby " + hobby + "."); + } catch (Exception e) { + System.out.println("Umur harus berupa angka"); + } + input.close() ; + } +} \ No newline at end of file diff --git a/src/H071221092/Pertemuan_1/No4.java b/src/H071221092/Pertemuan_1/No4.java new file mode 100644 index 0000000..57218b5 --- /dev/null +++ b/src/H071221092/Pertemuan_1/No4.java @@ -0,0 +1,34 @@ + +package H071221092.Pertemuan_1; + +import java.util.Scanner; + +public class No4 { + public static void main(String[] args) { + Scanner inputan = new Scanner(System.in); + + String kalimat; + + System.out.print("Masukkan Judul Film : "); + kalimat = inputan.nextLine(); + + String kalimatBaru = new String(); + + String[] array = kalimat.split(" "); + for (int index = 0; index < array.length; index=index+1) { + // System.out.print(array[index] + " "); + String kataBaru = array[index].toUpperCase().charAt(0) + array[index].substring(1).toLowerCase(); + System.out.print(kataBaru + " ") ; + } + // Split kalimat menjadi beberapa kata: + // // for (String kata : kalimat.split(" ")) { + + // String kataBaru = kata.toUpperCase().charAt(0) + kata.substring(1).toLowerCase(); + + // // kalimatBaru.append(kataBaru).append(" "); + // kalimatBaru += kataBaru + (" "); + // } + // System.out.println(kalimatBaru); + // inputan.close(); + } +} diff --git a/src/H071221092/Pertemuan_1/No5.java b/src/H071221092/Pertemuan_1/No5.java new file mode 100644 index 0000000..5709e19 --- /dev/null +++ b/src/H071221092/Pertemuan_1/No5.java @@ -0,0 +1,61 @@ +package H071221092.Pertemuan_1; + +import java.util.Scanner; + +public class No5 { + public static void main(String[] args) { + Scanner ip = new Scanner(System.in); + String a = ip.next(); + String day = a.substring(0, 2); + System.out.print(Integer.parseInt(day)); //untuk ubah 03 mnjdi 3 (menghilangkan 0) + String bulan = a.substring(3, 5); + int month = Integer.parseInt(bulan); + String [] bul = {"Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "september", "Oktober", "November", "Desember"}; + System.out.print(" " + bul[month-1] + " "); + + // 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/H071221092/Pertemuan_1/No6.java b/src/H071221092/Pertemuan_1/No6.java new file mode 100644 index 0000000..b2a04ce --- /dev/null +++ b/src/H071221092/Pertemuan_1/No6.java @@ -0,0 +1,28 @@ +package H071221092.Pertemuan_1; + +import java.util.Scanner; + +public class No6 { + public static void main(String[] args) { + + Scanner input = new Scanner(System.in); + + //Deklarasi variabel + double luas, phi=3.14; + double r; + try { + //Input nilai jari-jari + System.out.print("Masukan Jari-jari : "); + r = input.nextDouble(); + + //Menghitung luas lingkaran + luas = phi*r*r; + + //untuk menampilkan hasil + System.out.printf("Luas Lingkaran = %.2f",luas); + input.close(); + } catch(Exception a) { + System.out.println("Inputan bukan angka"); + } + } +} diff --git a/src/H071221092/Pertemuan_1/No7.java b/src/H071221092/Pertemuan_1/No7.java new file mode 100644 index 0000000..f70ca36 --- /dev/null +++ b/src/H071221092/Pertemuan_1/No7.java @@ -0,0 +1,23 @@ +package H071221092.Pertemuan_1; + +import java.util.Scanner; + +public class No7 { + public static void main(String[] args) { + String [] Makanan = {"KFC" , "MCD" , "Shilin" , "Pangsit" , "Bakso"} ; + Scanner input = new Scanner (System.in) ; + System.out.println("Masukkan nama makanan:"); + String search = input.nextLine() ; + input.close() ; // + + System.out.println(findIndex(Makanan, search)); + } + public static int findIndex (String[] array, String teks) { + for (int i = 0; i < array.length; i=i+1) { + if (array[i].toLowerCase().equals(teks.toLowerCase())) { // method untuk digunakan untuk mengabaikan case sensitive contohnya hurufbesar kecil pada inputan //cara lain gunakan tolowercase + return i ; + } + } + return -1 ; + } +} \ No newline at end of file diff --git a/src/H071221092/Pertemuan_1/No8.java b/src/H071221092/Pertemuan_1/No8.java new file mode 100644 index 0000000..7caf291 --- /dev/null +++ b/src/H071221092/Pertemuan_1/No8.java @@ -0,0 +1,35 @@ +package H071221092.Pertemuan_1; + +import java.util.Scanner; + +public class No8 { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + // Input satu bilangan + try { + System.out.print("Masukkan satu bilangan : "); + int bil = scanner.nextInt(); + + int[][] array2D = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; + boolean found = false; + + for (int i = 0; i < array2D.length; i++) { + for (int j = 0; j < array2D[i].length; j++) { + if (array2D[i][j] == bil) { + System.out.println("Bilangan " + bil + " ditemukan pada indeks [" + i + "][" + j + "]"); + found = true; + return; + } + } + } + if (!found) { + System.out.println("Bilangan " + bil + " 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/H071221092/Pertemuan_2/.vscode/settings.json b/src/H071221092/Pertemuan_2/.vscode/settings.json new file mode 100644 index 0000000..c995aa5 --- /dev/null +++ b/src/H071221092/Pertemuan_2/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.debug.settings.onBuildFailureProceed": true +} \ No newline at end of file diff --git a/src/H071221092/Pertemuan_2/No1.java b/src/H071221092/Pertemuan_2/No1.java new file mode 100644 index 0000000..1e081ec --- /dev/null +++ b/src/H071221092/Pertemuan_2/No1.java @@ -0,0 +1,29 @@ +class Handphone { + String merk ; // atribt 3-6 + String warna ; + int harga ; + + public String getMerk () { + return merk; + } + public String getWarna () { + return warna; + } + public int getHarga () { + return harga; + } +} + +public class No1 { // class main method harus public dan public cuma boleh ada satu dalam satu file + public static void main(String[] args) { + Handphone hp = new Handphone (); + hp.merk = "Iphone"; + hp.warna = "Merah"; + hp.harga = 10000; + + System.out.println("Merk handphone: " + hp.getMerk()); + System.out.println("Warna handphone: " + hp.getWarna()); + System.out.println("Harga handphone: " + hp.getHarga()); + + } +} diff --git a/src/H071221092/Pertemuan_2/No2.java b/src/H071221092/Pertemuan_2/No2.java new file mode 100644 index 0000000..d06c694 --- /dev/null +++ b/src/H071221092/Pertemuan_2/No2.java @@ -0,0 +1,43 @@ +class Person { + String name; //atribut 2-4 + int age; + boolean isMale; + + public void setName (String name){ //String name itu parameter + this.name = name; // this supaya merujuk ke objek atau class dan nama antara atribut dan parameter harus sama, bisa tidak pakai this tp harus beda nama antara atribut dan parameter + } + public String getName () { + return name; + } + public void setAge (int age) { //public void yaitu method yang tidak mengembalikan apa2 + this.age = age; + } + public int getAge () { + return age; + } + public void setGender (String gender) { //String gender karena + this.isMale = gender == "male"; + } + public String getGender (){ + if (isMale) { + return "male"; + } + else { + return "female"; + } + + } +} + +public class No2{ + public static void main(String[] args) { + Person orang = new Person (); + orang.setName("Fara"); + orang.setAge(18); + orang.setGender("female"); + + System.out.println("Nama: " + orang.getName()); + System.out.println("Umur: " + orang.getAge()); + System.out.println("Jenis kelamin: " + orang.getGender()); + } +} diff --git a/src/H071221092/Pertemuan_2/No3.java b/src/H071221092/Pertemuan_2/No3.java new file mode 100644 index 0000000..6611859 --- /dev/null +++ b/src/H071221092/Pertemuan_2/No3.java @@ -0,0 +1,67 @@ +class Produk { + String ID; + String nama; + int stok; + int harga; + public Produk (){ + } + public Produk (String ID, String nama, int stok, int harga ){ + this.ID = ID; + this.nama = nama; + this.stok = stok; + this.harga = harga; + + } + public String getId () { + return ID; + } + public String getNama () { + return nama; + } + public double getHarga () { + return harga; + } + public int getStok () { + return stok; + } + public boolean isAda () { + return stok > 0; + } +} + +public class No3{ + public static void main(String[] args) { + Produk produk1 = new Produk (); //PEMBUAT OBJEK PRODUK 1 yang PARAMETERNYA KOSONG + produk1.ID = "A"; + produk1.nama = "Baju"; + produk1.stok = 12; + produk1.harga= 100000; + + // Produk produk1 = new Produk ("A", "Baju", 12, 50000); + Produk produk2 = new Produk ("B", "Celana", 0, 40000); // PEMBUAT OBJEK MENGGUNAKAN KONSTRAKTOR YANG DALAM PARAMETERNYA + Produk produk3 = new Produk ("C", "Mukenah", 5, 100000); + + + System.out.println("ID produk 1 : " + produk1.getId()); + System.out.println("Nama Produk : " + produk1.getNama()); + System.out.println("Jumlah Stok : " + produk1.getStok()); + System.out.println("Harga: RP." + produk1.getHarga()); + System.out.printf("Cek Stok: %s\n" , produk1.isAda() ? "Tersedia" : "Barang Kosong"); + + System.out.println("========================================"); + + System.out.println("ID produk 2 : " + produk2.getId()); + System.out.println("Nama Produk : " + produk2.getNama()); + System.out.println("Jumlah Stok : " + produk2.getStok()); + System.out.println("Harga: RP." + produk2.getHarga()); + System.out.printf("Cek Stok: %s\n" , produk2.isAda() ? "Tersedia" : "Barang Kosong"); + + System.out.println("======================================="); + + System.out.println("ID produk 3 : " + produk3.getId()); + System.out.println("Nama Produk : " + produk3.getNama()); + System.out.println("Jumlah Stok : " + produk3.getStok()); + System.out.println("Harga: RP." + produk3.getHarga()); + System.out.printf("Cek Stok: %s\n" ,produk3.isAda() ? "Tersedia" : "Barang Kosong"); + } +} \ No newline at end of file diff --git a/src/H071221092/Pertemuan_2/No4.java b/src/H071221092/Pertemuan_2/No4.java new file mode 100644 index 0000000..5a70487 --- /dev/null +++ b/src/H071221092/Pertemuan_2/No4.java @@ -0,0 +1,20 @@ +class Cuboid { + double height; + double widht; + double length; + + double getVolume(){ + return height * widht * length; + } +} + +public class No4 { + public static void main(String[] args) { + Cuboid cuboid = new Cuboid (); + cuboid.height = 10.0; + cuboid.widht = 30.0; + cuboid.length = 15.0; + + System.out.printf("Volume = %.2f", cuboid.getVolume()); + } +} \ No newline at end of file diff --git a/src/H071221092/Pertemuan_2/No5.java b/src/H071221092/Pertemuan_2/No5.java new file mode 100644 index 0000000..126153d --- /dev/null +++ b/src/H071221092/Pertemuan_2/No5.java @@ -0,0 +1,43 @@ +class Alamat { + String jalan; + String kota; + + public String getAlamatLengkap(){ + return this.jalan + "," + this.kota; + } +} + +class Mahasiswa { + Alamat alamat; + String nama; + String nim; + + public Alamat getAlamat () { + return this.alamat; + } + + public String getNama() { + return this.nama; + } + + public String getNim () { + return this.nim; + } +} + +public class No5 { + public static void main(String[] args) { + Alamat alamat = new Alamat () ; + alamat.jalan = "mana saja"; + alamat.kota = "Kota Makassar"; + + Mahasiswa mahasiswa = new Mahasiswa (); + mahasiswa.alamat = alamat; + mahasiswa.nama = "Fara Aulia Al Aini Syam"; + mahasiswa.nim = "H071221092"; + + System.out.println("Nama : " + mahasiswa.getNama()); + System.out.println("Nim : " + mahasiswa.getNim()); + System.out.println("Alamat : " + mahasiswa.getAlamat().getAlamatLengkap()); + } +} \ No newline at end of file diff --git a/src/H071221092/Pertemuan_3/No1.java b/src/H071221092/Pertemuan_3/No1.java new file mode 100644 index 0000000..4c69961 --- /dev/null +++ b/src/H071221092/Pertemuan_3/No1.java @@ -0,0 +1,78 @@ +public class No1 { + public static void main(String[] args) { + Stationary produk1 = new Stationary ("Pulpen", 3, 4000, new Diskon(90, "Diskon Ramadhan")); + Stationary produk2 = new Stationary ("Penggaris", 2, 2000, new Diskon(50, "Diskon Ramadhan")); + + produk1.tampilkanRincian(); + produk2.tampilkanRincian(); + + produk1.tambahBarang(4); + System.out.println("Setelah ditambahkan barang: " + "\n"); + produk2.tambahBarang(3); + System.out.println("Setelah ditambahkan barang: " + "\n"); + + produk1.tampilkanRincian(); + } +} + +class Stationary { + String barang ; + int jumlah ; + int harga ; + Diskon diskon ; + + public Stationary () {} + public Stationary (String barang, int jumlah, int harga, Diskon diskon ){ + this.barang = barang; + this.jumlah = jumlah; + this.harga = harga; + this.diskon = diskon; + } + public void setBarang (String barang){ + this.barang = barang; + } + public String getBarang () { + return barang; + } + public void setHarga (int harga){ + this.harga = harga; + } + public int getHarga (){ + return harga; + } + public void setJumlah (int jumlah){ + this.jumlah = jumlah; + } + public int getJumlah (){ + return jumlah; + } + public void setDiskon (Diskon diskon){ + this.diskon = diskon; + } + public Diskon getdiskon () { + return diskon; + } + //Behavior + public void tambahBarang(int barangTambahan) { + jumlah += barangTambahan; + } + public int diskonBarang () { + harga = harga-(diskon.persentaseDiskon * harga/100); + return harga; + } + public void tampilkanRincian (){ + System.out.println("========== Rincian Produk 1 =========="); + System.out.println("Nama barang : " + barang); + System.out.println("Jumlah barang : " + jumlah); + System.out.println("Harga barang : " + harga); + } +} + +class Diskon { + int persentaseDiskon; + String namaDiskon; + public Diskon (int persentaseDiskon, String namaDiskon) { + this.persentaseDiskon = persentaseDiskon; + this.namaDiskon = namaDiskon; + } +} diff --git a/src/H071221092/Pertemuan_3/No2.java b/src/H071221092/Pertemuan_3/No2.java new file mode 100644 index 0000000..709a542 --- /dev/null +++ b/src/H071221092/Pertemuan_3/No2.java @@ -0,0 +1,63 @@ +public class No2 { + 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(); + } +} + +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 defense){ // + this.name = name; + this.hp = 100; + this.defense = defense; + } + + public Player (String name,int defense,int attackPower){ + this(name, defense); + this.attackPower = attackPower; + } + + + 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 No2 { +// 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/H071221092/Pertemuan_3/No3.java b/src/H071221092/Pertemuan_3/No3.java new file mode 100644 index 0000000..c83a12d --- /dev/null +++ b/src/H071221092/Pertemuan_3/No3.java @@ -0,0 +1,36 @@ +public class No3{ + public static void main(String[] args) { + ObjekWisata objek = new ObjekWisata ("Dufan", "Jakarta", 120); + System.out.println(objek.nama); + System.out.println(objek.lokasi); + if (objek.isPopular()){ + System.out.println("Populer"); + } + else { + System.out.println("Tidak Populer"); + } + } +} + +class ObjekWisata{ + String nama; + String lokasi; + int pengunjung; + + public ObjekWisata () {} + public ObjekWisata (String nama, String lokasi, int pengunjung){ + this.nama = nama; + this.lokasi = lokasi; + this.pengunjung = 120; + + } + public boolean isPopular(){ + if (pengunjung >= 100){ + return true; + } + else { + return false; + } + } +} + diff --git a/src/H071221092/Pertemuan_4/No2.java b/src/H071221092/Pertemuan_4/No2.java new file mode 100644 index 0000000..97952c8 --- /dev/null +++ b/src/H071221092/Pertemuan_4/No2.java @@ -0,0 +1,86 @@ +public class No2{ + public static void main(String[] args) { + Player player = new Player(); + System.out.println("========== PLAYER 1 =========="); + player.setName("Miya"); //memberi nilai ke objek menggunakan setter + player.setLevel(2); + player.setHealth(250); + player.setMana(350); + player.setExp(450); + player.displayinfo(); + System.out.println("========== PLAYER 2 =========="); + Player player2 = new Player("Lancelot", 3, 200, 300, 400); + System.out.println("Nama : " + player2.getName()); //Mengambil nilai objek menggunakan getter + System.out.println("Level : " + player2.getLevel()); + System.out.println("Health : " + player2.getHealth()); + System.out.println("Mana :" + player2.getMana()); + System.out.println("Exp : " + player2.getExp()); + System.out.println("============ DATA ============"); + Utils.displaySelfData(); //Mamanggil method static tanpa instance objek + // Utils utils = new Utils (); + // utils.displaySelfData(); + } +} + +class Player{ + private String name; + private int level; + private int health; + private int mana; + private int exp; + + public Player (){} //constroctur kosong + public Player (String name, int level, int health, int mana, int exp){ + this.name = name; + this.level = level; + this.health = health; + this.mana = mana; + this.exp = exp; + } + public void setName (String name){ + this.name = name; + } + public String getName(){ + return name; + } + public void setLevel (int level){ + this.level = level; + } + public int getLevel (){ + return level; + } + public void setHealth (int health){ + this.health = health; + } + public int getHealth (){ + return health; + } + public void setMana (int mana){ + this.mana = mana; + } + public int getMana (){ + return mana; + } + public void setExp (int exp){ + this.exp = exp; + } + public int getExp (){ + return exp; + } + + //behavior + public void displayinfo(){ + System.out.println("Name : " + name); + System.out.println("Level : " + level); + System.out.println("Health : " + health); + System.out.println("Mana : " + mana); + System.out.println("Exp : " + exp); + } +} + +class Utils{ //static method + public static void displaySelfData() { + System.out.println("Nama : Fara Aulia Al Aini Syam"); + System.out.println("NIm : H071221092"); + } +} diff --git a/src/H071221092/Pertemuan_4/login_app/Main.java b/src/H071221092/Pertemuan_4/login_app/Main.java new file mode 100644 index 0000000..494b3cc --- /dev/null +++ b/src/H071221092/Pertemuan_4/login_app/Main.java @@ -0,0 +1,179 @@ +package login_app; + +import java.util.ArrayList; +import java.util.Scanner; +import login_app.models.Profile; +import login_app.models.User; +import login_app.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); //scanner untuk input + + 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(); //input username + // 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 sudah diinput. + * Jika ada ganti userIndex dengan Index dari User Tersebut, kemudian hentikan + * perulangan + */ + if (listUser.get(i).getUsername().equals(username)){ //equels membandingkan 2 string + userIndex = i; //supaya ditau di dalam list userindex mana yg sama dengan yg sdh diinput + 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"); + /* + * 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()); + } +} \ No newline at end of file diff --git a/src/H071221092/Pertemuan_4/login_app/models/Profile.java b/src/H071221092/Pertemuan_4/login_app/models/Profile.java new file mode 100644 index 0000000..34c8158 --- /dev/null +++ b/src/H071221092/Pertemuan_4/login_app/models/Profile.java @@ -0,0 +1,38 @@ +package login_app.models; + +public class Profile { + private String fullName; + private int age; + private String hobby; + private String nickname; + + 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; + } +} + /* + * TODO: + * Tambahkan attribute, method, atau constructor + * yang dibutuhkan di kelas user + */ \ No newline at end of file diff --git a/src/H071221092/Pertemuan_4/login_app/models/User.java b/src/H071221092/Pertemuan_4/login_app/models/User.java new file mode 100644 index 0000000..670f69e --- /dev/null +++ b/src/H071221092/Pertemuan_4/login_app/models/User.java @@ -0,0 +1,28 @@ +package login_app.models; + +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/H071221092/Pertemuan_4/login_app/utils/StringUtils.java b/src/H071221092/Pertemuan_4/login_app/utils/StringUtils.java new file mode 100644 index 0000000..613eac7 --- /dev/null +++ b/src/H071221092/Pertemuan_4/login_app/utils/StringUtils.java @@ -0,0 +1,24 @@ +package login_app.utils; + +public class StringUtils { + public static String generateNickName(String fullName){ //method static + String[] nameParts = fullName.split(" "); //memecah fullname menjadi beberapa bagian menggunakan split + + if (nameParts.length ==1) { //memeriksa apakah hanya satu elemen jika iya langsung return fullname + return fullName; + }else{ + return nameParts[1]; + } + } +} + /* + 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) + */ \ No newline at end of file diff --git a/src/H071221092/Pertemuan_5/.vscode/extensions.json b/src/H071221092/Pertemuan_5/.vscode/extensions.json new file mode 100644 index 0000000..70f4ee7 --- /dev/null +++ b/src/H071221092/Pertemuan_5/.vscode/extensions.json @@ -0,0 +1,6 @@ +{ + "recommendations": [ + "visualstudioexptteam.vscodeintellicode", + "visualstudioexptteam.intellicode-api-usage-examples" + ] +} \ No newline at end of file diff --git a/src/H071221092/Pertemuan_5/Diagram Anggota.jpeg b/src/H071221092/Pertemuan_5/Diagram Anggota.jpeg new file mode 100644 index 0000000..178169e Binary files /dev/null and b/src/H071221092/Pertemuan_5/Diagram Anggota.jpeg differ diff --git a/src/H071221092/Pertemuan_5/Diagram Bangun.jpeg b/src/H071221092/Pertemuan_5/Diagram Bangun.jpeg new file mode 100644 index 0000000..f0e90aa Binary files /dev/null and b/src/H071221092/Pertemuan_5/Diagram Bangun.jpeg differ diff --git a/src/H071221092/Pertemuan_5/No1/Balok.java b/src/H071221092/Pertemuan_5/No1/Balok.java new file mode 100644 index 0000000..1e4e122 --- /dev/null +++ b/src/H071221092/Pertemuan_5/No1/Balok.java @@ -0,0 +1,14 @@ +public class Balok extends BangunRuang{ + private double panjang; + private double lebar; + private double tinggi; + public Balok (double panjang, double lebar, double tinggi){ + super(panjang, lebar, tinggi); //dia akan panggil nila3 + } + public double getVolume (){ + return panjang*lebar*tinggi; + } + public double getLuasPermukaan(){ + return 2+panjang*lebar+lebar*tinggi*panjang*tinggi; + } +} \ No newline at end of file diff --git a/src/H071221092/Pertemuan_5/No1/BangunDatar.java b/src/H071221092/Pertemuan_5/No1/BangunDatar.java new file mode 100644 index 0000000..98a84fb --- /dev/null +++ b/src/H071221092/Pertemuan_5/No1/BangunDatar.java @@ -0,0 +1,25 @@ +public class BangunDatar { + protected double luas; + protected double keliling; + protected double nilai1, nilai2, nilai3; + + public BangunDatar(){} + public BangunDatar(double nilai1){ + this.nilai1 = nilai1; + } + public BangunDatar(double nilai1, double nilai2){ + this.nilai1 = nilai1; + this.nilai2 = nilai2; + } + public BangunDatar(double nilai1, double nilai2, double nilai3){ + this.nilai1 = nilai1; + this.nilai2 = nilai2; + this.nilai3 = nilai3; + } + public double getLuas (){ + return luas; + } + public double getKeliling (){ + return keliling; + } +} diff --git a/src/H071221092/Pertemuan_5/No1/BangunRuang.java b/src/H071221092/Pertemuan_5/No1/BangunRuang.java new file mode 100644 index 0000000..383e189 --- /dev/null +++ b/src/H071221092/Pertemuan_5/No1/BangunRuang.java @@ -0,0 +1,25 @@ +public class BangunRuang{ + protected double volume; + protected double luaspermukaan; + protected double nilai1, nilai2, nilai3, nilai4; + + public BangunRuang(){} + public BangunRuang(double nilai1){ + this.nilai1 = nilai1; + } + public BangunRuang(double nilai1, double nilai2){ + this.nilai1 = nilai1; + this.nilai2 = nilai2; + } + public BangunRuang(double nilai1, double nilai2, double nilai3){ + this.nilai1 = nilai1; + this.nilai2 = nilai2; + this.nilai3 = nilai3; + } + public double getVolume (){ + return volume; + } + public double getLuasPermukaan (){ + return luaspermukaan; + } +} \ No newline at end of file diff --git a/src/H071221092/Pertemuan_5/No1/Bola.java b/src/H071221092/Pertemuan_5/No1/Bola.java new file mode 100644 index 0000000..719926a --- /dev/null +++ b/src/H071221092/Pertemuan_5/No1/Bola.java @@ -0,0 +1,11 @@ +public class Bola extends BangunRuang{ + public Bola (double jarijari){ + super(jarijari); //dia akan panggil nila1 + } + public double getVolume (){ + return 1.3*Math.PI*nilai1*nilai1*nilai1; + } + public double getLuasPermukaan(){ + return 4*Math.PI*nilai1*nilai1; + } +} \ No newline at end of file diff --git a/src/H071221092/Pertemuan_5/No1/Kubus.java b/src/H071221092/Pertemuan_5/No1/Kubus.java new file mode 100644 index 0000000..c6073f9 --- /dev/null +++ b/src/H071221092/Pertemuan_5/No1/Kubus.java @@ -0,0 +1,11 @@ +public class Kubus extends BangunRuang{ + public Kubus (double sisi){ + super(sisi); //dia akan panggil nilai1 + } + public double getVolume (){ + return nilai1*nilai1*nilai1; + } + public double getLuasPermukaan(){ + return 6*nilai1*nilai1; + } +} diff --git a/src/H071221092/Pertemuan_5/No1/Lingkaran.java b/src/H071221092/Pertemuan_5/No1/Lingkaran.java new file mode 100644 index 0000000..4503a0d --- /dev/null +++ b/src/H071221092/Pertemuan_5/No1/Lingkaran.java @@ -0,0 +1,11 @@ +public class Lingkaran extends BangunDatar{ + public Lingkaran (double jarijari){ + super(jarijari); + } + public double getLuas (){ + return Math.PI*nilai1*nilai1; + } + public double getKeliling (){ + return 2*Math.PI*nilai1; + } +} diff --git a/src/H071221092/Pertemuan_5/No1/Main.java b/src/H071221092/Pertemuan_5/No1/Main.java new file mode 100644 index 0000000..b40c7d3 --- /dev/null +++ b/src/H071221092/Pertemuan_5/No1/Main.java @@ -0,0 +1,70 @@ +public class Main { + public static void main(String[] args) { + 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("===== BANGUN RUANG ====="); + 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("10. KELUAR"); + + Scanner sc = new Scanner (System.in); + System.out.println("Masukkan pilihan: "); + int bangun = sc.nextInt(); + + switch (bangun){ + case 1: + Kubus kubus = new Kubus (7); + System.out.println("LP : " + kubus.getLuasPermukaan()); + System.out.println("Volume : " + kubus.getVolume()); + break; + case 2: + Balok balok = new Balok (9); + System.out.println("LP : " + balok.getLuasPermukaan()); + System.out.println("Volume : " + balok.Volume); + break; + case 3: + Bola bola = new Bola (3); + System.out.println("LP : " + bola.getLuasPermukaan()); + System.out.println("Volume : " + bola.Volume()); + break; + case 4: + Tabung tabung = new Tabung (11); + System.out.println("LP : " + tabung.getLuasPermukaan()); + System.out.println("Volume : " + tabung.getVolume); + break; + case 5: + Persegi persegi = new Persegi(2); + System.out.println("Luas : " + persegi.getLuas()); + System.out.println("Keliling : " + persegi.getKeliling()); + break; + case 6: + PersegiPanjang persegipanjang = new PersegiPanjang(3,4); + System.out.println("Luas : " + persegipanjang.getLuas()); + System.out.println("Keliling : " + persegipanjang.getKeliling()); + break; + case 7: + Lingkaran lingkaran = new Lingkaran (4); + System.out.println("Luas : " + lingkaran.getLuas()); + System.out.println("Keliling : " + lingkaran.getKeliling()); + break; + case 8: + Segitiga segitiga = new Segitiga (5,5); + System.out.println("Luas : " + segitiga.getLuas()); + System.out.println("Keliling : " + segitiga.getKeliling()); + break; + case 9: + Trapesium trapesium = new Trapesium (9,5); + System.out.println("Luas : " + trapesium.getLuas()); + System.out.println("Keliling : " + trapesium.getKeliling()); + break; + default: + System.out.println("Masukkan Angka yang tersedia"); + } + } +} diff --git a/src/H071221092/Pertemuan_5/No1/Persegi.java b/src/H071221092/Pertemuan_5/No1/Persegi.java new file mode 100644 index 0000000..06de53d --- /dev/null +++ b/src/H071221092/Pertemuan_5/No1/Persegi.java @@ -0,0 +1,11 @@ +public class Persegi extends BangunDatar { + public Persegi (double sisi){ + super(sisi); + } + public double getLuas (){ + return nilai1*nilai1; + } + public double getKeliling (){ + return 4*nilai1; + } +} diff --git a/src/H071221092/Pertemuan_5/No1/PersegiPanjang.java b/src/H071221092/Pertemuan_5/No1/PersegiPanjang.java new file mode 100644 index 0000000..9d5e227 --- /dev/null +++ b/src/H071221092/Pertemuan_5/No1/PersegiPanjang.java @@ -0,0 +1,11 @@ +public class PersegiPanjang extends BangunDatar{ + public PersegiPanjang (double panjang, double lebar){ + super(panjang, lebar); + } + public double getLuas (){ + return nilai2*nilai2; + } + public double getKeliling (){ + return 2*(nilai2+nilai2); + } +} diff --git a/src/H071221092/Pertemuan_5/No1/Segitiga.java b/src/H071221092/Pertemuan_5/No1/Segitiga.java new file mode 100644 index 0000000..52ddd1c --- /dev/null +++ b/src/H071221092/Pertemuan_5/No1/Segitiga.java @@ -0,0 +1,11 @@ +public class Segitiga extends BangunDatar{ + public Segitiga (double alas, double tinggi, double sisi){ + super(alas, tinggi, sisi); + } + public double getLuas (){ + return 0.5*nilai1*nilai2; + } + public double getKeliling (){ + return nilai3+nilai3+nilai3; + } +} diff --git a/src/H071221092/Pertemuan_5/No1/Tabung.java b/src/H071221092/Pertemuan_5/No1/Tabung.java new file mode 100644 index 0000000..cc1d34c --- /dev/null +++ b/src/H071221092/Pertemuan_5/No1/Tabung.java @@ -0,0 +1,11 @@ +public class Tabung extends BangunRuang{ + public Tabung (double tinggi, double jarijari) { + super(tinggi, jarijari); //dia akan panggil nilai4 + } + public double getVolume (){ + return Math.PI*nilai2*nilai2*nilai1; + } + public double getLuasPermukaan(){ + return (2*Math.PI*nilai2)*(nilai2*nilai1); + } +} \ No newline at end of file diff --git a/src/H071221092/Pertemuan_5/No1/Trapesium.java b/src/H071221092/Pertemuan_5/No1/Trapesium.java new file mode 100644 index 0000000..f1a5cb6 --- /dev/null +++ b/src/H071221092/Pertemuan_5/No1/Trapesium.java @@ -0,0 +1,11 @@ +public class Trapesium extends BangunRuang{ + public Trapesium (double sisi, double tinggi){ + super(sisi, tinggi); + } + public double getLuas (){ + return 0.5*(nilai1+nilai1)*nilai2; + } + public double getKeliling (){ + return nilai1+nilai1+nilai1+nilai1; + } +} diff --git a/src/H071221092/Pertemuan_5/No2/Anggota.java b/src/H071221092/Pertemuan_5/No2/Anggota.java new file mode 100644 index 0000000..801bc6f --- /dev/null +++ b/src/H071221092/Pertemuan_5/No2/Anggota.java @@ -0,0 +1,29 @@ +class Anggota{ + private String nama; + private int umur; + private String alamat; + + public Anggota(String nama, int umur, String alamat) { + this.nama = nama; + this.umur = umur; + this.alamat = alamat; + } + public String getNama() { + return nama; + } + public void setNama(String nama) { + this.nama = nama; + } + public int getUmur() { + return umur; + } + public void setUmur(int umur) { + this.umur = umur; + } + public String getAlamat (){ + return alamat; + } + public void setAlamat (String alamat){ + this.alamat = alamat; + } +} \ No newline at end of file diff --git a/src/H071221092/Pertemuan_5/No2/Koordinator.java b/src/H071221092/Pertemuan_5/No2/Koordinator.java new file mode 100644 index 0000000..db04452 --- /dev/null +++ b/src/H071221092/Pertemuan_5/No2/Koordinator.java @@ -0,0 +1,13 @@ +public class Koordinator extends Anggota{ + private String bidangstaf; + public Koordinator(String nama, int umur, String alamat,String bidangstaf) { + super(nama, umur, alamat); + this.bidangstaf = bidangstaf; + } + public String getBidangstaf() { + return bidangstaf; + } + public void setBidangstaf(String bidangstaf) { + this.bidangstaf = bidangstaf; + } +} diff --git a/src/H071221092/Pertemuan_5/No2/Mainn.java b/src/H071221092/Pertemuan_5/No2/Mainn.java new file mode 100644 index 0000000..4439bfd --- /dev/null +++ b/src/H071221092/Pertemuan_5/No2/Mainn.java @@ -0,0 +1,16 @@ +public class Mainn { + public static void main(String[] args) { //method yang dapat dipakai tanpa harus mendeklarasikan suatu class + System.out.println("===== PENGURUS INTI ====="); + PengurusInti pengurusInti = new PengurusInti("Ayya", 18, "Wanita", "Ketua"); + System.out.println("Nama : " + pengurusInti.getNama()); + System.out.println("Umur : " + pengurusInti.getUmur()); + System.out.println("Alamat : " + pengurusInti.getAlamat()); + System.out.println("Jabatan : " + pengurusInti.getJabatan()); + System.out.println("====== KOORDINATOR ======"); + Koordinator koordinasiBidangStaff = new Koordinator("Fara", 18,"Wanita", "Humas"); + System.out.println("Nama : " + koordinasiBidangStaff.getNama()); + System.out.println("Umur : " + koordinasiBidangStaff.getUmur()); + System.out.println("Alamat : " + koordinasiBidangStaff.getAlamat()); + System.out.println("Bidang : " + koordinasiBidangStaff.getBidangstaf()); + } +} diff --git a/src/H071221092/Pertemuan_5/No2/PengurusInti.java b/src/H071221092/Pertemuan_5/No2/PengurusInti.java new file mode 100644 index 0000000..8dcbaa2 --- /dev/null +++ b/src/H071221092/Pertemuan_5/No2/PengurusInti.java @@ -0,0 +1,14 @@ +public class PengurusInti extends Anggota{ + private String jabatan; + + public PengurusInti(String nama, int umur, String alamat,String jabatan) { + super(nama, umur, alamat); + this.jabatan = jabatan; + } + public String getJabatan() { + return jabatan; + } + public void setJabatan(String jabatan) { + this.jabatan = jabatan; + } +} diff --git a/src/H071221092/Pertemuan_6/Bulldog.java b/src/H071221092/Pertemuan_6/Bulldog.java new file mode 100644 index 0000000..5e373e3 --- /dev/null +++ b/src/H071221092/Pertemuan_6/Bulldog.java @@ -0,0 +1,13 @@ +class Bulldog extends Dog { + public Bulldog(int position, int averageLength){ + super(position, averageLength); + } + @Override + public void move() { + position +=1; + } + @Override + void describe() { + System.out.println("Memiliki mata yang bulat, berkaki pendek, hidung berwarna hitam, dll."); + } +} \ No newline at end of file diff --git a/src/H071221092/Pertemuan_6/Car.java b/src/H071221092/Pertemuan_6/Car.java new file mode 100644 index 0000000..ff641ee --- /dev/null +++ b/src/H071221092/Pertemuan_6/Car.java @@ -0,0 +1,33 @@ +public class Car implements Moveable { + 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; + } + + public void move () { + System.out.println("Mobil sedang berakselerasi"); + } +} diff --git a/src/H071221092/Pertemuan_6/Dog.java b/src/H071221092/Pertemuan_6/Dog.java new file mode 100644 index 0000000..2b8fa32 --- /dev/null +++ b/src/H071221092/Pertemuan_6/Dog.java @@ -0,0 +1,24 @@ +abstract class Dog implements Moveable { + protected int position; + protected int averageLength; + + abstract void describe();// disimpan di abstract karena sebagai implementasi untuk child class + + public Dog(int position, int averageLength) { + this.position = position; + this.averageLength = averageLength; + } + public int getPosition() { + return position; + } + public void setPosition(int position) { + this.position = position; + } + public int getAverageLength() { + return averageLength; + } + public void setAverageLength(int averageLength) { + this.averageLength = averageLength; + } +} + diff --git a/src/H071221092/Pertemuan_6/GermanShepherd.java b/src/H071221092/Pertemuan_6/GermanShepherd.java new file mode 100644 index 0000000..529c291 --- /dev/null +++ b/src/H071221092/Pertemuan_6/GermanShepherd.java @@ -0,0 +1,14 @@ +public class GermanShepherd extends Dog { + public GermanShepherd(int position, int averageLength){ + super(position, averageLength); + } + + @Override + public void move() { + position +=3; + } + @Override + void describe() { + System.out.println("Memiliki tubuh yang panjang, mata berbentuk almond, Telinga tegak, dll."); + } +} \ No newline at end of file diff --git a/src/H071221092/Pertemuan_6/Main.java b/src/H071221092/Pertemuan_6/Main.java new file mode 100644 index 0000000..b463bed --- /dev/null +++ b/src/H071221092/Pertemuan_6/Main.java @@ -0,0 +1,19 @@ +public class Main { + public static void main(String[] args) { + System.out.println("========== BULLDOG =========="); + Bulldog bulldog = new Bulldog(12, 5); + bulldog.move(); + bulldog.describe(); + System.out.println("========== SMARTPHONE =========="); + Smartphone hp = new Smartphone(9900, "Iphone"); + System.out.println("Price: " + hp.getPrice()); + System.out.println("Brand: " + hp.getBrand()); + hp.move(); + System.out.println("========== CAR =========="); + Car car = new Car (12, "red", 10); + System.out.println("Total Forward Gear: " + car.getTotalForwardGear()); + System.out.println("Color: " + car.getColor()); + System.out.println("Max Speed: " + car.getMaxSpeed()); + car.move(); + } +} diff --git a/src/H071221092/Pertemuan_6/Moveable.java b/src/H071221092/Pertemuan_6/Moveable.java new file mode 100644 index 0000000..90ccdf5 --- /dev/null +++ b/src/H071221092/Pertemuan_6/Moveable.java @@ -0,0 +1,3 @@ +interface Moveable { + void move(); +} \ No newline at end of file diff --git a/src/H071221092/Pertemuan_6/Pitbull.java b/src/H071221092/Pertemuan_6/Pitbull.java new file mode 100644 index 0000000..21a9d8a --- /dev/null +++ b/src/H071221092/Pertemuan_6/Pitbull.java @@ -0,0 +1,15 @@ +class Pitbull extends Dog { + public Pitbull(int position, int averageLength){ + super(position, averageLength); + } + + @Override + public void move() { + position += 3; + } + + @Override + void describe() { + System.out.println("Memiliki rahang yang kuat, aktif, tidak menyerang tanpa sebab, dll."); + } +} \ No newline at end of file diff --git a/src/H071221092/Pertemuan_6/SeiberianHusky.java b/src/H071221092/Pertemuan_6/SeiberianHusky.java new file mode 100644 index 0000000..ec06831 --- /dev/null +++ b/src/H071221092/Pertemuan_6/SeiberianHusky.java @@ -0,0 +1,13 @@ +class SiberianHusky extends Dog { + public SiberianHusky(int position, int averageLength){ + super(position, averageLength); + } + @Override + public void move() { + position +=2; + } + @Override + void describe() { + System.out.println("Memiliki bulu yang lumayan lebat dan berwarna belang hitam, putih, abu, aktif, ramah, dll"); + } +} \ No newline at end of file diff --git a/src/H071221092/Pertemuan_6/Smartphone.java b/src/H071221092/Pertemuan_6/Smartphone.java new file mode 100644 index 0000000..96c0520 --- /dev/null +++ b/src/H071221092/Pertemuan_6/Smartphone.java @@ -0,0 +1,24 @@ +public class Smartphone implements Moveable{ + 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; + } + public void move (){ + System.out.println("Smartphone berpindah"); + } +} diff --git a/src/H071221092/Pertemuan_7/No1/Character.java b/src/H071221092/Pertemuan_7/No1/Character.java new file mode 100644 index 0000000..b13f02e --- /dev/null +++ b/src/H071221092/Pertemuan_7/No1/Character.java @@ -0,0 +1,23 @@ +package No1; + +abstract class Character { + protected String name; + protected int attackPower; + + public String getName() { + return name; + } + + public int getAttackPower() { + return attackPower; + } + + public Character(String name, int attackPower) { + this.name = name; + this.attackPower = attackPower; + } + + abstract int attack(); + + abstract int attack(String attackType); +} \ No newline at end of file diff --git a/src/H071221092/Pertemuan_7/No1/Fighter.java b/src/H071221092/Pertemuan_7/No1/Fighter.java new file mode 100644 index 0000000..d767d02 --- /dev/null +++ b/src/H071221092/Pertemuan_7/No1/Fighter.java @@ -0,0 +1,20 @@ +package No1; + +public class Fighter extends Character{ + public Fighter(String name, int attackPower){ + super(name, attackPower); + } + int attack(){ + return attackPower; + } + int attack (String attackType) { + int ap = attackPower; + if (attackType.equals("Male")){ + ap = attackPower*2; + } + else if (attackType.equals("Ranged")){ + ap = attackPower; + } + return ap; + } +} \ No newline at end of file diff --git a/src/H071221092/Pertemuan_7/No1/Mage.java b/src/H071221092/Pertemuan_7/No1/Mage.java new file mode 100644 index 0000000..20bd3aa --- /dev/null +++ b/src/H071221092/Pertemuan_7/No1/Mage.java @@ -0,0 +1,24 @@ +package No1; + +public class Mage extends Character { + public Mage(String name, int attackPower){ + super(name, attackPower); + } + + @Override + int attack(){ + return attackPower; + } + + int attack (String attackType){ + int ap = attackPower; + if (attackType.equals("Fire")){ + ap = attackPower*3; + } + else if(attackType.equals("Frost")){ + ap = attackPower*2; + } + return ap; + } +} + diff --git a/src/H071221092/Pertemuan_7/No1/Main.java b/src/H071221092/Pertemuan_7/No1/Main.java new file mode 100644 index 0000000..965d241 --- /dev/null +++ b/src/H071221092/Pertemuan_7/No1/Main.java @@ -0,0 +1,35 @@ +package No1; + +public class Main { + public static void printAttack(Character character) { + System.out.println("Nama : " + character.getName()); + System.out.println("<==ATTACK INFORMATION==>"); + System.out.println("Attack Power : " + character.attackPower); + if (character instanceof Fighter) { + System.out.println("Mele : " + character.attack("Mele")); + System.out.println("Ranged : " + character.attack("Ranged")); + } else if (character instanceof Mage) { //instanceof untuk cek tipe objek atau karakter + System.out.println("Fire : " + character.attack("Fire")); + System.out.println("Frost : " + character.attack("Frost")); + } + } + public static void main(String[] args) { + + Character[] hero = new Character[5]; + hero[0] = new Fighter("Fara", 10); + hero[1] = new Mage("Aulia", 20); + hero[2] = new Fighter("Al Aini", 30); + hero[3] = new Fighter("Syam", 40); + hero[4] = new Mage("Ayya", 50); + + + // for (Character i : hero) { + // printAttack(i); + // System.out.println(""); + // } + + for (int i = 0; i product1 = new Product<>("Pizza", "Rp 1000", "12-12-2022"); + Product product2 = new Product<>("Burger", 2000, "12-01-2020"); + Product product3 = new Product<>("Ciki", 12.12, "13-03-2020"); + + System.out.println("===== Produk 1 ====="); + System.out.println("Nama: " + product1.getName()); + System.out.println("Harga: " + product1.getPrice()); + System.out.println("Tanggal Kadaluarsa: " + product1.getExpDate()); + System.out.println(); + + System.out.println("===== Produk 2 ====="); + System.out.println("Nama: " + product2.getName()); + System.out.println("Harga: " + product2.getPrice()); + System.out.println("Tanggal Kadaluarsa: " + product2.getExpDate()); + System.out.println(); + + System.out.println("===== Produk 3 ====="); + System.out.println("Nama: " + product3.getName()); + System.out.println("Harga: " + product3.getPrice()); + System.out.println("Tanggal Kadaluarsa: " + product3.getExpDate()); + System.out.println(); + } +} + +class Product { // generic bisa lebih dari 1 variabel + protected String name; + protected A price; + protected String expDate; + + public Product (String name, A price, String expDate){ + this.name = name; + this.price = price; + this.expDate = expDate; + } + public String getName(){ + return name; + } + public A getPrice(){ + return price; + } + public String getExpDate(){ + return expDate; + } +} \ No newline at end of file diff --git a/src/H071221092/Pertemuan_7/No2/Product.java b/src/H071221092/Pertemuan_7/No2/Product.java new file mode 100644 index 0000000..9671ae6 --- /dev/null +++ b/src/H071221092/Pertemuan_7/No2/Product.java @@ -0,0 +1,4 @@ +package No2; + +import java.util.Date; + diff --git a/src/H071221092/Pertemuan_7/No3/No3.java b/src/H071221092/Pertemuan_7/No3/No3.java new file mode 100644 index 0000000..b10a021 --- /dev/null +++ b/src/H071221092/Pertemuan_7/No3/No3.java @@ -0,0 +1,73 @@ +import java.util.ArrayList; +import java.util.List; + +public class No3{ + public static void main(String[] args) { + Food burger = FoodFactory.getFood(FoodType.burger); + Food pizza = FoodFactory.getFood(FoodType.pizza); + Food steak = FoodFactory.getFood(FoodType.steak); + + List foods = new ArrayList<>(); + foods.add(burger); + foods.add(pizza); + foods.add(steak); + + int total = Restaurant.kalkulTotal(foods); + System.out.println("Total price: "+ total); + } +} + +class FoodFactory{ //poli itu klaas anak bs dsmpn diparent + static Food getFood(FoodType food){ + if (food == FoodType.burger){ + return new Burger(); + }else if (food == FoodType.pizza){ + return new Pizza(); + }else if (food == FoodType.steak){ + return new Steak(); + }else{ + System.out.println("Error"); + return null; + } + } +} + +interface Food{ + public int getPrice(); +} + +class Burger implements Food{ + + @Override + public int getPrice() { + return 50000; + } +} +class Pizza implements Food{ + + @Override + public int getPrice() { + return 100000; + } +} +class Steak implements Food{ + + @Override + public int getPrice() { + return 70000; + } +} + +class Restaurant{ + static int kalkulTotal(List foods){ + int totalPrice = 0; + for (Food food : foods){ + totalPrice += food.getPrice(); + } + return totalPrice; + } +} + +enum FoodType{ //kategori + burger, pizza, steak +} \ No newline at end of file diff --git a/src/H071221092/Pertemuan_8/AppRacer.java b/src/H071221092/Pertemuan_8/AppRacer.java new file mode 100644 index 0000000..5468cc1 --- /dev/null +++ b/src/H071221092/Pertemuan_8/AppRacer.java @@ -0,0 +1,197 @@ +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/H071221092/Pertemuan_8/TugasPraktikum.java b/src/H071221092/Pertemuan_8/TugasPraktikum.java new file mode 100644 index 0000000..4864cd0 --- /dev/null +++ b/src/H071221092/Pertemuan_8/TugasPraktikum.java @@ -0,0 +1,101 @@ +package no3; + +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/H071221092/Pertemuan_9/.gitattributes b/src/H071221092/Pertemuan_9/.gitattributes new file mode 100644 index 0000000..097f9f9 --- /dev/null +++ b/src/H071221092/Pertemuan_9/.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/H071221092/Pertemuan_9/.gitignore b/src/H071221092/Pertemuan_9/.gitignore new file mode 100644 index 0000000..1b6985c --- /dev/null +++ b/src/H071221092/Pertemuan_9/.gitignore @@ -0,0 +1,5 @@ +# Ignore Gradle project-specific cache directory +.gradle + +# Ignore Gradle build output directory +build diff --git a/src/H071221092/Pertemuan_9/.vscode/settings.json b/src/H071221092/Pertemuan_9/.vscode/settings.json new file mode 100644 index 0000000..c5f3f6b --- /dev/null +++ b/src/H071221092/Pertemuan_9/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.configuration.updateBuildConfiguration": "interactive" +} \ No newline at end of file diff --git a/src/H071221092/Pertemuan_9/app/bin/main/bgkalkul.jpg b/src/H071221092/Pertemuan_9/app/bin/main/bgkalkul.jpg new file mode 100644 index 0000000..2c9fa4f Binary files /dev/null and b/src/H071221092/Pertemuan_9/app/bin/main/bgkalkul.jpg differ diff --git a/src/H071221092/Pertemuan_9/app/bin/main/styles/style.css b/src/H071221092/Pertemuan_9/app/bin/main/styles/style.css new file mode 100644 index 0000000..0599c5e --- /dev/null +++ b/src/H071221092/Pertemuan_9/app/bin/main/styles/style.css @@ -0,0 +1,3 @@ +#section-right{ + -fx-background-color: #a75757; +} \ No newline at end of file diff --git a/src/H071221092/Pertemuan_9/app/build.gradle b/src/H071221092/Pertemuan_9/app/build.gradle new file mode 100644 index 0000000..e19c6cd --- /dev/null +++ b/src/H071221092/Pertemuan_9/app/build.gradle @@ -0,0 +1,48 @@ +/* + * This file was generated by the Gradle 'init' task. + * + * This generated file contains a sample Java application project to get you started. + * For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle + * User Manual available at https://docs.gradle.org/8.1.1/userguide/building_java_projects.html + */ + + +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 = 'kalkulator.App' +} + +tasks.named('test') { + // Use JUnit Platform for unit tests. + useJUnitPlatform() +} diff --git a/src/H071221092/Pertemuan_9/app/src/main/java/kalkulator/App.java b/src/H071221092/Pertemuan_9/app/src/main/java/kalkulator/App.java new file mode 100644 index 0000000..2930ec1 --- /dev/null +++ b/src/H071221092/Pertemuan_9/app/src/main/java/kalkulator/App.java @@ -0,0 +1,168 @@ +/* + * This Java source file was generated by the Gradle 'init' task. + */ +package kalkulator; + +import javafx.application.Application; +import javafx.scene.image.ImageView; +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.StackPane; +import javafx.scene.layout.VBox; +import javafx.scene.text.Font; +import javafx.stage.Stage; + +public class App extends Application { + + @Override + public void start(Stage stage) throws Exception { + //mulai coding + + VBox vbox = new VBox(); + + Label judul = new Label ("CALCULATOR"); + judul.setFont(Font.font("Arial", 23)); + vbox.getChildren().add(judul); + vbox.setSpacing(12.5); + + Button tombol = new Button("start"); + tombol.getStyleClass().add("tombol"); + vbox.getChildren().add(tombol); + vbox.setAlignment(Pos.CENTER); + + tombol.setOnAction(action -> { + layarOpsi(stage); + }); + + // VBox secRight = new VBox (judul, tombol); + // secRight.setSpacing(8); + // secRight.setAlignment(Pos.CENTER); + // secRight.setPrefWidth(320); + // secRight.setId("s"); + + ImageView ivBanner = new ImageView("/bgkalkul.jpg"); + ivBanner.setFitWidth(320); + ivBanner.setFitHeight(512); + ivBanner.setPreserveRatio(true); + + StackPane backg = new StackPane(ivBanner, vbox); + // VBox rootNode = new VBox (ivBanner, vbox); + + // Scene gmbr = new Scene(rootNode, 320, 512); + // return gmbr; + + Scene scene = new Scene(backg, 320, 512); + stage.setScene(scene); + stage.setTitle("Kalkul"); + stage.show(); + } + + public void layarOpsi (Stage stage){ + VBox vbox = new VBox(); + vbox.setId("section-right"); + Label opsiLabel = new Label("MENU"); + opsiLabel.setFont(Font.font("Arial",23)); + vbox.getChildren().add(opsiLabel); + vbox.setSpacing(12.5); + + Button kalkulSuhu = new Button ("Kalkulator Suhu"); + kalkulSuhu.getStyleClass().add("kalkulSuhu"); + vbox.getChildren().add(kalkulSuhu); + vbox.setAlignment(Pos.CENTER); + vbox.setSpacing(12.5); + + kalkulSuhu.setOnAction(action -> { + kalkulSuhu(stage); + }); + + Button kalkulJarak = new Button ("Kalkulator Jarak"); + kalkulJarak.getStyleClass().add("kalkulJarak"); + vbox.getChildren().add(kalkulJarak); + vbox.setAlignment(Pos.CENTER); + vbox.setSpacing(12.5); + + kalkulJarak.setOnAction(action ->{ + kalkulJarak(stage); + }); + + Scene scene = new Scene(vbox, 320, 512); + scene.getStylesheets().add(getClass().getResource("/styles/style.css").toExternalForm()); + stage.setScene(scene); + stage.show(); + } + + public void kalkulSuhu (Stage stage){ + Label judulSuhu = new Label ("KALKULATOR SUHU CELCIUS ke REAMUR"); + judulSuhu.setFont(Font.font("Arial", 15)); + + TextField tfCelcius = new TextField(); + tfCelcius.setPromptText("Celcius"); + + Button tombolProses = new Button ("COUNT"); + + Label lHasil = new Label(); + Button back = new Button("RETURN"); + back.setOnAction(v ->{ + layarOpsi(stage); + }); + + tombolProses.setOnAction(v ->{ + double celcius = Double.parseDouble(tfCelcius.getText()); + double hasil = (0.8)*celcius; + + lHasil.setText(String.format("%.0f Reamur", hasil)); + }); + + VBox vbox = new VBox(judulSuhu, tfCelcius, tombolProses, lHasil, back); + vbox.setAlignment(Pos.CENTER); + vbox.setSpacing(12.5); + + Scene scene = new Scene(vbox, 320, 512); + stage.setScene(scene); + stage.show(); + } + + public void kalkulJarak (Stage stage){ + Label judulJarak = new Label ("KALKULATOR JARAK CM ke M"); + judulJarak.setFont(Font.font("Arial", 15)); + + TextField tfCentiMeter = new TextField(); + tfCentiMeter.setPromptText("Centimeter"); + + Button tombolProses = new Button ("COUNT"); + + Label lJumlah = new Label(); + Button back = new Button("RETURN"); + back.setOnAction(v ->{ + layarOpsi(stage); + }); + + tombolProses.setOnAction(v ->{ + double cm = Double.parseDouble(tfCentiMeter.getText()); + double jumlah = cm/100; + + lJumlah.setText(String.format("%.2f", jumlah,"Meter")); + }); + + VBox vbox = new VBox(judulJarak, tfCentiMeter, tombolProses, lJumlah, back); + vbox.setAlignment(Pos.CENTER); + vbox.setSpacing(12.5); + + // ImageView ivBanner = new ImageView("/bgkalkul.jpg"); + // ivBanner.setFitWidht(320); + // ivBanner.setFitHeight(512); + // ivBanner.setPrerveRatio(true); + + Scene scene = new Scene(vbox, 320, 512); + stage.setScene(scene); + stage.show(); + } + + public static void main(String[] args) { // untuk run + launch(); + } + +} \ No newline at end of file diff --git a/src/H071221092/Pertemuan_9/app/src/main/resources/bgkalkul.jpg b/src/H071221092/Pertemuan_9/app/src/main/resources/bgkalkul.jpg new file mode 100644 index 0000000..2c9fa4f Binary files /dev/null and b/src/H071221092/Pertemuan_9/app/src/main/resources/bgkalkul.jpg differ diff --git a/src/H071221092/Pertemuan_9/app/src/main/resources/styles/style.css b/src/H071221092/Pertemuan_9/app/src/main/resources/styles/style.css new file mode 100644 index 0000000..0599c5e --- /dev/null +++ b/src/H071221092/Pertemuan_9/app/src/main/resources/styles/style.css @@ -0,0 +1,3 @@ +#section-right{ + -fx-background-color: #a75757; +} \ No newline at end of file diff --git a/src/H071221092/Pertemuan_9/app/src/test/java/kalkulator/AppTest.java b/src/H071221092/Pertemuan_9/app/src/test/java/kalkulator/AppTest.java new file mode 100644 index 0000000..8c21205 --- /dev/null +++ b/src/H071221092/Pertemuan_9/app/src/test/java/kalkulator/AppTest.java @@ -0,0 +1,14 @@ +/* + * This Java source file was generated by the Gradle 'init' task. + */ +package kalkulator; + +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/H071221092/Pertemuan_9/gradle/wrapper/gradle-wrapper.properties b/src/H071221092/Pertemuan_9/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..37aef8d --- /dev/null +++ b/src/H071221092/Pertemuan_9/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/H071221092/Pertemuan_9/gradlew b/src/H071221092/Pertemuan_9/gradlew new file mode 100644 index 0000000..aeb74cb --- /dev/null +++ b/src/H071221092/Pertemuan_9/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/H071221092/Pertemuan_9/gradlew.bat b/src/H071221092/Pertemuan_9/gradlew.bat new file mode 100644 index 0000000..93e3f59 --- /dev/null +++ b/src/H071221092/Pertemuan_9/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/H071221092/Pertemuan_9/settings.gradle b/src/H071221092/Pertemuan_9/settings.gradle new file mode 100644 index 0000000..0ef62d9 --- /dev/null +++ b/src/H071221092/Pertemuan_9/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 = 'Kalkulator' +include('app')