Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Need help with multi-threading assignment (Buyer/Seller) in java eclipse

I must implement my run methods for buyer and seller in such a way that the buyer doesn't immediately buy from carshowroom list after appearing and seller doesn't immediately sell a car after showing up on list.

Below is my code and the output for it

package Assignment2Multithreading;

import java.util.Random;

public class Main {

public static void main(String args[]) throws InterruptedException {

    CarShowroom c = new CarShowroom();

    for(int i = 1; i<=30; i++) {

        Seller s = new Seller(c);

        Buyer b = new Buyer(c);

        if(c.numCarsInShowroom() == 1) {
            System.out.println("\nDay " + String.valueOf(i) + " There is one car in the show room today.\n");



        }
        else {
            System.out.println("\nDay " + String.valueOf(i) + " There are " + c.numCarsInShowroom() + " cars in the show room today.\n");

        }

        s.init();

        b.init();

        Thread.sleep(1000);


    }


}

}

package Assignment2Multithreading;

import java.util.ArrayList; import java.util.Random; import java.util.concurrent.atomic.AtomicInteger;

public class CarShowroom {

public static final int fullCapacity = 10;

private ArrayList<Car> carList= new ArrayList<Car>();

AtomicInteger saleNumber = new AtomicInteger();


public CarShowroom() {

}

public boolean isEmpty() {

    if(this.carList.isEmpty()) {

        return true;


    }
    return false;
}

public boolean isFull() {

    if(carList.size() == fullCapacity) {

        return true;
    }

    return false;
}

public synchronized void addCar(Car c) {


    carList.add(c);


}


public synchronized Car takeCar() {

    Car car = carList.remove(0);


    return car;
}




public int numCarsInShowroom() {

    return carList.size();
}

}

package Assignment2Multithreading;

import java.util.Random; import java.util.concurrent.atomic.AtomicInteger;

public class Seller implements Runnable{

CarShowroom carshowroom;

public Car car;

Random rand = new Random();

int numSale;

private static AtomicInteger sellerID  = new AtomicInteger(0);

private static AtomicInteger saleNumber = new AtomicInteger(0);

//private static long sellerID = 0;

/*public static synchronized String createSellerID()
{
    return String.valueOf(++sellerID);
} */


public Seller() {


    this.carshowroom = new CarShowroom();
    this.car = new Car();

}



public Seller(CarShowroom c) {


    this.carshowroom = c;
    this.car = new Car();
}

public void init() {

    Thread t;

    int n = rand.nextInt(3)+ 1;

    for(int i =0 ; i< n; i++) {

        t = new Thread(this);
        t.start();
    }

}






public void run() {




    synchronized(carshowroom) {


        try {

            sellerID.getAndIncrement();

            System.out.println("A new seller # " + sellerID + " just appeared with " + car + " to sell.");



            while(carshowroom.isFull()) {

                System.out.println("Seller # "+ sellerID + " is trying to sell a car but the showroom is full.");

                carshowroom.wait();
            }

            Thread.sleep(20);

            carshowroom.addCar(car);

            saleNumber.getAndIncrement();

            System.out.println("Seller # "+ sellerID + " sold "+ car);

            System.out.println("This is sale number " + saleNumber);

            //wait(1000);

            carshowroom.notifyAll();




        }catch(Exception e) {

            e.printStackTrace();
        }
    }


}

}

package Assignment2Multithreading;

import java.util.Random; import java.util.UUID; import java.util.concurrent.atomic.AtomicInteger;

public class Buyer implements Runnable{

CarShowroom carshowroom;

private static AtomicInteger newPurchase  = new AtomicInteger(0);

private static AtomicInteger buyerID = new AtomicInteger(0);

Random rand = new Random();

Car car;


public Buyer() {

    this.carshowroom = new CarShowroom();



}

public Buyer(CarShowroom c) {

    this.carshowroom = c;
}

public void init() { // we create the threads from within a method in the task class (that's fine)
    Thread t;


    int n = rand.nextInt(3) + 1;


    for(int j=0 ; j< n; j++) {



        t = new Thread(this); 
        t.start();




    }
}




public void run() {



    synchronized(carshowroom){

        try {


            buyerID.getAndIncrement();

            System.out.println("A new buyer # " + buyerID + " has appeared");




            while(carshowroom.isEmpty()) {

                System.out.println("Buyer # " + buyerID + " is trying to buy a car but the showroom is empty.");

                carshowroom.wait();

            }

            Thread.sleep(20);

            Car car = carshowroom.takeCar();




            newPurchase.getAndIncrement();

            System.out.println("Buyer # " + buyerID + " bought " + car);

            System.out.println("This is purchase number " + newPurchase);


            carshowroom.notifyAll();





        }catch(Exception e) {
            e.printStackTrace();
        }

    }


}

}

