Skip to content

CRC > UML > CODE

Estimated time to read: 2 minutes

CRC

Example CRC

Car
Responsibilities
Collaborators
Turn on Turn off Move Carry Passengers Carry Cargo Driver Passengers Cargo Mechanic Engine Breaks

UML

UML card

Car
Attributes
- age: int - colour: string - brand: string - doors: int - wheels: int - engineType: string - fuel: string - operational: boolean
Methods
- enginePower(power:boolean): boolean - engineAccelerate(): void - doorLock(): void + getCarDetails(): String + getModel(): String + *getters(); - *setters();

Code

public class Car {
    private int age;
 private String colour;
 private String model;
 private String brand;
 private int doors;
 private int wheels;
 private String engineType;
 private String fuelType;
 private boolean operational;

    public Car(int ageInit; String colourInit; String modelInit; String brandInit; int doorsInit; int wheelsInit; String engineTypeInit; String fuelTypeInit; boolean operationalInit) {
        this.age = ageInit;
        this.colour = colourInit;
  this.model = modelInit; 
  this.brand = brandInit;
  this.doors = doorsInit;
  this.wheels = wheelsInit;
  this.engineType = engineTypeInit;
  this.fuelType = fuelTypeInit;
  this.operational = operationalInit;
    }

 public boolean enginePower(boolean power){
  if (power) {
   startEngine();
  }
  else {
   stopEngine();
  }
 }

    public String getCarDetails() {
  carDetails = "The " this.model + " is "+  this.age + " years old";
        return carDetails
    }

    public String getModel() {
        return this.model;
    }
}