OpenDataPhillyFinal / src / edu / upenn / cit594 / processor / AverageMarketValue.java
AverageMarketValue.java
Raw
package edu.upenn.cit594.processor;

import java.util.ArrayList;

import edu.upenn.cit594.util.Property;

public class AverageMarketValue implements AverageValue {
	
    @Override
	public Integer calculateAverage(int inputZipCode, ArrayList<Property> propertyData) {
    	
        double sumTotalMarketValue = 0;
        int countProperties = 0;
        
        for (Property property : propertyData) {
            if (property.getZipCode() == inputZipCode) {
                if (property.getMarketValue() == -1 || property.getMarketValue() == -1.0) {
                	continue;
                }
            	sumTotalMarketValue += property.getMarketValue();
                countProperties++;
            }
        }
        
        if (countProperties == 0) {
            return 0;
        }
        
        //truncate and get average marketValue
        return (int) (sumTotalMarketValue /  countProperties);
    }



}