Day 1 There are 0 cars in the show room today.

A new seller # 1 just appeared with yellow car with registration 39-KY-8621 worth €16299 to sell. Seller # 1 sold yellow car with registration 39-KY-8621 worth €16299 This is sale number 1 A new buyer # 1 has appeared Buyer # 1 bought yellow car with registration 39-KY-8621 worth €16299 This is purchase number 1 A new buyer # 2 has appeared Buyer # 2 is trying to buy a car but the showroom is empty. A new seller # 2 just appeared with yellow car with registration 39-KY-8621 worth €16299 to sell. Seller # 2 sold yellow car with registration 39-KY-8621 worth €16299 This is sale number 2 Buyer # 2 bought yellow car with registration 39-KY-8621 worth €16299 This is purchase number 2

Day 2 There are 0 cars in the show room today.

A new seller # 3 just appeared with black car with registration 83-CE-1538 worth €13490 to sell. Seller # 3 sold black car with registration 83-CE-1538 worth €13490 This is sale number 3 A new buyer # 3 has appeared Buyer # 3 bought black car with registration 83-CE-1538 worth €13490 This is purchase number 3

Day 3 There are 0 cars in the show room today.

A new seller # 4 just appeared with yellow car with registration 84-LH-318 worth €3570 to sell. Seller # 4 sold yellow car with registration 84-LH-318 worth €3570 This is sale number 4 A new buyer # 4 has appeared Buyer # 4 bought yellow car with registration 84-LH-318 worth €3570 This is purchase number 4 A new buyer # 5 has appeared Buyer # 5 is trying to buy a car but the showroom is empty. A new seller # 5 just appeared with yellow car with registration 84-LH-318 worth €3570 to sell. Seller # 5 sold yellow car with registration 84-LH-318 worth €3570 This is sale number 5 A new seller # 6 just appeared with yellow car with registration 84-LH-318 worth €3570 to sell. Seller # 6 sold yellow car with registration 84-LH-318 worth €3570 This is sale number 6 Buyer # 5 bought yellow car with registration 84-LH-318 worth €3570 This is purchase number 5

Day 4 There is one car in the show room today.

A new seller # 7 just appeared with black car with registration 72-T-5799 worth €613 to sell. Seller # 7 sold black car with registration 72-T-5799 worth €613 This is sale number 7 A new buyer # 6 has appeared Buyer # 6 bought yellow car with registration 84-LH-318 worth €3570 This is purchase number 6 A new buyer # 7 has appeared Buyer # 7 bought black car with registration 72-T-5799 worth €613 This is purchase number 7

Day 5 There are 0 cars in the show room today.

A new seller # 8 just appeared with black car with registration 47-OY-5300 worth €9291 to sell. Seller # 8 sold black car with registration 47-OY-5300 worth €9291 This is sale number 8 A new buyer # 8 has appeared Buyer # 8 bought black car with registration 47-OY-5300 worth €9291 This is purchase number 8 A new buyer # 9 has appeared Buyer # 9 is trying to buy a car but the showroom is empty. A new buyer # 10 has appeared Buyer # 10 is trying to buy a car but the showroom is empty. A new seller # 9 just appeared with black car with registration 47-OY-5300 worth €9291 to sell. Seller # 9 sold black car with registration 47-OY-5300 worth €9291 This is sale number 9 Buyer # 10 bought black car with registration 47-OY-5300 worth €9291 This is purchase number 9 Buyer # 10 is trying to buy a car but the showroom is empty.

Day 6 There are 0 cars in the show room today.

