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
11 changes: 11 additions & 0 deletions src/H071211014/Pertemuan6/Assignment_main_no1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class Assignment_main_no1 {
public static void main(String[] args) {
Smartphone android = new Smartphone(1000000, "Samsung");
android.move();
Car ferarri = new Car(6, "blue", 250);
ferarri.move();
Bulldog bulldog = new Bulldog(1, 100);
bulldog.move();
bulldog.describe();
}
}
17 changes: 17 additions & 0 deletions src/H071211014/Pertemuan6/Bulldog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public class Bulldog extends Dog {

Bulldog(int position, int averageLength) {
super(position, averageLength);
}

@Override
public void move() {
position += 1;
}

@Override
void describe() {
System.out.println("Pendek dan berwajah besar");
}

}
16 changes: 16 additions & 0 deletions src/H071211014/Pertemuan6/Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
public class Car implements Move{
int totalFowardGear;
String color;
int maxSpeed;

public Car(int totalFowardGear, String color, int maxSpeed) {
this.totalFowardGear = totalFowardGear;
this.color = color;
this.maxSpeed = maxSpeed;
}

@Override
public void move() {
System.out.println("Mobil sedang berakselerasi");
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
146 changes: 146 additions & 0 deletions src/H071211014/Pertemuan6/Diagram Class/diagramClass.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<mxfile host="app.diagrams.net" modified="2023-05-02T09:11:30.181Z" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36" etag="4wwSiuI07b8iAtSnhD_O" version="21.2.4" type="device">
<diagram id="C5RBs43oDa-KdzZeNtuy" name="Page-1">
<mxGraphModel dx="993" dy="578" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
<root>
<mxCell id="WIyWlLk6GJQsqaUBKTNV-0" />
<mxCell id="WIyWlLk6GJQsqaUBKTNV-1" parent="WIyWlLk6GJQsqaUBKTNV-0" />
<mxCell id="zkfFHV4jXpPFQw0GAbJ--0" value="Move" style="swimlane;fontStyle=2;align=center;verticalAlign=top;childLayout=stackLayout;horizontal=1;startSize=26;horizontalStack=0;resizeParent=1;resizeLast=0;collapsible=1;marginBottom=0;rounded=0;shadow=0;strokeWidth=1;" parent="WIyWlLk6GJQsqaUBKTNV-1" vertex="1">
<mxGeometry x="220" y="120" width="160" height="60" as="geometry">
<mxRectangle x="230" y="140" width="160" height="26" as="alternateBounds" />
</mxGeometry>
</mxCell>
<mxCell id="ixBVoI8oF5UoxdTUAyft-1" value="move()" style="text;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rounded=0;shadow=0;html=0;" vertex="1" parent="zkfFHV4jXpPFQw0GAbJ--0">
<mxGeometry y="26" width="160" height="26" as="geometry" />
</mxCell>
<mxCell id="zkfFHV4jXpPFQw0GAbJ--6" value="Car" style="swimlane;fontStyle=0;align=center;verticalAlign=top;childLayout=stackLayout;horizontal=1;startSize=26;horizontalStack=0;resizeParent=1;resizeLast=0;collapsible=1;marginBottom=0;rounded=0;shadow=0;strokeWidth=1;" parent="WIyWlLk6GJQsqaUBKTNV-1" vertex="1">
<mxGeometry x="120" y="370" width="160" height="110" as="geometry">
<mxRectangle x="130" y="380" width="160" height="26" as="alternateBounds" />
</mxGeometry>
</mxCell>
<mxCell id="zkfFHV4jXpPFQw0GAbJ--7" value="+totalFowardGear : Int" style="text;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;" parent="zkfFHV4jXpPFQw0GAbJ--6" vertex="1">
<mxGeometry y="26" width="160" height="26" as="geometry" />
</mxCell>
<mxCell id="zkfFHV4jXpPFQw0GAbJ--8" value="+color : String&#xa;" style="text;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rounded=0;shadow=0;html=0;" parent="zkfFHV4jXpPFQw0GAbJ--6" vertex="1">
<mxGeometry y="52" width="160" height="28" as="geometry" />
</mxCell>
<mxCell id="zkfFHV4jXpPFQw0GAbJ--10" value="+maxSpeed : Int" style="text;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;fontStyle=0" parent="zkfFHV4jXpPFQw0GAbJ--6" vertex="1">
<mxGeometry y="80" width="160" height="26" as="geometry" />
</mxCell>
<mxCell id="zkfFHV4jXpPFQw0GAbJ--12" value="" style="endArrow=block;endSize=10;endFill=0;shadow=0;strokeWidth=1;rounded=0;edgeStyle=elbowEdgeStyle;elbow=vertical;" parent="WIyWlLk6GJQsqaUBKTNV-1" source="zkfFHV4jXpPFQw0GAbJ--6" target="zkfFHV4jXpPFQw0GAbJ--0" edge="1">
<mxGeometry width="160" relative="1" as="geometry">
<mxPoint x="200" y="203" as="sourcePoint" />
<mxPoint x="200" y="203" as="targetPoint" />
<Array as="points">
<mxPoint x="300" y="270" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="zkfFHV4jXpPFQw0GAbJ--16" value="" style="endArrow=block;endSize=10;endFill=0;shadow=0;strokeWidth=1;rounded=0;edgeStyle=elbowEdgeStyle;elbow=vertical;exitX=0.5;exitY=0;exitDx=0;exitDy=0;" parent="WIyWlLk6GJQsqaUBKTNV-1" source="ixBVoI8oF5UoxdTUAyft-4" target="zkfFHV4jXpPFQw0GAbJ--0" edge="1">
<mxGeometry width="160" relative="1" as="geometry">
<mxPoint x="410" y="360" as="sourcePoint" />
<mxPoint x="310" y="271" as="targetPoint" />
<Array as="points">
<mxPoint x="300" y="270" />
<mxPoint x="310" y="270" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="ixBVoI8oF5UoxdTUAyft-4" value="Smartphone" style="swimlane;fontStyle=0;align=center;verticalAlign=top;childLayout=stackLayout;horizontal=1;startSize=26;horizontalStack=0;resizeParent=1;resizeLast=0;collapsible=1;marginBottom=0;rounded=0;shadow=0;strokeWidth=1;" vertex="1" parent="WIyWlLk6GJQsqaUBKTNV-1">
<mxGeometry x="330" y="370" width="160" height="80" as="geometry">
<mxRectangle x="130" y="380" width="160" height="26" as="alternateBounds" />
</mxGeometry>
</mxCell>
<mxCell id="ixBVoI8oF5UoxdTUAyft-5" value="+price : Int" style="text;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;" vertex="1" parent="ixBVoI8oF5UoxdTUAyft-4">
<mxGeometry y="26" width="160" height="26" as="geometry" />
</mxCell>
<mxCell id="ixBVoI8oF5UoxdTUAyft-6" value="+brand : String&#xa;" style="text;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rounded=0;shadow=0;html=0;" vertex="1" parent="ixBVoI8oF5UoxdTUAyft-4">
<mxGeometry y="52" width="160" height="28" as="geometry" />
</mxCell>
<mxCell id="ixBVoI8oF5UoxdTUAyft-8" value="Dog" style="swimlane;fontStyle=0;align=center;verticalAlign=top;childLayout=stackLayout;horizontal=1;startSize=26;horizontalStack=0;resizeParent=1;resizeLast=0;collapsible=1;marginBottom=0;rounded=0;shadow=0;strokeWidth=1;" vertex="1" parent="WIyWlLk6GJQsqaUBKTNV-1">
<mxGeometry x="540" y="370" width="160" height="140" as="geometry">
<mxRectangle x="130" y="380" width="160" height="26" as="alternateBounds" />
</mxGeometry>
</mxCell>
<mxCell id="ixBVoI8oF5UoxdTUAyft-9" value="+position : Int" style="text;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;" vertex="1" parent="ixBVoI8oF5UoxdTUAyft-8">
<mxGeometry y="26" width="160" height="26" as="geometry" />
</mxCell>
<mxCell id="ixBVoI8oF5UoxdTUAyft-10" value="+averageLength : Int" style="text;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rounded=0;shadow=0;html=0;" vertex="1" parent="ixBVoI8oF5UoxdTUAyft-8">
<mxGeometry y="52" width="160" height="28" as="geometry" />
</mxCell>
<mxCell id="ixBVoI8oF5UoxdTUAyft-11" value="+maxSpeed : Int" style="text;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;fontStyle=0" vertex="1" parent="ixBVoI8oF5UoxdTUAyft-8">
<mxGeometry y="80" width="160" height="30" as="geometry" />
</mxCell>
<mxCell id="ixBVoI8oF5UoxdTUAyft-17" value="&amp;nbsp;+describe()" style="text;html=1;align=left;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="ixBVoI8oF5UoxdTUAyft-8">
<mxGeometry y="110" width="160" height="30" as="geometry" />
</mxCell>
<mxCell id="ixBVoI8oF5UoxdTUAyft-12" value="" style="endArrow=none;html=1;rounded=0;" edge="1" parent="WIyWlLk6GJQsqaUBKTNV-1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="410" y="270" as="sourcePoint" />
<mxPoint x="620" y="270" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="ixBVoI8oF5UoxdTUAyft-13" value="" style="endArrow=none;html=1;rounded=0;exitX=0.5;exitY=0;exitDx=0;exitDy=0;" edge="1" parent="WIyWlLk6GJQsqaUBKTNV-1" source="ixBVoI8oF5UoxdTUAyft-8">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="570" y="320" as="sourcePoint" />
<mxPoint x="620" y="270" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="ixBVoI8oF5UoxdTUAyft-16" value="" style="endArrow=none;html=1;rounded=0;" edge="1" parent="WIyWlLk6GJQsqaUBKTNV-1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="540" y="480" as="sourcePoint" />
<mxPoint x="700" y="480" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="ixBVoI8oF5UoxdTUAyft-38" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;entryPerimeter=0;" edge="1" parent="WIyWlLk6GJQsqaUBKTNV-1" source="ixBVoI8oF5UoxdTUAyft-21" target="ixBVoI8oF5UoxdTUAyft-17">
<mxGeometry relative="1" as="geometry">
<mxPoint x="429.5" y="510" as="targetPoint" />
<Array as="points">
<mxPoint x="430" y="550" />
<mxPoint x="620" y="550" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="ixBVoI8oF5UoxdTUAyft-21" value="Pitbull" style="swimlane;fontStyle=0;align=center;verticalAlign=top;childLayout=stackLayout;horizontal=1;startSize=26;horizontalStack=0;resizeParent=1;resizeLast=0;collapsible=1;marginBottom=0;rounded=0;shadow=0;strokeWidth=1;" vertex="1" parent="WIyWlLk6GJQsqaUBKTNV-1">
<mxGeometry x="350" y="585" width="160" height="25" as="geometry">
<mxRectangle x="130" y="380" width="160" height="26" as="alternateBounds" />
</mxGeometry>
</mxCell>
<mxCell id="ixBVoI8oF5UoxdTUAyft-41" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="WIyWlLk6GJQsqaUBKTNV-1" source="ixBVoI8oF5UoxdTUAyft-24" target="ixBVoI8oF5UoxdTUAyft-17">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="ixBVoI8oF5UoxdTUAyft-24" value="SiberianHusky" style="swimlane;fontStyle=0;align=center;verticalAlign=top;childLayout=stackLayout;horizontal=1;startSize=26;horizontalStack=0;resizeParent=1;resizeLast=0;collapsible=1;marginBottom=0;rounded=0;shadow=0;strokeWidth=1;" vertex="1" parent="WIyWlLk6GJQsqaUBKTNV-1">
<mxGeometry x="540" y="585" width="160" height="25" as="geometry">
<mxRectangle x="130" y="380" width="160" height="26" as="alternateBounds" />
</mxGeometry>
</mxCell>
<mxCell id="ixBVoI8oF5UoxdTUAyft-46" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="WIyWlLk6GJQsqaUBKTNV-1" source="ixBVoI8oF5UoxdTUAyft-27">
<mxGeometry relative="1" as="geometry">
<mxPoint x="619" y="510" as="targetPoint" />
<Array as="points">
<mxPoint x="810" y="550" />
<mxPoint x="619" y="550" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="ixBVoI8oF5UoxdTUAyft-27" value="Bulldog" style="swimlane;fontStyle=0;align=center;verticalAlign=top;childLayout=stackLayout;horizontal=1;startSize=26;horizontalStack=0;resizeParent=1;resizeLast=0;collapsible=1;marginBottom=0;rounded=0;shadow=0;strokeWidth=1;" vertex="1" parent="WIyWlLk6GJQsqaUBKTNV-1">
<mxGeometry x="730" y="585" width="160" height="25" as="geometry">
<mxRectangle x="130" y="380" width="160" height="26" as="alternateBounds" />
</mxGeometry>
</mxCell>
<mxCell id="ixBVoI8oF5UoxdTUAyft-47" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.502;entryY=0.983;entryDx=0;entryDy=0;entryPerimeter=0;" edge="1" parent="WIyWlLk6GJQsqaUBKTNV-1" source="ixBVoI8oF5UoxdTUAyft-30" target="ixBVoI8oF5UoxdTUAyft-17">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="1000" y="550" />
<mxPoint x="620" y="550" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="ixBVoI8oF5UoxdTUAyft-30" value="GermanShepperd" style="swimlane;fontStyle=0;align=center;verticalAlign=top;childLayout=stackLayout;horizontal=1;startSize=26;horizontalStack=0;resizeParent=1;resizeLast=0;collapsible=1;marginBottom=0;rounded=0;shadow=0;strokeWidth=1;" vertex="1" parent="WIyWlLk6GJQsqaUBKTNV-1">
<mxGeometry x="920" y="585" width="160" height="25" as="geometry">
<mxRectangle x="130" y="380" width="160" height="26" as="alternateBounds" />
</mxGeometry>
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>
11 changes: 11 additions & 0 deletions src/H071211014/Pertemuan6/Dog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
abstract class Dog implements Move{
int position;
int averageLength;
abstract void describe();

Dog(int position, int averageLength) {
this.position = position;
this.averageLength = averageLength;
}
}

17 changes: 17 additions & 0 deletions src/H071211014/Pertemuan6/GermanShepperd.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public class GermanShepperd extends Dog{

GermanShepperd(int position, int averageLength) {
super(position, averageLength);
}

@Override
public void move() {
position += 3;
}

@Override
void describe() {
System.out.println("Besar dan bertelinga lebar");
}

}
3 changes: 3 additions & 0 deletions src/H071211014/Pertemuan6/Move.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
interface Move {
void move();
}
17 changes: 17 additions & 0 deletions src/H071211014/Pertemuan6/Pitbull.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public 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("Berbadan besar dan kekar");
}

}
17 changes: 17 additions & 0 deletions src/H071211014/Pertemuan6/SiberianHusky.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public class SiberianHusky extends Dog {

SiberianHusky(int position, int averageLength) {
super(position, averageLength);
}

@Override
public void move() {
position += 2;
}

@Override
void describe() {
System.out.println("Mirip Serigala");
}

}
14 changes: 14 additions & 0 deletions src/H071211014/Pertemuan6/Smartphone.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class Smartphone implements Move{
int price;
String brand;

public Smartphone(int price, String brand) {
this.price = price;
this.brand = brand;
}

@Override
public void move() {
System.out.println("Smartphone berpindah");
}
}
25 changes: 25 additions & 0 deletions src/H071211014/Pertemuan7/Assignment_no1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
public class Assignment_no1 {
public static void main(String[] args) {
Character[] characters = new Character[5];
characters[0] = new Fighter(2);
characters[1] = new Mage(3);
characters[2] = new Fighter(5);
characters[3] = new Fighter(4);
characters[4] = new Mage(12);

for(Character character : characters){
printAttack(character);
}
}

private static void printAttack(Character character){
System.out.println(character.attack());
if (character instanceof Fighter){
System.out.println(character.attack("melee"));
System.out.println(character.attack("ranged"));
}else if (character instanceof Mage){
System.out.println(character.attack("fire"));
System.out.println(character.attack("frost"));
}
}
}
16 changes: 16 additions & 0 deletions src/H071211014/Pertemuan7/Assignment_no2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
public class Assignment_no2 {
public static void main(String[] args) {
Product<Integer>product1 = new Product<Integer>("Indomie", "2024-01-01", 5000);
Product<Double>product2 = new Product<Double>("Ultra Milk", "2024-06-24", 6000.00);
Product<String>product3 = new Product<String>("Teh Kotak", "2024-12-31", "5000");

printProduct(product1);
printProduct(product2);
printProduct(product3);

}
private static void printProduct(Product product){
System.out.println(product.getName() + " - " + product.getExpiryDate() + " - " + product.getPrice());
}
}

