Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions src/H071221088/Pertemuan_6/No1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@

abstract class Dog {
int position;
int averageLenght;
abstract void move();
abstract void describe();
}

class Pitbull extends Dog {

@Override
void move() {
position=3;
System.out.println("Pitbull bergerak " + position + "langkah");
}

@Override
void describe() {
System.out.println("Pitbull biasanya memiliki otot yang kekar");
}

}

class siberianHusky extends Dog {

@Override
void move() {
position=2;
System.out.println("Siberian Husky bergerak " + position + " langkah");
}

@Override
void describe() {
System.out.println("Siberian Husky biasanya terlihat seperti serigala");
}

}

class Bulldog extends Dog {

@Override
void move() {
position=1;
System.out.println("Bulldog bergerak " + position + "langkah");
}

@Override
void describe() {
System.out.println("Bulldog memiliki tubuh yang kecil atau pendek");
}

}

class germanShepherd extends Dog {

@Override
void move() {
position=3;
System.out.println("German Shepherd bergerak " + position + "langkah");
}

@Override
void describe() {
System.out.println("German Shepherd memiliki berat antara 34-43kg");
}

}

interface SC {
void move();
}

class Smartphone implements SC {
int price;
String brand;

public Smartphone(int price, String brand) {
this.price = price;
this.brand = brand;
}
public void move() {
System.out.println("Smartphone berpindah");
}
}

class Car implements SC {
int totalForwardGear;
String color;
int maxSpeed;

public Car(int totalForwardGear, String color, int maxSpeed) {
this.totalForwardGear = totalForwardGear;
this.color = color;
this.maxSpeed = maxSpeed;
}
public void move() {
System.out.println("Mobil sedang berakselerasi");
}
}
12 changes: 12 additions & 0 deletions src/H071221088/Pertemuan_6/No2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
public class No2 {
public static void main(String[] args) {
Smartphone hp = new Smartphone(500, "Iphone");
hp.move();
Car oto = new Car(1, "black", 168);
oto.move();
siberianHusky ajg = new siberianHusky();
ajg.move();
ajg.describe();
}

}
55 changes: 55 additions & 0 deletions src/H071221088/Pertemuan_6/No3.plantuml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
@startum diagram

Dog <-- Pitbull
Dog <-- siberianHusky
Dog <-- Bulldog
Dog <-- germanShepherd

class Dog {
{static} #position : int
{static} #averageLenght : int
+ move() : void
+ describe() : void
}

class Pitbull {
+ move() : void
+ describe() : void
}

class siberianHusky {
+ move() : void
+ describe() : void
}

class Bulldog {
+ move() : void
+ describe() : void
}

class germanShepherd {
+ move() : void
+ describe() : void
}

SC <-- Smartphone
SC <-- Car

class SC {
+ move() : void
}

class Smartphone {
{static} #price : int
{static} #brand : string
+ move() : void
}

class Car {
{static} #totalForwardGear : int
{static} #color : string
{static} #maxSpeed : int
+ move() : void
}

@endum diagram
104 changes: 104 additions & 0 deletions src/H071221088/Pertemuan_7/No1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
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(); // bertujuan untuk mengatur serangan karakter

abstract int attack(String attackType); // bertujuan untuk mengatur serangan karakter dengan jenis serangan tertentu, yang ditentukan oleh parameter attackType.
}

class Fighter extends Character {

public Fighter(String name, int attackPower) {
super(name, attackPower);
}

@Override
int attack() {
return attackPower;
}

@Override
int attack(String attackType) {
int AP = attackPower;
if (attackType.equals("melee")) {
AP = attackPower * 2;
} else if (attackType.equals("ranged")) {
AP = attackPower;
}
return AP;
}

}

class Mage extends Character {

public Mage(String name, int attackPower) {
super(name, attackPower);
}

@Override
int attack() {
return attackPower;
}

@Override
int attack(String attackType) {
int kekuatanSerangan = attackPower;
if (attackType.equals("fire")) {
kekuatanSerangan = attackPower * 3 ;
} else if (attackType.equals("frost")) {
kekuatanSerangan = attackPower* 2 ;
}
return kekuatanSerangan;
}

}