A new seller # 10 just appeared with blue car with registration 67-WH-9581 worth €4976 to sell. Seller # 10 sold blue car with registration 67-WH-9581 worth €4976 This is sale number 10 Buyer # 10 bought blue car with registration 67-WH-9581 worth €4976 This is purchase number 10 A new buyer # 11 has appeared Buyer # 11 is trying to buy a car but the showroom is empty. A new buyer # 12 has appeared Buyer # 12 is trying to buy a car but the showroom is empty.

Day 7 There are 0 cars in the show room today.

A new seller # 11 just appeared with black car with registration 5-WH-1705 worth €9466 to sell. Seller # 11 sold black car with registration 5-WH-1705 worth €9466 This is sale number 11 Buyer # 12 bought black car with registration 5-WH-1705 worth €9466 This is purchase number 11 Buyer # 12 is trying to buy a car but the showroom is empty. A new buyer # 13 has appeared Buyer # 13 is trying to buy a car but the showroom is empty. A new buyer # 14 has appeared Buyer # 14 is trying to buy a car but the showroom is empty. A new seller # 12 just appeared with black car with registration 5-WH-1705 worth €9466 to sell. Seller # 12 sold black car with registration 5-WH-1705 worth €9466 This is sale number 12 A new seller # 13 just appeared with black car with registration 5-WH-1705 worth €9466 to sell. Seller # 13 sold black car with registration 5-WH-1705 worth €9466 This is sale number 13 Buyer # 14 bought black car with registration 5-WH-1705 worth €9466 This is purchase number 12 Buyer # 14 bought black car with registration 5-WH-1705 worth €9466 This is purchase number 13 Buyer # 14 is trying to buy a car but the showroom is empty.

Day 8 There are 0 cars in the show room today.

A new seller # 14 just appeared with red car with registration 60-LH-2011 worth €12711 to sell. Seller # 14 sold red car with registration 60-LH-2011 worth €12711 This is sale number 14 Buyer # 14 bought red car with registration 60-LH-2011 worth €12711 This is purchase number 14 A new buyer # 15 has appeared Buyer # 15 is trying to buy a car but the showroom is empty. A new buyer # 16 has appeared Buyer # 16 is trying to buy a car but the showroom is empty. A new seller # 15 just appeared with red car with registration 60-LH-2011 worth €12711 to sell. Seller # 15 sold red car with registration 60-LH-2011 worth €12711 This is sale number 15 A new seller # 16 just appeared with red car with registration 60-LH-2011 worth €12711 to sell. Seller # 16 sold red car with registration 60-LH-2011 worth €12711 This is sale number 16 Buyer # 16 bought red car with registration 60-LH-2011 worth €12711 This is purchase number 15 Buyer # 16 bought red car with registration 60-LH-2011 worth €12711 This is purchase number 16

Day 9 There are 0 cars in the show room today.

A new seller # 17 just appeared with blue car with registration 91-LS-9839 worth €5057 to sell. Seller # 17 sold blue car with registration 91-LS-9839 worth €5057 This is sale number 17 A new buyer # 17 has appeared Buyer # 17 bought blue car with registration 91-LS-9839 worth €5057 This is purchase number 17 A new seller # 18 just appeared with blue car with registration 91-LS-9839 worth €5057 to sell. Seller # 18 sold blue car with registration 91-LS-9839 worth €5057 This is sale number 18

Day 10 There is one car in the show room today.

A new seller # 19 just appeared with green car with registration 51-OY-7800 worth €17830 to sell. Seller # 19 sold green car with registration 51-OY-7800 worth €17830 This is sale number 19 A new buyer # 18 has appeared Buyer # 18 bought blue car with registration 91-LS-9839 worth €5057 This is purchase number 18

Day 11 There is one car in the show room today.

A new seller # 20 just appeared with blue car with registration 52-WH-5776 worth €4073 to sell. Seller # 20 sold blue car with registration 52-WH-5776 worth €4073 This is sale number 20 A new buyer # 19 has appeared Buyer # 19 bought green car with registration 51-OY-7800 worth €17830 This is purchase number 19 A new buyer # 20 has appeared Buyer # 20 bought blue car with registration 52-WH-5776 worth €4073 This is purchase number 20 A new buyer # 21 has appeared Buyer # 21 is trying to buy a car but the showroom is empty. A new seller # 21 just appeared with blue car with registration 52-WH-5776 worth €4073 to sell. Seller # 21 sold blue car with registration 52-WH-5776 worth €4073 This is sale number 21 Buyer # 21 bought blue car with registration 52-WH-5776 worth €4073 This is purchase number 21

