public class Cashier implements Visitor {
  private double totalPrice;

  //collect data about the book
  public void visit(Book book) {
    // Supporse there is a discount for the book, if the price is over $10
    if(book.getPrice() > 10.0) {
      totalPrice += book.getPrice() * 0.9;
    } else {
      totalPrice += book.getPrice;
    }
  }

  //add other visitors here
  public void visit(Fruit fruit) {
    totalPrice += fruit.getWeight() * fruit.getPrice();
  }

  //return the internal state
  public double getTotalPrice() {
    return totalPrice;
  }
}