// Jeff Marinko (jeff@vhub.com)
// Example Solution for Wockets, Wackets, and Widgets Lab (CSC 101)

import java.text.DecimalFormat;

// comment
public class Widget {

	// data fields, should comment each
	private int mCount, fCount;
	private double mWeight, fWeight;
	
	// not expected
	private static DecimalFormat format = new DecimalFormat("0.00");

	// comment
	public Widget(int mCount, double mWeight, int fCount, double fWeight) {
		// check male parameters
		if (mCount > 0 && mWeight > 0) {
			this.mCount = mCount;
			this.mWeight = mWeight;
		}
		else {
			this.mCount = 0;
			this.mWeight = 0;
		}
		
		// check female parameters
		if (fCount > 0 && fWeight > 0) {
			this.fCount = fCount;
			this.fWeight = fWeight;
		}
		else {
			this.fCount = 0;
			this.fWeight = 0;
		}	
	}
	
	// comment
	public int getMaleCount() {return mCount;}
	public int getFemaleCount() {return fCount;}
	public double getMaleWeight() {return mWeight;}
	public double getFemaleWeight() {return fWeight;}
	
	// comment
	public double getAvgMaleWeight() {
		if (mCount > 0)
			return mWeight / mCount;
		else
			return 0;
		
		// shorthand notation, for those interested
		//return mCount > 0 ? mWeight / mCount : 0;
	
	}
	public double getAvgFemaleWeight() {
		if (fCount > 0)
			return fWeight / fCount;
		else
			return 0;
		
		// shorthand notation, for those interested
		//return fCount > 0 ? fWeight / fCount : 0;
	}
	
	// comment
	public String toString() {
		return "Widget: " + mCount + " male gremlins, " +
		 format.format(mWeight) + " weight, " + fCount + 
		 " female gremlins, " + format.format(fWeight) + " weight";
	}
	
	// comment
	public void add(Wacket addWacket) {
		mCount += addWacket.getCount();
		mWeight += addWacket.getWeight();
	}
	
	// comment
	public void add(Wocket addWocket) {
		fCount += addWocket.getCount();
		fWeight += addWocket.getWeight();
	}
	
	// comment
	public void add(Widget addWidget) {
		mCount += addWidget.getMaleCount();
		mWeight += addWidget.getMaleWeight();
		fCount += addWidget.getFemaleCount();
		fWeight += addWidget.getFemaleWeight();
	}
}