Day 12 There are 0 cars in the show room today.

A new seller # 22 just appeared with black car with registration 73-W-216 worth €3267 to sell. Seller # 22 sold black car with registration 73-W-216 worth €3267 This is sale number 22 A new buyer # 22 has appeared Buyer # 22 bought black car with registration 73-W-216 worth €3267 This is purchase number 22

Day 13 There are 0 cars in the show room today.

A new seller # 23 just appeared with silver car with registration 97-KY-673 worth €151 to sell. Seller # 23 sold silver car with registration 97-KY-673 worth €151 This is sale number 23 A new buyer # 23 has appeared Buyer # 23 bought silver car with registration 97-KY-673 worth €151 This is purchase number 23 A new buyer # 24 has appeared Buyer # 24 is trying to buy a car but the showroom is empty.

Day 14 There are 0 cars in the show room today.

A new seller # 24 just appeared with green car with registration 46-KK-4063 worth €5568 to sell. Seller # 24 sold green car with registration 46-KK-4063 worth €5568 This is sale number 24 Buyer # 24 bought green car with registration 46-KK-4063 worth €5568 This is purchase number 24 A new buyer # 25 has appeared Buyer # 25 is trying to buy a car but the showroom is empty. A new buyer # 26 has appeared Buyer # 26 is trying to buy a car but the showroom is empty. A new buyer # 27 has appeared Buyer # 27 is trying to buy a car but the showroom is empty. A new seller # 25 just appeared with green car with registration 46-KK-4063 worth €5568 to sell. Seller # 25 sold green car with registration 46-KK-4063 worth €5568 This is sale number 25 A new seller # 26 just appeared with green car with registration 46-KK-4063 worth €5568 to sell. Seller # 26 sold green car with registration 46-KK-4063 worth €5568 This is sale number 26 Buyer # 27 bought green car with registration 46-KK-4063 worth €5568 This is purchase number 25 Buyer # 27 bought green car with registration 46-KK-4063 worth €5568 This is purchase number 26 Buyer # 27 is trying to buy a car but the showroom is empty.

Day 15 There are 0 cars in the show room today.

A new seller # 27 just appeared with silver car with registration 17-LH-6046 worth €12063 to sell. Seller # 27 sold silver car with registration 17-LH-6046 worth €12063 This is sale number 27 Buyer # 27 bought silver car with registration 17-LH-6046 worth €12063 This is purchase number 27 A new buyer # 28 has appeared Buyer # 28 is trying to buy a car but the showroom is empty. A new buyer # 29 has appeared Buyer # 29 is trying to buy a car but the showroom is empty. A new buyer # 30 has appeared Buyer # 30 is trying to buy a car but the showroom is empty. A new seller # 28 just appeared with silver car with registration 17-LH-6046 worth €12063 to sell. Seller # 28 sold silver car with registration 17-LH-6046 worth €12063 This is sale number 28 A new seller # 29 just appeared with silver car with registration 17-LH-6046 worth €12063 to sell. Seller # 29 sold silver car with registration 17-LH-6046 worth €12063 This is sale number 29 Buyer # 30 bought silver car with registration 17-LH-6046 worth €12063 This is purchase number 28 Buyer # 30 bought silver car with registration 17-LH-6046 worth €12063 This is purchase number 29 Buyer # 30 is trying to buy a car but the showroom is empty.

Day 16 There are 0 cars in the show room today.

A new seller # 30 just appeared with yellow car with registration 61-W-7827 worth €2743 to sell. Seller # 30 sold yellow car with registration 61-W-7827 worth €2743 This is sale number 30 Buyer # 30 bought yellow car with registration 61-W-7827 worth €2743 This is purchase number 30 A new buyer # 31 has appeared Buyer # 31 is trying to buy a car but the showroom is empty. A new buyer # 32 has appeared Buyer # 32 is trying to buy a car but the showroom is empty. A new buyer # 33 has appeared Buyer # 33 is trying to buy a car but the showroom is empty.

Day 17 There are 0 cars in the show room today.

