FileDocCategorySizeDatePackage
TrashVisitor.javaAPI DocExample5144Mon Apr 06 18:10:20 BST 1998c16.trashvisitor

PriceVisitor

public class PriceVisitor extends Object implements Visitor

Fields Summary
private double
alSum
private double
pSum
private double
gSum
private double
cSum
Constructors Summary
Methods Summary
voidtotal()

    System.out.println(
      "Total Aluminum: $" + alSum + "\n" +
      "Total Paper: $" + pSum + "\n" +
      "Total Glass: $" + gSum + "\n" +
      "Total Cardboard: $" + cSum);
  
public voidvisit(VAluminum al)

    double v = al.weight() * al.value();
    System.out.println(
      "value of Aluminum= " + v);
    alSum += v;
  
public voidvisit(VPaper p)

    double v = p.weight() * p.value();
    System.out.println(
      "value of Paper= " + v);
    pSum += v;
  
public voidvisit(VGlass g)

    double v = g.weight() * g.value();
    System.out.println(
      "value of Glass= " + v);
    gSum += v;
  
public voidvisit(VCardboard c)

    double v = c.weight() * c.value();
    System.out.println(
      "value of Cardboard = " + v);
    cSum += v;