diff --git a/src/H071221028/Pertemuan_1/No1.java b/src/H071221028/Pertemuan_1/No1.java new file mode 100644 index 0000000..a2cbc87 --- /dev/null +++ b/src/H071221028/Pertemuan_1/No1.java @@ -0,0 +1,24 @@ +package H071221028.Pertemuan_1; + +import java.util.Scanner; + +public class No1 { // nama file classnya + public static void main(String[] args) { + String nim; // variable + Scanner keyboard = new Scanner(System.in); + System.out.print("Masukkan NIM: "); + nim = keyboard.next(); + String inp = nim.substring(nim.length() - 3); // memasukkan index yang diminta, -3 untuk 3 angka terakkhir + + int angka = Integer.parseInt(inp); // modifikasi tipedata + + if (angka % 7 == 0) { + System.out.println("soal: no 7"); + } else { + System.out.printf("soal : no %d\n", angka % 7); // %d untuk angka int + } + + keyboard.close(); + } + +} diff --git a/src/H071221028/Pertemuan_1/No2.java b/src/H071221028/Pertemuan_1/No2.java new file mode 100644 index 0000000..98904f0 --- /dev/null +++ b/src/H071221028/Pertemuan_1/No2.java @@ -0,0 +1,61 @@ +package H071221028.Pertemuan_1; + +import java.util.InputMismatchException; +import java.util.Scanner; + +public class No2 { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + try { + int n = scanner.nextInt(); + + int countDecimal = 0; + int countInteger = 0; + + for (int i = 0; i < n; i++) { + float number = scanner.nextFloat(); + + if (number - (int)number > 0) { // angka - angka, jika agka menyisakan angka dibelakang koma akan masuk ke bilangan desimal + countDecimal++; + } else { + countInteger++; + } + } + + System.out.printf("%d Bilangan Bulat\n", countInteger); + System.out.printf("%d Bilangan Desimal\n", countDecimal); + } catch (InputMismatchException e) { + System.out.println("Please input a number!"); + e.printStackTrace(); + } + + scanner.close(); + } +} + + +// import java.util.Scanner; + +// public class Dua { +// public static void main(String[] args) { +// Scanner scanner = new Scanner(System.in); +// System.out.print("Masukkan jumlah bilangan: "); +// int n = scanner.nextInt(); +// int decimals = 0; +// int integers = 0; + +// for (int i = 0; i < n; i++) { +// System.out.print("Masukkan bilangan ke-" + (i+1) + ": "); +// double num = scanner.nextDouble(); +// if (num == (int) num) { +// integers++; +// } else { +// decimals++; +// } +// } + +// System.out.println("Jumlah bilangan decimal: " + decimals); +// System.out.println("Jumlah bilangan bulat: " + integers); +// } +// } diff --git a/src/H071221028/Pertemuan_1/No3.java b/src/H071221028/Pertemuan_1/No3.java new file mode 100644 index 0000000..ff58991 --- /dev/null +++ b/src/H071221028/Pertemuan_1/No3.java @@ -0,0 +1,32 @@ +package H071221028.Pertemuan_1; + +import java.util.InputMismatchException; +import java.util.Scanner; + +public class No3 { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + try { + System.out.print("Name : "); + String name = scanner.nextLine(); + + System.out.print("Umur : "); + int age = scanner.nextInt(); + + scanner.nextLine(); // hapus \n yang masih tersisa di aliran input + + + System.out.print("Hobby : "); + String hobby = scanner.nextLine(); + + System.out.printf("Nama saya %s, %d tahun, hobby %s.\n", name, age, hobby); + + } catch (InputMismatchException e) { + System.out.println("Please input with proper data format!"); + + } + + scanner.close(); + } +} diff --git a/src/H071221028/Pertemuan_1/No4.java b/src/H071221028/Pertemuan_1/No4.java new file mode 100644 index 0000000..c48f928 --- /dev/null +++ b/src/H071221028/Pertemuan_1/No4.java @@ -0,0 +1,41 @@ +package H071221028.Pertemuan_1; + +import java.util.Scanner; + +public class No4 { + public static String capitalizeFirstCharacter(String sentence) { + String words[] = sentence.split("\\s"); + + String returnSentence = ""; + + // for (int i = 0; i < words.length; i++) { + // words[i] = words[i].substring(0, 1).toUpperCase() + words[i].substring(1).toLowerCase(); + + // returnSentence += words[i]; + // if (i < words.length - 1) { + // returnSentence += " "; + // } + // } + for (String word : words ){ + word = word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase(); + + returnSentence += word; + returnSentence += " "; + + + } + + return returnSentence; + } + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + System.out.print("Masukkan Judul Film :\n> "); + String sentence = scanner.nextLine(); + + System.out.println(capitalizeFirstCharacter(sentence)); + + scanner.close(); + } +} diff --git a/src/H071221028/Pertemuan_1/No5.java b/src/H071221028/Pertemuan_1/No5.java new file mode 100644 index 0000000..e3f7be4 --- /dev/null +++ b/src/H071221028/Pertemuan_1/No5.java @@ -0,0 +1,63 @@ +package H071221028.Pertemuan_1; + +import java.util.Scanner; + +public class No5 { + public static void main(String[] args) { + Scanner inp = new Scanner(System.in); + String a = inp.next(); + String hari = a.substring(0, 2); + System.out.print(Integer.parseInt(hari) + " "); // parseint untuk mengubah dari string ke int + 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); + } + } +} \ No newline at end of file diff --git a/src/H071221028/Pertemuan_1/No6.java b/src/H071221028/Pertemuan_1/No6.java new file mode 100644 index 0000000..414d426 --- /dev/null +++ b/src/H071221028/Pertemuan_1/No6.java @@ -0,0 +1,18 @@ +package H071221028.Pertemuan_1; + +import java.util.Scanner; + +public class No6 { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + System.out.print("Input jari-jari: "); + double jariJari = scanner.nextDouble(); + + double area = (22.0 / 7.0) * jariJari * jariJari; + + System.out.printf("Luas lingkaran: %.2f\n", area); // pakai %.2f untuk 2 angka dibelakang koma + + scanner.close(); + } +} diff --git a/src/H071221028/Pertemuan_1/No7.java b/src/H071221028/Pertemuan_1/No7.java new file mode 100644 index 0000000..ebf997e --- /dev/null +++ b/src/H071221028/Pertemuan_1/No7.java @@ -0,0 +1,28 @@ +package H071221028.Pertemuan_1; + +import java.util.Scanner; + +public class No7 { + static String[] buah = {"Anggur", "Apel", "Belimbing", "Durian", "Rambutan", "Pisang", "Jeruk", "Semangka", "Nanas", +"Salak", "manggis"}; +public static void main(String[] args) { + Scanner inp = new Scanner(System.in); + System.out.print("Key: "); + String inputBuah = inp.next(); + int indexBuah = findIndex(inputBuah); + System.out.println(indexBuah); + inp.close(); +} +static int findIndex(String text){ + text = text.toLowerCase(); + int result = -1; + for (int i = 0; i < buah.length; i++) { + String buah1 = buah[i]; + buah1 = buah1.toLowerCase(); + if (buah1.equals(text)){ + result = i; + } + }; + return result; +} +} \ No newline at end of file diff --git a/src/H071221028/Pertemuan_1/No8.java b/src/H071221028/Pertemuan_1/No8.java new file mode 100644 index 0000000..c714c51 --- /dev/null +++ b/src/H071221028/Pertemuan_1/No8.java @@ -0,0 +1,34 @@ +package H071221028.Pertemuan_1; + +import java.util.Scanner; + +public class No8 { + public static void main(String[] args) { + int[][] angka = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9, }, { 10, 11 }, { 12 }, { 13, 14, 15, 16 } }; // menyimpan + // array + System.out.println(angka[0][2]); + Scanner inp = new Scanner(System.in); + + try { + System.out.print("Input angka yang ingin di cari : "); + int inputAngka = inp.nextInt(); + boolean found = false; + + for (int i = 0; i < angka.length; i++) { + for (int j = 0; j < angka[i].length; j++) { + int angka1 = angka[i][j]; + if (angka1 == inputAngka) { + System.out.println("Found" + inputAngka + " at [" + i + "][" + j + "]"); + break; + } + } + } + if (!found) { + System.out.println("Bilangan" + " " + inputAngka + " " + "tidak ditemukan pada bilangan"); + } + } catch (Exception e) { + System.out.println("Input harus berupa data integer (angka)"); + } + inp.close(); + } +} diff --git a/src/H071221028/Pertemuan_2/No1.java b/src/H071221028/Pertemuan_2/No1.java new file mode 100644 index 0000000..58bb312 --- /dev/null +++ b/src/H071221028/Pertemuan_2/No1.java @@ -0,0 +1,53 @@ +// class Event { +// String namaEvent; +// String peserta; +// int jumlahPeserta; + +// public String getnama(){ +// return namaEvent; +// } + +// public String getpeserta(){ +// return peserta; +// } + +// public int getjumlah(){ +// return jumlahPeserta; +// } +// } + +// public class No1 { +// public static void main(String[] args) { +// Event event = new Event(); + +// event.namaEvent = "Mathematic Event"; +// event.peserta = "SD"; +// event.jumlahPeserta = 560; + +// System.out.println("Nama event: " + event.getnama() + "."); +// System.out.println("Jenjang Peserta: " + event.getpeserta()+ "."); +// System.out.println("Jumlah Peserta: " + event.getjumlah()+"."); + +// } + +// } +// Parent class +class Sepatu { + protected String brand = "Sport"; + public void running() { + System.out.println("fastest"); + } + } + + // Child class + class Shoe extends Sepatu { + private String model = "Sport"; + public static void main(String[] args) { + Shoe mynike = new Shoe(); + mynike.brand = "Nike"; + mynike.model = "Running"; + System.out.println("Brand: " + mynike.brand + ", Model: " + mynike.model); + mynike.running(); + } + } + diff --git a/src/H071221028/Pertemuan_2/No2.java b/src/H071221028/Pertemuan_2/No2.java new file mode 100644 index 0000000..db5b843 --- /dev/null +++ b/src/H071221028/Pertemuan_2/No2.java @@ -0,0 +1,52 @@ +public class No2 { + + + public static void main(String[] args) { + Person person = new Person(); + person.setName("awa"); + person.setAge(18); + person.setGender("Male"); + + System.out.println("nama: " + person.getName()); + System.out.println("umur: " + person.getAge()); + System.out.println("Jenis kelamin: " + person.getGender()); + + + } +} + +class Person { + String name; + int age; + boolean isMale; + + public void setName(String name){ + this.name = name; + } + + public String getName(){ + return name; + } + + public void setAge(int age){ + this.age = age; + } + + public int getAge(){ + return age; + } + + public void setGender(String gender){ + this.isMale = gender == "Male"; + } + + public String getGender(){ + if (isMale) { + return "Male"; + } + else { + return "Female"; + } + +} +} \ No newline at end of file diff --git a/src/H071221028/Pertemuan_2/No3.java b/src/H071221028/Pertemuan_2/No3.java new file mode 100644 index 0000000..a751702 --- /dev/null +++ b/src/H071221028/Pertemuan_2/No3.java @@ -0,0 +1,39 @@ +class Barang { + public int id; + public String nama; + public int stok; + public double harga; + + public boolean isAvailable(){ + return this.stok > 0; + } +} + +public class No3 { + public static void main(String[] args) { + Barang barang = new Barang(); + + barang.id = 071221; + barang.nama = "kitkat"; + barang.stok = 30; + barang.harga = 12000; + + System.out.println("Id barang: " + barang.id); + System.out.println("Nama barang: " + barang.nama); + System.out.println("Stok barang: " + barang.stok); + System.out.println("Harga barang: " + barang.harga); + System.out.printf("ketersediaan barang: %s\n" , barang.isAvailable() ? "Tersedia": "Tidak tersedia"); + + + System.out.println("========================================"); + + barang.stok = 0; + + System.out.println("Id barang: " + barang.id); + System.out.println("Nama barang: " + barang.nama); + System.out.println("Stok barang: " + barang.stok); + System.out.println("Harga barang: " + barang.harga); + System.out.printf("ketersediaan barang: %s\n" , barang.isAvailable() ? "Tersedia": "Tidak tersedia"); + + } +} diff --git a/src/H071221028/Pertemuan_2/No4.java b/src/H071221028/Pertemuan_2/No4.java new file mode 100644 index 0000000..3db5a3e --- /dev/null +++ b/src/H071221028/Pertemuan_2/No4.java @@ -0,0 +1,22 @@ + +class Cuboid { + double height; + double width; + double lenght; + + double getVolume(){ + return height*width*lenght; + } +} + +public class No4 { + public static void main(String[] args) { + Cuboid cuboid = new Cuboid(); + cuboid.height = 10.0; + cuboid.width = 15.0; + cuboid.lenght = 30.0; + + System.out.printf("Volume = %.2f", cuboid.getVolume()); + + } +} \ No newline at end of file diff --git a/src/H071221028/Pertemuan_2/No5.java b/src/H071221028/Pertemuan_2/No5.java new file mode 100644 index 0000000..47732b5 --- /dev/null +++ b/src/H071221028/Pertemuan_2/No5.java @@ -0,0 +1,50 @@ +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 getName() { + return this.nama; + } + + public String getNim () { + return this.nim; + } +} + +public class No5 { + public static void main(String[] args) { + try{ + Alamat alamat = new Alamat () ; + alamat.jalan = "Minasa Upa"; + alamat.kota = "Kota Makassar"; + + + Mahasiswa mahasiswa = new Mahasiswa (); + mahasiswa.alamat = alamat; + mahasiswa.nama = "Nadjwa Amalia"; + mahasiswa.nim = "H071221028"; + + System.out.println("Nama: " + mahasiswa.getName()); + System.out.println("Nim: " + mahasiswa.getNim()); + System.out.println("Alamat: " + mahasiswa.getAlamat().getAlamatLengkap()); + }catch(Exception e){ + System.out.println(e.toString()); + } + + } +} + diff --git a/src/H071221028/Pertemuan_3/No1/Main.java b/src/H071221028/Pertemuan_3/No1/Main.java new file mode 100644 index 0000000..09ad661 --- /dev/null +++ b/src/H071221028/Pertemuan_3/No1/Main.java @@ -0,0 +1,91 @@ +package H071221028.Pertemuan_3.No1; +class Taekwondo { + + private String serangan; + private int skor; + private Atlet atlet; + + + public Taekwondo ( String serangan, int skor){ + this.serangan = serangan; + this.skor = skor; + } + public Taekwondo ( Atlet atlet, String serangan, int skor){ + this.atlet = atlet; + this.serangan = serangan; + this.skor = skor; + } + public Taekwondo(){} + + public Atlet getAtlet() { + return atlet; + } + + public void setAtlet (Atlet atlet){ + this.atlet = atlet; + } + + public String getSerangan() { + return serangan; + } + + public void setSerangan( String serangan) { + this.serangan = serangan; + } + + public int getSkor(){ + return skor; + } + + public void setSkor(int skor) { + this.skor = skor; + } + + public int hitungSkor(){ + if (serangan == "kepala"){ + return 4; + } else if (serangan == "badan"){ + return 2; + } else if (serangan == "pukulan"){ + return 1; + } else { + return -1; + } + + } + public void tampilkanDataAtlet(){ + System.out.println("nama: " + atlet.getNama()); + System.out.println("Ranking: " + atlet.getRangking()); + } +} +class Atlet { + String nama; + int rangking; + + public Atlet (String nama, int rangking){ + this.nama = nama; + this.rangking = rangking; + } + public String getNama(){ + return nama; + } + public int getRangking(){ + return rangking; + } +} + +class Main { + public static void main(String[] args) { + Atlet atlet = new Atlet("awa",17); + atlet.nama = "awa"; + atlet.rangking = 17; + + Taekwondo tkd = new Taekwondo(); + + tkd.setAtlet(atlet); + + tkd.tampilkanDataAtlet(); + System.out.println("serangan : " + tkd.getSerangan()); + System.out.println("Skor: " + tkd.hitungSkor()); + } +} \ No newline at end of file diff --git a/src/H071221028/Pertemuan_3/No1/Quiz.java b/src/H071221028/Pertemuan_3/No1/Quiz.java new file mode 100644 index 0000000..208ffc1 --- /dev/null +++ b/src/H071221028/Pertemuan_3/No1/Quiz.java @@ -0,0 +1,61 @@ +package H071221028.Pertemuan_3.No1; +public class Quiz { + public static void main(String[] args) { + Utils.selfDisplay(); + Pesanan pesanan1 = new Pesanan("ayam", "minasa upa"); + pesanan1.setNamaPesanan("ayam"); + pesanan1.setAlamatPemesanan("minasa upa"); + pesanan1.setTotalHarga(1000); + } +} + +class Pesanan { + String namaPesanan; + String alamatPemesanan; + double totalHarga; + + public String getNamaPesanan() { + return namaPesanan; + } + + public void setNamaPesanan(String namaPesanan) { + this.namaPesanan = namaPesanan; + } + + public String getAlamatPemesanan() { + return alamatPemesanan; + } + + public void setAlamatPemesanan(String alamatPemesanan) { + this.alamatPemesanan = alamatPemesanan; + } + + public double getTotalHarga() { + return totalHarga; + } + + public void setTotalHarga(double totalHarga) { + this.totalHarga = totalHarga; + } + + public Pesanan (String namaPesanan, String alamatPemesanan) { + this.namaPesanan = namaPesanan; + this.alamatPemesanan = alamatPemesanan; + } +} + + // public void Pesanan (double totalHarga) { + // this.totalHarga = totalHarga; + // } + + + +class Utils { + public static void selfDisplay() { + String nama = "awa"; + String nim = "H071221028"; + System.out.println("Nama: " + nama); + System.out.println("NIM: " + nim); + } +} + diff --git a/src/H071221028/Pertemuan_3/No1/Utils.java b/src/H071221028/Pertemuan_3/No1/Utils.java new file mode 100644 index 0000000..a4115de --- /dev/null +++ b/src/H071221028/Pertemuan_3/No1/Utils.java @@ -0,0 +1,9 @@ +package H071221028.Pertemuan_3.No1; +class Utils { + public static void selfDisplay() { + String nama = "awa"; + String nim = "H071221028"; + System.out.println("Nama: " + nama); + System.out.println("NIM: " + nim); + } +} \ No newline at end of file diff --git a/src/H071221028/Pertemuan_3/No2/Pllayer.java b/src/H071221028/Pertemuan_3/No2/Pllayer.java new file mode 100644 index 0000000..a68afef --- /dev/null +++ b/src/H071221028/Pertemuan_3/No2/Pllayer.java @@ -0,0 +1,61 @@ +package H071221028.Pertemuan_3.No2; + +class Player{ + private String name; + private int hp; + private int attackPower; + private int defense; + + public Player() {} + + public void getDamage(Player enemy) { + hp = hp-Math.abs(enemy.getAttackPower()-defense); + } + + // + public Player(String name, int attackPower, int defense) { + this.name = name; + this.attackPower = attackPower; + this.defense = defense; + hp = 100; + } + + // + public Player(String name, int defense) { + this.name = name; + this.defense = defense; + hp = 100; + } + + public void status() { + System.out.println(name + " status"); + System.out.println("HP = " + hp); + System.out.println("Defense = " + defense); + System.out.println("Attack = " + attackPower + "\n"); + } + + public int getAttackPower() { + return attackPower; + } + // + public void setAttackPower(int attackPower) { + this.attackPower = attackPower; + } + + +} + +class Main { + public static void main(String [] args) { + Player player1= new Player("Mino", 30, 15); + Player player2= new Player("Hilda", 10); + + player2.setAttackPower(35); + + player1.getDamage(player2); + + player1.status(); + player2.status(); + } +} + \ No newline at end of file diff --git a/src/H071221028/Pertemuan_3/No3/no1.java b/src/H071221028/Pertemuan_3/No3/no1.java new file mode 100644 index 0000000..69d5da7 --- /dev/null +++ b/src/H071221028/Pertemuan_3/No3/no1.java @@ -0,0 +1,34 @@ +package H071221028.Pertemuan_3.No3; +class Event { + String nama; + String tipe; + boolean isPaid; + double hargaTiket; + + public Event(String nama, String tipe, boolean isPaid, double hargaTiket) { + this.nama = nama; + this.tipe = tipe; + this.isPaid = isPaid; + if (isPaid == true) { + this.hargaTiket = hargaTiket; + } + else { + this.hargaTiket = 0; + } + } + public void beliTiket (){ + System.out.printf("Selamat anda telah berhasil membeli tiket %s %s", nama, isPaid? "Seharga " + hargaTiket: "Secara Gratis"); + } + + +} + +public class no1 { + public static void main(String[] args) { + Event event = new Event ("UNHAS CUP", "OLAHRAGA", true, 10.000); + System.out.println("Nama Event: " + event.nama); + System.out.println("Tipe Event: " + event.tipe); + System.out.println("Pembayaran: " + event.isPaid); + System.out.println("Harga tiket: " + event.hargaTiket); + } +} diff --git a/src/H071221028/Pertemuan_4/No2/Car.java b/src/H071221028/Pertemuan_4/No2/Car.java new file mode 100644 index 0000000..e69de29 diff --git a/src/H071221028/Pertemuan_5/Diagram Anggota_nadjwa amalia.html b/src/H071221028/Pertemuan_5/Diagram Anggota_nadjwa amalia.html new file mode 100644 index 0000000..3e13d23 --- /dev/null +++ b/src/H071221028/Pertemuan_5/Diagram Anggota_nadjwa amalia.html @@ -0,0 +1,11 @@ + + + + +Diagram Tanpa Judul + + +
+ + + \ No newline at end of file diff --git a/src/H071221028/Pertemuan_5/No1/BangunDatar.java b/src/H071221028/Pertemuan_5/No1/BangunDatar.java new file mode 100644 index 0000000..eb4eab9 --- /dev/null +++ b/src/H071221028/Pertemuan_5/No1/BangunDatar.java @@ -0,0 +1,110 @@ +package H071221028.Pertemuan_5.No1; + +public class BangunDatar { + protected double nilaiA; + protected double nilaiB; + protected double nilaiC; + protected double nilaiD; + + // protected double keliling; + // protected double luas; + + public BangunDatar(double nilaiA) { + this.nilaiA = nilaiA; + } + + public BangunDatar(double nilaiA, double nilaiB) { + this.nilaiA = nilaiA; + this.nilaiB = nilaiB; + } + + public BangunDatar(double nilaiA, double nilaiB, double nilaiC) { + this.nilaiA = nilaiA; + this.nilaiB = nilaiB; + this.nilaiC = nilaiC; + } + + public BangunDatar(double nilaiA, double nilaiB, double nilaiC, double nilaiD) { + this.nilaiA = nilaiA; + this.nilaiB = nilaiB; + this.nilaiC = nilaiC; + this.nilaiD = nilaiD; + } + + public double keliling(){ + return 0; + } + + public double luas(){ + return 0; + } + +} + +class Persegi extends BangunDatar { + + public Persegi(double sisi){ + super(sisi); + + } + public double keliling(){ + return 4*nilaiA; + } + public double luas(){ + return nilaiA*nilaiB; + } +} + +class PersegiPanjang extends BangunDatar{ + + + public PersegiPanjang(double panjang, double lebar){ + super(panjang, lebar); + + } + public double keliling(){ + return 2 * (nilaiA * nilaiB); + } + + public double luas(){ + return nilaiA * nilaiB; + } + + + + +} + +class Segitiga extends BangunDatar{ + + + public Segitiga( double alas, double tinggi, double sisi){ + super(alas, tinggi, sisi); + + } + public double keliling(){ + return nilaiA + nilaiB + nilaiC; + } + public double luas(){ + return (nilaiA*nilaiB)/2; + + } + + + +} + +class Trapesium extends BangunDatar{ + + public Trapesium (double tinggi, double alas, double atas, double sisimiring){ + super(tinggi, alas, sisimiring, atas); + } + + public double getLuas(){ + return 0.5*(nilaiA+nilaiB)*nilaiC; + } + + public double getKeliling(){ + return nilaiA+nilaiB+nilaiC+nilaiD; + } +} diff --git a/src/H071221028/Pertemuan_5/No1/BangunRuang.java b/src/H071221028/Pertemuan_5/No1/BangunRuang.java new file mode 100644 index 0000000..9f3acd0 --- /dev/null +++ b/src/H071221028/Pertemuan_5/No1/BangunRuang.java @@ -0,0 +1,87 @@ +package H071221028.Pertemuan_5.No1; + +public class BangunRuang { + protected double nilaiA; + protected double nilaiB; + protected double nilaiC; + + + protected double keliling; + protected double luas; + protected double volume; + + public BangunRuang(double nilaiA) { + this.nilaiA = nilaiA; + } + public BangunRuang(double nilaiA, double nilaiB) { + this.nilaiA = nilaiA; + this.nilaiB = nilaiB; + } + public BangunRuang(double nilaiA, double nilaiB, double nilaiC) { + this.nilaiA = nilaiA; + this.nilaiB = nilaiB; + this.nilaiC = nilaiC; + } + + + + +} +class Kubus extends BangunRuang{ + + public Kubus (double sisi){ + super(sisi); + } + + public double volume(){ + return 3*nilaiA; + } + + public double luasPermukaan(){ + return 6*nilaiA*nilaiA; + } +} + +class Balok extends BangunRuang{ + + public Balok (double panjang, double lebar, double tinggi){ + super(panjang, lebar, tinggi); + } + + public double volume(){ + return nilaiA*nilaiB*nilaiC; + } + public double luasPermukaan(){ + return (2*nilaiA*nilaiB)+(2*nilaiA*nilaiC)+(2*nilaiB*nilaiC); + } +} + +class Bola extends BangunRuang{ + + public Bola (double sisi){ + super(sisi); + } + + public double volume(){ + return (4*Math.PI/3); + } + + public double luasPermukaan(){ + return (4*Math.PI*nilaiA); + } +} + +class Tabung extends BangunRuang{ + + public Tabung (double jariJari, double tinggi){ + super(jariJari, tinggi); + } + + public double volume(){ + return (Math.PI*nilaiA*nilaiA*nilaiB); + } + + public double luasPermukaan(){ + return (2*Math.PI*nilaiA*(nilaiA+nilaiB)); + } +} diff --git a/src/H071221028/Pertemuan_5/No1/Main.java b/src/H071221028/Pertemuan_5/No1/Main.java new file mode 100644 index 0000000..c05029f --- /dev/null +++ b/src/H071221028/Pertemuan_5/No1/Main.java @@ -0,0 +1,15 @@ +package H071221028.Pertemuan_5.No1; + + +public class Main { + public static void main(String[] args) { + Segitiga segitiga = new Segitiga(3, 2, 4); + System.out.println(segitiga.luas()); + System.out.println(segitiga.keliling()); + + Kubus kubus = new Kubus(6); + System.out.println(kubus.volume()); + System.out.println(kubus.luasPermukaan()); + + } +} diff --git a/src/H071221028/Pertemuan_5/No1/diagramno1.png b/src/H071221028/Pertemuan_5/No1/diagramno1.png new file mode 100644 index 0000000..0e13621 Binary files /dev/null and b/src/H071221028/Pertemuan_5/No1/diagramno1.png differ diff --git a/src/H071221028/Pertemuan_5/No2/Anggota.java b/src/H071221028/Pertemuan_5/No2/Anggota.java new file mode 100644 index 0000000..dd1e538 --- /dev/null +++ b/src/H071221028/Pertemuan_5/No2/Anggota.java @@ -0,0 +1,69 @@ +package H071221028.Pertemuan_5.No2; +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/H071221028/Pertemuan_5/No2/Diagram Anggota_nadjwa amalia.html b/src/H071221028/Pertemuan_5/No2/Diagram Anggota_nadjwa amalia.html new file mode 100644 index 0000000..3e13d23 --- /dev/null +++ b/src/H071221028/Pertemuan_5/No2/Diagram Anggota_nadjwa amalia.html @@ -0,0 +1,11 @@ + + + + +Diagram Tanpa Judul + + +
+ + + \ No newline at end of file diff --git a/src/H071221028/Pertemuan_5/No2/MainAnggota.java b/src/H071221028/Pertemuan_5/No2/MainAnggota.java new file mode 100644 index 0000000..a824b0c --- /dev/null +++ b/src/H071221028/Pertemuan_5/No2/MainAnggota.java @@ -0,0 +1,17 @@ +package H071221028.Pertemuan_5.No2; +public class MainAnggota { + public static void main(String[] args) { //method yang dapat dipakai tanpa harus mendeklarasikan suatu class + PengurusInti pengurusInti = new PengurusInti("Diva", 19, "Wanita", "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("Arni", 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/H071221028/Pertemuan_8/AppRacer.java b/src/H071221028/Pertemuan_8/AppRacer.java new file mode 100644 index 0000000..5468cc1 --- /dev/null +++ b/src/H071221028/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/H071221028/Pertemuan_8/Pertemuan8/TugasPraktikum.java b/src/H071221028/Pertemuan_8/Pertemuan8/TugasPraktikum.java new file mode 100644 index 0000000..19db690 --- /dev/null +++ b/src/H071221028/Pertemuan_8/Pertemuan8/TugasPraktikum.java @@ -0,0 +1,101 @@ +package Pertemuan8; + +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/H071221028/Pertemuan_8/Pertemuan8/halo.py b/src/H071221028/Pertemuan_8/Pertemuan8/halo.py new file mode 100644 index 0000000..9a8722e --- /dev/null +++ b/src/H071221028/Pertemuan_8/Pertemuan8/halo.py @@ -0,0 +1,2 @@ +n= "Halo maul" +print(n) \ No newline at end of file diff --git a/src/H071221028/Pertemuan_9/.gitattributes b/src/H071221028/Pertemuan_9/.gitattributes new file mode 100644 index 0000000..097f9f9 --- /dev/null +++ b/src/H071221028/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/H071221028/Pertemuan_9/.gitignore b/src/H071221028/Pertemuan_9/.gitignore new file mode 100644 index 0000000..1b6985c --- /dev/null +++ b/src/H071221028/Pertemuan_9/.gitignore @@ -0,0 +1,5 @@ +# Ignore Gradle project-specific cache directory +.gradle + +# Ignore Gradle build output directory +build diff --git a/src/H071221028/Pertemuan_9/.vscode/settings.json b/src/H071221028/Pertemuan_9/.vscode/settings.json new file mode 100644 index 0000000..7b016a8 --- /dev/null +++ b/src/H071221028/Pertemuan_9/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.compile.nullAnalysis.mode": "automatic" +} \ No newline at end of file diff --git a/src/H071221028/Pertemuan_9/app/bin/main/css/style.css b/src/H071221028/Pertemuan_9/app/bin/main/css/style.css new file mode 100644 index 0000000..c1f15b7 --- /dev/null +++ b/src/H071221028/Pertemuan_9/app/bin/main/css/style.css @@ -0,0 +1,3 @@ +/* .startbutton { + -fx-background-color: #FFC0CB; -fx-background-radius: 10; +} */ \ No newline at end of file diff --git a/src/H071221028/Pertemuan_9/app/bin/main/image/timbangan.png b/src/H071221028/Pertemuan_9/app/bin/main/image/timbangan.png new file mode 100644 index 0000000..5d71b52 Binary files /dev/null and b/src/H071221028/Pertemuan_9/app/bin/main/image/timbangan.png differ diff --git a/src/H071221028/Pertemuan_9/app/bin/main/image/timbanganBiru.png b/src/H071221028/Pertemuan_9/app/bin/main/image/timbanganBiru.png new file mode 100644 index 0000000..b95ded2 Binary files /dev/null and b/src/H071221028/Pertemuan_9/app/bin/main/image/timbanganBiru.png differ diff --git a/src/H071221028/Pertemuan_9/app/build.gradle b/src/H071221028/Pertemuan_9/app/build.gradle new file mode 100644 index 0000000..aafc8da --- /dev/null +++ b/src/H071221028/Pertemuan_9/app/build.gradle @@ -0,0 +1,47 @@ +/* + * 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.0.2/userguide/building_java_projects.html + */ + +plugins { + // Apply the application plugin to add support for building a CLI application in Java. + id 'application' + id 'org.openjfx.javafxplugin' version '0.0.14' +} + +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' +} + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(17) + } +} + +javafx { + version = "17" + modules = [ 'javafx.controls' ] +} + +application { + // Define the main class for the application. + mainClass = 'javafxx.App' +} + +tasks.named('test') { + // Use JUnit Platform for unit tests. + useJUnitPlatform() +} diff --git a/src/H071221028/Pertemuan_9/app/src/main/java/javafxx/App.java b/src/H071221028/Pertemuan_9/app/src/main/java/javafxx/App.java new file mode 100644 index 0000000..5a06d41 --- /dev/null +++ b/src/H071221028/Pertemuan_9/app/src/main/java/javafxx/App.java @@ -0,0 +1,252 @@ +/* + * This Java source file was generated by the Gradle 'init' task. + */ +package javafxx; + +import javafx.application.Application; +import javafx.scene.Scene; +import javafx.stage.Stage; +import javafx.scene.layout.VBox; +import javafx.scene.text.Font; +import javafx.geometry.Insets; +import javafx.geometry.Pos; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; +import javafx.scene.image.ImageView; + + +public class App extends Application{ + + + public static void main(String[] args){ + Application.launch(args); + } + + @Override + public void start(Stage stage) throws Exception{ + + + + VBox vbox = new VBox(); + + + Label tittle = new Label ("Kalkulator Sehat"); + // tittle.getStyleClass().add("tittle"); + tittle.setFont(Font.font("Arial",30)); + tittle.setStyle("-fx-font-weight: bold; -f"); + vbox.getChildren().add(tittle); + vbox.setSpacing(12.0); + vbox.setStyle("-fx-background-color: #E8F6EF;"); + + // Image logo = new Image(getClass().getClassLoader().getResourceAsStream("/image/timbangan.png")); + ImageView calculatorLogo = new ImageView("/image/timbanganBiru.png"); + calculatorLogo.setFitWidth(254); + calculatorLogo.setFitHeight(230); + calculatorLogo.setPreserveRatio(true); + calculatorLogo.setId("logo"); + + + + + + Button startButton = new Button("Mulai"); + startButton.setMaxSize(100, 200); + startButton.getStyleClass().add("startbutton"); + startButton.setMaxSize(100, 200); + startButton.setStyle("-fx-background-color: #4C4C6D; -fx-background-radius: 20; -fx-text-fill: white;"); + vbox.getChildren().addAll(calculatorLogo,startButton); + vbox.setAlignment(Pos.CENTER); + // startButton.setStyle("-fx-background-color: #FFC0CB; -fx-background-radius: 10;"); + startButton.setOnAction(action -> { + // Seluruh kode diantara {} disini akan dijalankan / dieksekusi ketika button sedang di click. + calculatorScene(stage); + }); + + + + Scene scene = new Scene(vbox,320, 512); + + stage.setScene(scene); + stage.setTitle("Kalkulator keren"); + stage.show(); + } + + + public void calculatorScene(Stage stage){ + VBox vbox = new VBox(); + Label tittle1 = new Label ("Pilih Kalkulator"); + tittle1.setFont(Font.font("Arial",25)); + tittle1.setStyle("-fx-font-weight: bold; -f"); + vbox.getChildren().add(tittle1); + vbox.setSpacing(20.0); + + + Button calculatorBMIButton = new Button("Kalkulator BMI"); + vbox.getChildren().add(calculatorBMIButton); + vbox.setAlignment(Pos.CENTER); + calculatorBMIButton.setStyle("-fx-background-color: #4C4C6D; -fx-background-radius: 20; -fx-text-fill: white;"); + + calculatorBMIButton.setOnAction(action -> { + // Seluruh kode diantara {} disini akan dijalankan / dieksekusi ketika button sedang di click. + BMICalculator(stage); + }); + + Button calculatorCalorieButton = new Button("Kalkulator kalori"); + vbox.getChildren().add(calculatorCalorieButton); + vbox.setAlignment(Pos.CENTER); + calculatorCalorieButton.setStyle("-fx-background-color: #4C4C6D; -fx-background-radius: 20; -fx-text-fill: white;"); + + calculatorCalorieButton.setOnAction(action -> { + // Seluruh kode diantara {} disini akan dijalankan / dieksekusi ketika button sedang di click. + gender(stage); + }); + + + vbox.setStyle("-fx-background-color: #E8F6EF;"); + Scene scene = new Scene(vbox, 320, 512); + stage.setScene(scene); + stage.show(); + } + + public void BMICalculator(Stage stage){ + + + Label CalBMITittle = new Label("KALKULATOR BMI"); + CalBMITittle.setFont(Font.font("Arial",20)); + + TextField weightTextField = new TextField(); + weightTextField.setPromptText("Berat badan"); + TextField heighTextField = new TextField(); + heighTextField.setPromptText("Tinggi badan"); + + Button buttonCalculate = new Button("Calculate"); + buttonCalculate.setStyle("-fx-background-color: #4C4C6D; -fx-background-radius: 20; -fx-text-fill: white;"); + Label BMIResult = new Label(); + + Button buttonBack = new Button("Kembali"); + buttonBack.setStyle("-fx-background-color: #4C4C6D; -fx-background-radius: 20; -fx-text-fill: white;"); + buttonBack.setOnAction(v->{ + calculatorScene(stage); + }); + + buttonCalculate.setOnAction(v->{ + + try { + double tinggi= Double.parseDouble(heighTextField.getText()); + tinggi=tinggi/100; + double berat= Double.parseDouble(weightTextField.getText()); + double hasil = berat/(tinggi*tinggi); + BMIResult.setText(String.format("%f", hasil)); + + } catch (Exception e) { + BMIResult.setText("Input salah"); + + } + }); + + + + VBox vbox = new VBox(CalBMITittle, weightTextField,heighTextField,buttonCalculate, BMIResult,buttonBack); + vbox.setPadding(new Insets(24)); + vbox.setAlignment(Pos.CENTER); + vbox.setSpacing(12.0); + vbox.setStyle("-fx-background-color: #E8F6EF;"); + + + + Scene scene = new Scene(vbox, 320, 512); + stage.setScene(scene); + stage.show(); + } + + public void gender(Stage stage){ + + Button perempuaButton = new Button("Perempuan"); + perempuaButton.setStyle("-fx-background-color: #4C4C6D; -fx-background-radius: 20; -fx-text-fill: white;"); + perempuaButton.setOnAction(v->{ + calculatorCalorie(stage, false); + }); + + Button lakiButton = new Button("Laki-Laki"); + lakiButton.setStyle("-fx-background-color: #4C4C6D; -fx-background-radius: 20; -fx-text-fill: white;"); + lakiButton.setOnAction(v->{ + calculatorCalorie(stage, true); + }); + + Button backButton = new Button("Kembali"); + backButton.setStyle("-fx-background-color: #4C4C6D; -fx-background-radius: 20; -fx-text-fill: white;"); + backButton.setOnAction(v->{ + calculatorScene(stage); + }); + + VBox vbox = new VBox(perempuaButton, lakiButton,backButton); + vbox.setAlignment(Pos.CENTER); + vbox.setSpacing(20.0); + vbox.setStyle("-fx-background-color: #E8F6EF;"); + + Scene scene = new Scene(vbox, 320, 512); + stage.setScene(scene); + stage.show(); + } + + public void calculatorCalorie(Stage stage, boolean isMale){ + + Label judul2 = new Label("KALKULATOR KALORI"); + judul2.setFont(Font.font("Arial",20)); + + TextField tfBeratK = new TextField(); + tfBeratK.setPromptText("Berat badan dalam kg"); + TextField tfTinggiK = new TextField(); + tfTinggiK.setPromptText("Tinggi dalam cm"); + TextField tfUmurK = new TextField(); + tfUmurK.setPromptText("Umur dalam tahun"); + + Button calculate1 = new Button("calculate"); + calculate1.setStyle("-fx-background-color: #4C4C6D; -fx-background-radius: 20; -fx-text-fill: white;"); + + + + + Label labelHasil1Label = new Label(); + calculate1.setOnAction(v->{ + try { + double result; + if (isMale==true){ + result = 88.4 + 13.4 * Double.parseDouble(tfBeratK.getText()) + + 4.8 * Double.parseDouble(tfTinggiK.getText()) - 5.68 * Double.parseDouble(tfUmurK.getText()) * 1.55; + } + else { + result = 447.6 + 9.25 * Double.parseDouble(tfBeratK.getText()) + + 3.1 * Double.parseDouble(tfTinggiK.getText()) - 44.3 * Double.parseDouble(tfUmurK.getText()) * 1.375; + + } + + labelHasil1Label.setText(String.valueOf(result)); + } + catch (Exception e) { + labelHasil1Label.setText("Input salah"); + } + }); + Button buttonBack1 = new Button("Kembali"); + buttonBack1.setStyle("-fx-background-color: #4C4C6D; -fx-background-radius: 20; -fx-text-fill: white;"); + + buttonBack1.setOnAction(v->{ + gender(stage); + }); + + + + VBox vbox = new VBox(judul2, tfBeratK, tfTinggiK, tfUmurK,calculate1, labelHasil1Label, buttonBack1); + vbox.setAlignment(Pos.CENTER); + vbox.setSpacing(12.0); + vbox.setStyle("-fx-background-color: #E8F6EF;"); + vbox.setPadding(new Insets(24)); + + Scene scene = new Scene(vbox, 320, 512); + stage.setScene(scene); + stage.show(); + } + + +} \ No newline at end of file diff --git a/src/H071221028/Pertemuan_9/app/src/main/resources/css/style.css b/src/H071221028/Pertemuan_9/app/src/main/resources/css/style.css new file mode 100644 index 0000000..c1f15b7 --- /dev/null +++ b/src/H071221028/Pertemuan_9/app/src/main/resources/css/style.css @@ -0,0 +1,3 @@ +/* .startbutton { + -fx-background-color: #FFC0CB; -fx-background-radius: 10; +} */ \ No newline at end of file diff --git a/src/H071221028/Pertemuan_9/app/src/main/resources/image/timbangan.png b/src/H071221028/Pertemuan_9/app/src/main/resources/image/timbangan.png new file mode 100644 index 0000000..5d71b52 Binary files /dev/null and b/src/H071221028/Pertemuan_9/app/src/main/resources/image/timbangan.png differ diff --git a/src/H071221028/Pertemuan_9/app/src/main/resources/image/timbanganBiru.png b/src/H071221028/Pertemuan_9/app/src/main/resources/image/timbanganBiru.png new file mode 100644 index 0000000..b95ded2 Binary files /dev/null and b/src/H071221028/Pertemuan_9/app/src/main/resources/image/timbanganBiru.png differ diff --git a/src/H071221028/Pertemuan_9/gradle/wrapper/gradle-wrapper.properties b/src/H071221028/Pertemuan_9/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..bdc9a83 --- /dev/null +++ b/src/H071221028/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.0.2-bin.zip +networkTimeout=10000 +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/src/H071221028/Pertemuan_9/gradlew b/src/H071221028/Pertemuan_9/gradlew new file mode 100644 index 0000000..79a61d4 --- /dev/null +++ b/src/H071221028/Pertemuan_9/gradlew @@ -0,0 +1,244 @@ +#!/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 + +# 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"' + +# 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 + +# 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/H071221028/Pertemuan_9/gradlew.bat b/src/H071221028/Pertemuan_9/gradlew.bat new file mode 100644 index 0000000..93e3f59 --- /dev/null +++ b/src/H071221028/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/H071221028/Pertemuan_9/settings.gradle b/src/H071221028/Pertemuan_9/settings.gradle new file mode 100644 index 0000000..c94492b --- /dev/null +++ b/src/H071221028/Pertemuan_9/settings.gradle @@ -0,0 +1,11 @@ +/* + * 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.0.2/userguide/multi_project_builds.html + */ + +rootProject.name = 'JavaFxx' +include('app') diff --git a/src/H071221028/pertemuan_6/Diagram prak6 nadjwa.png b/src/H071221028/pertemuan_6/Diagram prak6 nadjwa.png new file mode 100644 index 0000000..c1dae3a Binary files /dev/null and b/src/H071221028/pertemuan_6/Diagram prak6 nadjwa.png differ diff --git a/src/H071221028/pertemuan_6/Dog.java b/src/H071221028/pertemuan_6/Dog.java new file mode 100644 index 0000000..040da3c --- /dev/null +++ b/src/H071221028/pertemuan_6/Dog.java @@ -0,0 +1,148 @@ +abstract class Dog implements Moveable { + protected int position; + protected int averageLength; + + public Dog(int position, int averageLength) { + this.position = position; + this.averageLength = averageLength; + } + + abstract void describe(); + + 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; + } +} +class Pitbull extends Dog{ + + public Pitbull(int position, int averageLength) { + super(position, averageLength); + } + + @Override + void describe() { + System.out.println("Pitbull : "); + System.out.println("Hewan penyayang"); + } + + @Override + public void move() { + position = position+3; + } +} + +class SiberianHusky extends Dog{ + + public SiberianHusky(int position, int averageLength) { + super(position, averageLength); + } + + @Override + public void move() { + position = position+2; + } + + @Override + void describe() { + + } + +} + +class BullDog extends Dog{ + + public BullDog(int position, int averageLength) { + super(position, averageLength); + } + + @Override + public void move() { + position = position+1; + } + + @Override + void describe() { + + + } + +} + + + +interface Moveable{ + void move(); +} + +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; + } + @Override + public void move() { + System.out.println("Smartphone berpindah"); + } + +} + +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; + } + @Override + public void move() { + System.out.println("Mobil sedang berakselerasi"); + } + +} + diff --git a/src/H071221028/pertemuan_6/Main.java b/src/H071221028/pertemuan_6/Main.java new file mode 100644 index 0000000..25bd74d --- /dev/null +++ b/src/H071221028/pertemuan_6/Main.java @@ -0,0 +1,20 @@ +/** + * Main + */ +public class Main { + + public static void main(String[] args) { + Pitbull pitbull = new Pitbull(2, 50); + pitbull.describe(); + System.out.println("Current Pitbull position: "+ pitbull.getPosition()); + pitbull.move(); + System.out.println("Current pitbull position: " + pitbull.getPosition()); + + Smartphone smartphone = new Smartphone(10000, "Iphone"); + smartphone.move(); + + Car car = new Car(10, "pink", 180); + car.move(); + + } +} \ No newline at end of file diff --git a/src/H071221028/pertemuan_7/.vscode/settings.json b/src/H071221028/pertemuan_7/.vscode/settings.json new file mode 100644 index 0000000..4e9b4de --- /dev/null +++ b/src/H071221028/pertemuan_7/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": [ + "No2", + "No1", + "No3" + ] +} \ No newline at end of file diff --git a/src/H071221028/pertemuan_7/No1/Main.java b/src/H071221028/pertemuan_7/No1/Main.java new file mode 100644 index 0000000..ead8616 --- /dev/null +++ b/src/H071221028/pertemuan_7/No1/Main.java @@ -0,0 +1,97 @@ +// abstract class Character{ +// protected String name; +// protected int attackPower; + +// public Character(String name, int attackPower) { +// this.name = name; +// this.attackPower = attackPower; +// } + +// public String getName(){ +// return name; +// } +// public int getAttackPower(){ +// return attackPower; + +// } +// abstract int attack(); +// abstract int attack(String attackType); +// } + +// class Fighter extends Character{ + +// public Fighter(String name, int attackPower) { +// super(name, attackPower); + +// } + +// @Override +// int attack() { +// return this.attackPower; +// } + +// @Override +// int attack(String attackType) { +// if (attackType.equalsIgnoreCase("melee")){ +// return 2*this.attackPower; +// } +// else if (attackType.equalsIgnoreCase("ranged")){ +// return this.attackPower; +// } +// return this.attackPower; +// } + + +// } +// class Mage extends Character{ + +// public Mage(String name, int attackPower) { +// super(name, attackPower); + +// } + +// @Override +// int attack() { + +// return this.attackPower; +// } + +// @Override +// int attack(String attackType) { +// if (attackType.equalsIgnoreCase("fire")){ +// return 3*attackPower; +// } +// else if (attackType.equalsIgnoreCase("frost")){ +// return 2*attackPower; +// } +// return this.attackPower; +// } + +// } + +// public class Main { +// public static void main(String[] args) { + +// Character[] character = new Character[5]; +// character[0]= new Fighter("alucard", 90); +// character[1]= new Mage("odette", 99); +// character[2]= new Fighter("Zilong", 80); +// character[3]= new Fighter("lancelot", 70); +// character[4]= new Mage("nana", 91); + + +// for (int i = 0; i < character.length; i++) { +// printAttack(character[i]); +// } +// } +// public static void printAttack(Character character) { +// if (character instanceof Fighter){ +// System.out.println("Attack power " + character.getName() + ":" + character.attack("ranged")); +// } +// if (character instanceof Mage){ +// System.out.println("Attack power " + character.getName() + ":" + character.attack("frost")); +// } +// } + + +// } diff --git a/src/H071221028/pertemuan_7/No2/Main.java b/src/H071221028/pertemuan_7/No2/Main.java new file mode 100644 index 0000000..0edaefd --- /dev/null +++ b/src/H071221028/pertemuan_7/No2/Main.java @@ -0,0 +1,58 @@ +class Product { + private String name; + private T price; + private String expiryDate; + + public Product(String name, T price, String expiryDate) { + this.name = name; + this.price = price; + this.expiryDate = expiryDate; + } + + public String getName() { + return name; + } + + public String getExpiryDate() { + return expiryDate; + } + + public T getPrice() { + return price; + } + // public String toString(){ + // return this.name + " - " + this.price + " - " + this.expiryDate; + // } + +} + +class Uang{ + public Uang(int uang) { + this.uang = uang; + } + public int getUang(){ + return uang; + } + + private int uang; +} + +public class Main { + public static void main(String[] args) { + Product product1 = new Product<>("Kinder Joy", 1000, "2023-05-01"); + Product product2 = new Product<>("Sari Roti", "Rp.15.000", "2023-05-20"); + Product product3 = new Product<>("Susu Kurma", 7.5, "2023-06-01"); + Product product4 = new Product<>("Kit", new Uang(2000), "2023-05-10"); + + 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()); + System.out.println("Product 4: " + product4.getName()+ " - " + product4.getPrice().getUang() + " - " + product4.getExpiryDate()); + // System.out.println("Product 2: " + product2); + // System.out.println("Product 3: " + product3); + + } + + + +} diff --git a/src/H071221028/pertemuan_7/No3/Main.java b/src/H071221028/pertemuan_7/No3/Main.java new file mode 100644 index 0000000..ce0d4ac --- /dev/null +++ b/src/H071221028/pertemuan_7/No3/Main.java @@ -0,0 +1,78 @@ +import java.util.ArrayList; +import java.util.List; + + +interface Food { + public int getPrice(); +} + +class Burger implements Food{ + + @Override + public int getPrice() { + return 8; + } +} + +class Pizza implements Food{ + + @Override + public int getPrice() { + return 7; + } +} + +class Steak implements Food{ + + @Override + public int getPrice() { + return 20; + } +} +class FoodFactory { + static Food getFood(FoodType food) throws Exception { // bertipe data "Food" karena mengembalikan objek makanan yang sesuai jenisnya (sesuai perintah soal) + 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"); + throw new Exception(); + } + } +} + + +class Restaurant { + static int calculateTotal(List foods) { + int totalPrice = 0; + for (Food i : foods) { // perulangan untuk mengeluarkan objek-objeknya, i itu adalah objek-objek nya (burger,dll) + totalPrice += i.getPrice(); + } + return totalPrice; + } +} + +public class Main { + public static void main(String[] args) throws Exception { + 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.calculateTotal(foods); + + System.out.println("Total price: " + total); + } +} + +enum FoodType{ + burger, pizza, steak +} \ No newline at end of file