A new seller # 31 just appeared with green car with registration 67-MH-4999 worth €2728 to sell. Seller # 31 sold green car with registration 67-MH-4999 worth €2728 This is sale number 31 Buyer # 33 bought green car with registration 67-MH-4999 worth €2728 This is purchase number 31 Buyer # 33 is trying to buy a car but the showroom is empty. Buyer # 33 is trying to buy a car but the showroom is empty. A new buyer # 34 has appeared Buyer # 34 is trying to buy a car but the showroom is empty. A new seller # 32 just appeared with green car with registration 67-MH-4999 worth €2728 to sell. Seller # 32 sold green car with registration 67-MH-4999 worth €2728 This is sale number 32 Buyer # 34 bought green car with registration 67-MH-4999 worth €2728 This is purchase number 32 Buyer # 34 is trying to buy a car but the showroom is empty. Buyer # 34 is trying to buy a car but the showroom is empty.

Day 18 There are 0 cars in the show room today.

A new seller # 33 just appeared with black car with registration 61-C-8774 worth €10371 to sell. Seller # 33 sold black car with registration 61-C-8774 worth €10371 This is sale number 33 Buyer # 34 bought black car with registration 61-C-8774 worth €10371 This is purchase number 33 Buyer # 34 is trying to buy a car but the showroom is empty. A new buyer # 35 has appeared Buyer # 35 is trying to buy a car but the showroom is empty. A new seller # 34 just appeared with black car with registration 61-C-8774 worth €10371 to sell. Seller # 34 sold black car with registration 61-C-8774 worth €10371 This is sale number 34 A new seller # 35 just appeared with black car with registration 61-C-8774 worth €10371 to sell. Seller # 35 sold black car with registration 61-C-8774 worth €10371 This is sale number 35 Buyer # 35 bought black car with registration 61-C-8774 worth €10371 This is purchase number 34 Buyer # 35 bought black car with registration 61-C-8774 worth €10371 This is purchase number 35

Day 19 There are 0 cars in the show room today.

A new seller # 36 just appeared with blue car with registration 94-CW-4050 worth €17974 to sell. Seller # 36 sold blue car with registration 94-CW-4050 worth €17974 This is sale number 36 A new buyer # 36 has appeared Buyer # 36 bought blue car with registration 94-CW-4050 worth €17974 This is purchase number 36 A new seller # 37 just appeared with blue car with registration 94-CW-4050 worth €17974 to sell. Seller # 37 sold blue car with registration 94-CW-4050 worth €17974 This is sale number 37 A new seller # 38 just appeared with blue car with registration 94-CW-4050 worth €17974 to sell. Seller # 38 sold blue car with registration 94-CW-4050 worth €17974 This is sale number 38

Day 20 There are 2 cars in the show room today.

A new seller # 39 just appeared with black car with registration 97-DL-8187 worth €14071 to sell. Seller # 39 sold black car with registration 97-DL-8187 worth €14071 This is sale number 39 A new buyer # 37 has appeared Buyer # 37 bought blue car with registration 94-CW-4050 worth €17974 This is purchase number 37 A new buyer # 38 has appeared Buyer # 38 bought blue car with registration 94-CW-4050 worth €17974 This is purchase number 38 A new seller # 40 just appeared with black car with registration 97-DL-8187 worth €14071 to sell. Seller # 40 sold black car with registration 97-DL-8187 worth €14071 This is sale number 40 A new seller # 41 just appeared with black car with registration 97-DL-8187 worth €14071 to sell. Seller # 41 sold black car with registration 97-DL-8187 worth €14071 This is sale number 41

Day 21 There are 3 cars in the show room today.

A new seller # 42 just appeared with green car with registration 72-WX-7080 worth €2507 to sell. Seller # 42 sold green car with registration 72-WX-7080 worth €2507 This is sale number 42 A new buyer # 39 has appeared Buyer # 39 bought black car with registration 97-DL-8187 worth €14071 This is purchase number 39 A new buyer # 40 has appeared Buyer # 40 bought black car with registration 97-DL-8187 worth €14071 This is purchase number 40 A new seller # 43 just appeared with green car with registration 72-WX-7080 worth €2507 to sell. Seller # 43 sold green car with registration 72-WX-7080 worth €2507 This is sale number 43 A new seller # 44 just appeared with green car with registration 72-WX-7080 worth €2507 to sell. Seller # 44 sold green car with registration 72-WX-7080 worth €2507 This is sale number 44

