All pastes #233358 Raw Edit

Unnamed

public java v1 · immutable
·published 2006-11-01 22:12 UTC
rendered paste body
    public double calculateDeliveryCost(){                //instance varibles        double deliveryCost = 0;        double aleCost=0;        Ale ale;        Iterator itr = products.iterator();        ArrayList ales = new ArrayList();        Product product;                //go through order and check is product is an ale        while (itr.hasNext()) {            product = (Product) itr.next();            //if product is an ale add to ales list            if(product.getClass().toString().equals("class Ale")){                ales.add(product);                //test ales size to ensure ale added or cake not added                System.out.println(ales.size());            }        }        //this is where the problem is        //if ale list is empty calculate cost as normal by adding 2 pound to each item        if(ales.isEmpty()){            while (itr.hasNext()) {                product = (Product) itr.next();                deliveryCost += product.getPrice() + 2;            }        }         //else is ales is not empty gp thourgh the ales list and calculate the total cost for ales        else{            Iterator itr2 = ales.iterator();            while(itr2.hasNext()){                ale = (Ale) itr2.next();                aleCost += ale.getPrice();            //if the cost is = or > than 50 then delivery = 0            if(aleCost >= 50){                deliveryCost = 0.00;            }        }        }        return(deliveryCost);    }