0% found this document useful (0 votes)
6 views6 pages

Class Diagram

The document provides a Java implementation of a car simulation using various classes such as Car, Engine, and GearBox. It includes attributes and methods for each class, demonstrating how to create and manipulate a Car object. The main program simulates actions like starting the engine, moving forward, and stopping the car.

Uploaded by

Siti Nurcica
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views6 pages

Class Diagram

The document provides a Java implementation of a car simulation using various classes such as Car, Engine, and GearBox. It includes attributes and methods for each class, demonstrating how to create and manipulate a Car object. The main program simulates actions like starting the engine, moving forward, and stopping the car.

Uploaded by

Siti Nurcica
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Implementasi class diagram yang diberikan dalam bahasa

pemrograman Java:
Nama : Siti Nurcica
NIM : 2023071069
class CarModel {

String title;

byte attribute;

void operation() {

// Implementasi operasi

class GearBoxType {

String name;

String remarks;

class GearBox {

float[] gearRatio;

int currentGear;

void shiftUp() {

// Implementasi shift up

void shiftDown() {

// Implementasi shift down

}
class Suspension {

float springRate;

class Wheel {

float diameter;

class Tire {

float width;

float airPressure;

class Brake {

String type;

void apply() {

// Implementasi rem

class Engine {

float capacity;

int numberOfCylinders;

void start() {

// Implementasi mesin menyala

void brake() {

// Implementasi pengereman mesin


}

void accelerate() {

// Implementasi akselerasi

class Body {

int numberOfDoors;

class Car {

String registrationNum;

int year;

String licenseNumber;

CarModel model;

GearBox gearBox;

Engine engine;

Body body;

Suspension suspension;

Wheel wheel;

Brake brake;

Tire tire;

void moveForward() {

// Implementasi maju

void moveBackward() {

// Implementasi mundur
}

void stop() {

// Implementasi berhenti

void turnRight() {

// Implementasi belok kanan

void turnLeft() {

// Implementasi belok kiri

PEMOGRAMAN UTAMA

public class Main {

public static void main(String[] args) {

// Membuat objek Car

Car myCar = new Car();

myCar.registrationNum = "B 1234 ABC";

myCar.year = 2023;

myCar.licenseNumber = "ID-56789";

// Membuat dan menghubungkan objek lainnya

myCar.model = new CarModel();

myCar.model.title = "Sedan Sport";

myCar.model.attribute = 1;
myCar.engine = new Engine();

myCar.engine.capacity = 2.0f;

myCar.engine.numberOfCylinders = 4;

myCar.gearBox = new GearBox();

myCar.gearBox.currentGear = 1;

myCar.body = new Body();

myCar.body.numberOfDoors = 4;

// Menjalankan metode

System.out.println("Mobil dengan plat: " + myCar.registrationNum);

System.out.println("Model: " + myCar.model.title);

System.out.println("Tahun: " + myCar.year);

System.out.println("Kapasitas Mesin: " + myCar.engine.capacity + "L");

System.out.println("Jumlah Silinder: " + myCar.engine.numberOfCylinders);

System.out.println("Jumlah Pintu: " + myCar.body.numberOfDoors);

// Simulasi aksi

System.out.println("Mesin dinyalakan...");

myCar.engine.start();

System.out.println("Mobil bergerak maju...");

myCar.moveForward();

System.out.println("Mobil berhenti...");

myCar.stop();

}
Output

You might also like