Day 22 There are 4 cars in the show room today.

A new seller # 45 just appeared with black car with registration 43-T-9191 worth €2317 to sell. Seller # 45 sold black car with registration 43-T-9191 worth €2317 This is sale number 45 A new buyer # 41 has appeared Buyer # 41 bought black car with registration 97-DL-8187 worth €14071 This is purchase number 41 A new buyer # 42 has appeared Buyer # 42 bought green car with registration 72-WX-7080 worth €2507 This is purchase number 42 A new buyer # 43 has appeared Buyer # 43 bought green car with registration 72-WX-7080 worth €2507 This is purchase number 43 A new seller # 46 just appeared with black car with registration 43-T-9191 worth €2317 to sell. Seller # 46 sold black car with registration 43-T-9191 worth €2317 This is sale number 46 A new seller # 47 just appeared with black car with registration 43-T-9191 worth €2317 to sell. Seller # 47 sold black car with registration 43-T-9191 worth €2317 This is sale number 47

Day 23 There are 4 cars in the show room today.

A new seller # 48 just appeared with black car with registration 92-KY-5722 worth €15709 to sell. Seller # 48 sold black car with registration 92-KY-5722 worth €15709 This is sale number 48 A new buyer # 44 has appeared Buyer # 44 bought green car with registration 72-WX-7080 worth €2507 This is purchase number 44 A new buyer # 45 has appeared Buyer # 45 bought black car with registration 43-T-9191 worth €2317 This is purchase number 45 A new buyer # 46 has appeared Buyer # 46 bought black car with registration 43-T-9191 worth €2317 This is purchase number 46 A new seller # 49 just appeared with black car with registration 92-KY-5722 worth €15709 to sell. Seller # 49 sold black car with registration 92-KY-5722 worth €15709 This is sale number 49

Day 24 There are 3 cars in the show room today.

A new seller # 50 just appeared with silver car with registration 49-T-5853 worth €4769 to sell. Seller # 50 sold silver car with registration 49-T-5853 worth €4769 This is sale number 50 A new buyer # 47 has appeared Buyer # 47 bought black car with registration 43-T-9191 worth €2317 This is purchase number 47 A new buyer # 48 has appeared Buyer # 48 bought black car with registration 92-KY-5722 worth €15709 This is purchase number 48 A new seller # 51 just appeared with silver car with registration 49-T-5853 worth €4769 to sell. Seller # 51 sold silver car with registration 49-T-5853 worth €4769 This is sale number 51 A new seller # 52 just appeared with silver car with registration 49-T-5853 worth €4769 to sell. Seller # 52 sold silver car with registration 49-T-5853 worth €4769 This is sale number 52

Day 25 There are 4 cars in the show room today.

A new seller # 53 just appeared with green car with registration 56-KY-4864 worth €5720 to sell. Seller # 53 sold green car with registration 56-KY-4864 worth €5720 This is sale number 53 A new buyer # 49 has appeared Buyer # 49 bought black car with registration 92-KY-5722 worth €15709 This is purchase number 49 A new buyer # 50 has appeared Buyer # 50 bought silver car with registration 49-T-5853 worth €4769 This is purchase number 50 A new buyer # 51 has appeared Buyer # 51 bought silver car with registration 49-T-5853 worth €4769 This is purchase number 51 A new seller # 54 just appeared with green car with registration 56-KY-4864 worth €5720 to sell. Seller # 54 sold green car with registration 56-KY-4864 worth €5720 This is sale number 54

Day 26 There are 3 cars in the show room today.

A new seller # 55 just appeared with red car with registration 11-C-7501 worth €9980 to sell. Seller # 55 sold red car with registration 11-C-7501 worth €9980 This is sale number 55 A new buyer # 52 has appeared Buyer # 52 bought silver car with registration 49-T-5853 worth €4769 This is purchase number 52 A new buyer # 53 has appeared Buyer # 53 bought green car with registration 56-KY-4864 worth €5720 This is purchase number 53 A new seller # 56 just appeared with red car with registration 11-C-7501 worth €9980 to sell. Seller # 56 sold red car with registration 11-C-7501 worth €9980 This is sale number 56 A new seller # 57 just appeared with red car with registration 11-C-7501 worth €9980 to sell. Seller # 57 sold red car with registration 11-C-7501 worth €9980 This is sale number 57

