package dk.itu.oop.lecture5; public class CarPersonTest{ public static void main (String[] args){ Car c = new Car("Ford", new Person("Jack")); System.out.println(c); } } class Car{ /* inv: owner != null, and owner.myCar == this*/ private Person owner; private String make; /* pre: owner.myCar == null post: owner.myCar = this. */ public Car(String make, Person owner){ this.make = make; this.owner = owner; owner.setCar(this); } /* pre: owner.myCar == null post: owner.myCar == this */ public void setOwner(Person owner){ this.owner.setCar(null); this.owner = owner; owner.setCar(this); } public String toString(){ return make +" owned by " + owner; } } class Person{ /* inv: if myCar != null, myCar.owner = this.*/ private Car myCar; private String name; Person(String name){ this.name = name; }; /* pre: myCar == null, c.owner = this post: inv */ public void setCar(Car c){ myCar = c; } public String toString(){ return "Person " + name; } }