public class No1 {
public static void printAttack(Character character) {
System.out.println("Nama : " + character.getName());
System.out.println("ATTAC INFORMATION");
System.out.println("Attack Power : " + character.attackPower);
if (character instanceof Fighter) {
System.out.println("Melee : " + character.attack("Melee"));
System.out.println("Ranged : " + character.attack("Ranged"));
} else if (character instanceof Mage) {
System.out.println("Fire : " + character.attack("Fire"));
System.out.println("Frost : " + character.attack("Frost"));
}
}
public static void main(String[] args) {
Fighter fighter = new Fighter("Ocang", 10);
Mage mage = new Mage("Fikry", 100);
Fighter faikter = new Fighter("Mayko", 1000);
Fighter petarung = new Fighter("Fylo", 10000);
Mage magee = new Mage("Delfa", 100000);

Character[] hero = new Character[5];
hero[0] = fighter;
hero[1] = mage;
hero[2] = faikter;
hero[3] = petarung;
hero[4] = magee;


for (Character i : hero) { // membuat perulangan untuk mengeluarkan objek2 yang ada pada list hero. objek2 tsb mau d print informasi ttg attack powernya, jdi dipanggil method print attack.
printAttack(i);// main, karena method static itu menempel pada kelasnya.
System.out.println("");
}
}
}
40 changes: 40 additions & 0 deletions src/H071221088/Pertemuan_7/No2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
class Product <T> {
protected String nama;
protected T harga;
protected String expire;
public String getNama() {
return nama;
}
public void setNama(String nama) {
this.nama = nama;
}
public T getHarga() {
return harga;
}
public void setHarga(T harga) {
this.harga = harga;
}
public String getExpire() {
return expire;
}
public void setExpire(String expire) {
this.expire = expire;
}
public Product(String nama, T harga, String expire) {
this.nama = nama;
this.harga = harga;
this.expire = expire;
}
}

public class No2 {
public static void main(String[] args) {
Product<Integer> product = new Product<>("Kinderjoy", 10000, "2023-05-01");
Product<String> productLagi = new Product<>("Sari Roti", "Rp 15.00", "2023-05-20");
Product<Double> productLagiLagi = new Product<>("Susu Kurma", 7.5, "2023-06-01");

System.out.println(product.getNama() + " - " + product.getHarga() + " - " + product.getExpire());
System.out.println(productLagi.getNama() + " - " + productLagi.getHarga() + " - " + productLagi.getExpire());
System.out.println(productLagiLagi.getNama() + " - " + productLagiLagi.getHarga() + " - " + productLagiLagi.getExpire());
}
}
12 changes: 12 additions & 0 deletions src/H071221088/Pertemuan_7/No3/Burger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package No3;

public class Burger implements Food{
protected int harga;

@Override
public int getPrice() {
return 1000000;
}


}
5 changes: 5 additions & 0 deletions src/H071221088/Pertemuan_7/No3/Food.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package No3;

interface Food {
int getPrice();
}
15 changes: 15 additions & 0 deletions src/H071221088/Pertemuan_7/No3/FoodFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package No3;

public class FoodFactory {
static Food getFood(String food) { // bertipe data "Food" karena mengembalikan objek makanan yang sesuai jenisnya (sesuai perintah soal)
Food makanan = null; // nilai default
if (food.equals("burger")) {
makanan = new Burger();
} else if (food.equals("pizza")) {
makanan = new Pizza();
} else if (food.equals("steak")) {
makanan = new Steak();
}
return makanan;
}
}
21 changes: 21 additions & 0 deletions src/H071221088/Pertemuan_7/No3/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package No3;

import java.util.List;
import java.util.ArrayList;

public class Main {
public static void main(String[] args) {
Food burger = FoodFactory.getFood("burger");
Food pizza = FoodFactory.getFood("pizza");
Food steak = FoodFactory.getFood("steak");

List<Food> foods = new ArrayList<>();
foods.add(burger);
foods.add(pizza);
foods.add(steak);

int total = Restaurant.calculateTotal(foods);

System.out.println("Total price: " + total);
}
}
11 changes: 11 additions & 0 deletions src/H071221088/Pertemuan_7/No3/Pizza.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package No3;

public class Pizza implements Food {
protected int harga;

@Override
public int getPrice() {
return 12000000;
}

}
12 changes: 12 additions & 0 deletions src/H071221088/Pertemuan_7/No3/Restaurant.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package No3;
import java.util.List;

public class Restaurant {
static int calculateTotal(List<Food> listMakanan) {
int totalPrice = 0;
for (Food i : listMakanan) { // perulangan untuk mengeluarkan objek-objeknya, i itu adalah objek-objek nya (burger,dll)
totalPrice += i.getPrice();
}
return totalPrice;
}
}
Loading