Day 27 There are 4 cars in the show room today.

A new seller # 58 just appeared with blue car with registration 75-WH-5889 worth €12907 to sell. Seller # 58 sold blue car with registration 75-WH-5889 worth €12907 This is sale number 58 A new buyer # 54 has appeared Buyer # 54 bought green car with registration 56-KY-4864 worth €5720 This is purchase number 54 A new seller # 59 just appeared with blue car with registration 75-WH-5889 worth €12907 to sell. Seller # 59 sold blue car with registration 75-WH-5889 worth €12907 This is sale number 59 A new seller # 60 just appeared with blue car with registration 75-WH-5889 worth €12907 to sell. Seller # 60 sold blue car with registration 75-WH-5889 worth €12907 This is sale number 60

Day 28 There are 6 cars in the show room today.

A new seller # 61 just appeared with blue car with registration 36-LD-7452 worth €17871 to sell. Seller # 61 sold blue car with registration 36-LD-7452 worth €17871 This is sale number 61 A new buyer # 55 has appeared Buyer # 55 bought red car with registration 11-C-7501 worth €9980 This is purchase number 55 A new buyer # 56 has appeared Buyer # 56 bought red car with registration 11-C-7501 worth €9980 This is purchase number 56 A new buyer # 57 has appeared Buyer # 57 bought red car with registration 11-C-7501 worth €9980 This is purchase number 57 A new seller # 62 just appeared with blue car with registration 36-LD-7452 worth €17871 to sell. Seller # 62 sold blue car with registration 36-LD-7452 worth €17871 This is sale number 62 A new seller # 63 just appeared with blue car with registration 36-LD-7452 worth €17871 to sell. Seller # 63 sold blue car with registration 36-LD-7452 worth €17871 This is sale number 63

Day 29 There are 6 cars in the show room today.

A new seller # 64 just appeared with green car with registration 81-L-1413 worth €11149 to sell. Seller # 64 sold green car with registration 81-L-1413 worth €11149 This is sale number 64 A new buyer # 58 has appeared Buyer # 58 bought blue car with registration 75-WH-5889 worth €12907 This is purchase number 58 A new seller # 65 just appeared with green car with registration 81-L-1413 worth €11149 to sell. Seller # 65 sold green car with registration 81-L-1413 worth €11149 This is sale number 65

Day 30 There are 7 cars in the show room today.

A new seller # 66 just appeared with black car with registration 50-LH-997 worth €13133 to sell. Seller # 66 sold black car with registration 50-LH-997 worth €13133 This is sale number 66 A new buyer # 59 has appeared Buyer # 59 bought blue car with registration 75-WH-5889 worth €12907 This is purchase number 59 A new buyer # 60 has appeared Buyer # 60 bought blue car with registration 75-WH-5889 worth €12907 This is purchase number 60 A new seller # 67 just appeared with black car with registration 50-LH-997 worth €13133 to sell. Seller # 67 sold black car with registration 50-LH-997 worth €13133 This is sale number 67 A new seller # 68 just appeared with black car with registration 50-LH-997 worth €13133 to sell. Seller # 68 sold black car with registration 50-LH-997 worth €13133 This is sale number 68

This is the desired output:

Day 1 beginning. There are 0 cars in the showroom today. A new buyer #1 just appeared. Buyer #1 wants to buy a car, but the showroom is empty. A new seller #1 just appeared with a yellow car with registration 11-G-7212 worth €3944 to sell. A new seller #3 just appeared with a black car with registration 18-G-2743 worth €14040 to sell. Seller #1 sold their yellow car with registration 11-G-7212 worth €3944 to the showroom. This is sale number 1. A new seller #2 just appeared with a silver car with registration 18-G-2469 worth €1449 to sell. Buyer #1 bought a yellow car with registration 11-G-7212 worth €3944 from the showroom. This is purchase number 1. Seller #3 sold their black car with registration 18-G-2743 worth €14040 to the showroom. This is sale number 2. Seller #2 sold their silver car with registration 18-G-2469 worth €1449 to the showroom. This is sale number 3. Day 2 beginning. There are 2 cars in the showroom today. A new seller #4 just appeared with a black car with registration 18-G-5011 worth €10859 to sell.