20 changes: 20 additions & 0 deletions src/H071211014/Pertemuan7/Assignment_no3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import java.util.ArrayList;
import java.util.List;

public class Assignment_no3 {
private static Food steak;

public static void main(String[] args) {
Food burger = FoodFactory.getFood(FoodType.BURGER);
Food pizza = FoodFactory.getFood(FoodType.PIZZA);
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);

}
}
9 changes: 9 additions & 0 deletions src/H071211014/Pertemuan7/Burger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public class Burger implements Food {
private final int price = 20000;

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

}
10 changes: 10 additions & 0 deletions src/H071211014/Pertemuan7/Character.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
abstract class Character{
private String name;

public String getName() {
return name;
}

abstract int attack();
abstract int attack(String attackType);
}
32 changes: 32 additions & 0 deletions src/H071211014/Pertemuan7/Fighter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
public class Fighter extends Character {
private int attackPower;
public int getAttackPower() {
return attackPower;
}

public void setAttackPower(int attackPower) {
this.attackPower = attackPower;
}

public Fighter(int attackPower) {
this.attackPower = attackPower;
}

@Override
int attack() {
return attackPower;

}

@Override
int attack(String attackType) {
if(attackType.equalsIgnoreCase("melee")){
return attackPower*2;
} else if(attackType.equalsIgnoreCase("ranged")){
return attackPower;
}else{
return -1;
}
}

}
Loading