FileDocCategorySizeDatePackage
ReceiptDTO.javaAPI DocExample884Mon Nov 24 22:05:54 GMT 2003com.oreilly.patterns.chapter9

ReceiptDTO.java

package com.oreilly.patterns.chapter9;

public class ReceiptDTO {
    private float totalPrice;
    private String[] descriptions;
    private float[] prices;
    
    public ReceiptDTO(LocalItem[] items, LocalSalesRecord record) {
        descriptions = new String[items.length];
        prices = new float[items.length];
        
        for (int i = 0; i < items.length; i++) {
            descriptions[i] = items[i].getDescription();
            prices[i] = items[i].getPrice();
        }
        
        totalPrice = record.getTotalPrice();
    }

    public float getTotalPrice() {
        return totalPrice;
    }
    
    public int getItemCount() {
        return descriptions.length;
    }
    
    public String getItemDescription(int index) {
        return descriptions[index];
    }
    
    public float getItemPrice(int index) {
        return prices[index];
    }
}