Tugas PPBO Week-1

Run Settings
LanguageJava
Language Version
Run Command
// Nama : Muhammad Daffa Rahman // NIM : l0124062 import java.util.ArrayList; import vehicle.Vehicle; import vehicle.Car; public class PPBO_01_L0124062 { public static void main(String[] args) { Campsite yosemite = new Campsite("Yosemite National Park", 2); Vehicle rv = new Car("RV Motorhome", 100, 2.0f, 4.5f); Car formulaAmba = new Car("Formula Amba", 690, 1.4f, 3.45f); formulaAmba.drive(20); yosemite.registerVehicle(formulaAmba); yosemite.registerVehicle(formulaAmba); yosemite.registerVehicle(rv); yosemite.unregisterVehicle(formulaAmba); } } class Campsite { private ArrayList<Vehicle> vehicles; public String name; private int capacity; public Campsite(String name, int capacity) { vehicles = new ArrayList<>(); this.name = name; this.capacity = capacity; } public void registerVehicle(Vehicle veh) { if(this.vehicles.contains(veh)) { System.out.println("Kendaraan " + veh.name + " sudah berada di campsite: " + this.name); } else { if(this.vehicles.size() < this.capacity) { vehicles.add(veh); System.out.println("Kendaraan " + veh.name + " teregistrasi ke campsite: " + this.name); } else { System.out.println("Campsite " + this.name + " sudah penuh!"); } } } public void unregisterVehicle(Vehicle veh) { if(this.vehicles.contains(veh)) { this.vehicles.remove(veh); System.out.println("Kendaraan " + veh.name + " telah di unregister dari campsite: " + this.name); } else { System.out.println("Kendaraan " + veh.name + " tidak ditemukan di campsite: " + this.name); } } }
package vehicle; public class Car extends Vehicle { public float width; public float length; public Car(String name, int topSpeed, float width, float length) { super(name, topSpeed); this.width = width; this.length = length; System.out.println("Mobil " + this.name + " berhasil dibuat"); } @Override public void drive(int speed) { if (speed >= 0 && speed <= topSpeed) { System.out.println(this.name + " is going vrooom vrooom ..... secepat " + speed + " km/h"); } else { System.out.println(this.name + " can't drive man at this speed"); } } }
package vehicle; public class Vehicle { public String name; public int topSpeed; public Vehicle(String name, int topSpeed) { this.name = name; this.topSpeed = topSpeed; } public void drive(int speed) { if (speed >= 0 && speed <= topSpeed) { System.out.println(this.name + " berjalan secepat " + speed + " km/h"); } else { System.out.println(this.name + " gaisa jalan cuy di kecepatan segini"); } } }
Editor Settings
Theme
Key bindings
Full width
Lines