// Jeff Marinko (jeff@vhub.com) // Example Solution for Wockets, Wackets, and Widgets Lab (CSC 101) import java.text.DecimalFormat; public class Wacket { // comment private int totalCount; // comment private double totalWeight; // not expected private static DecimalFormat format = new DecimalFormat("0.00"); // comment // ignore this for now public Wacket() {} // comment public Wacket(int count, double weight) { if (count >= 0 && weight >= 0) { totalCount = count; totalWeight = weight; } else { totalCount = 0; totalWeight = 0; } } // comment public int getCount() {return totalCount;} // comment public double getWeight() {return totalWeight;} // comment public double getAvgWeight() { if (totalCount > 0) return totalWeight / totalCount; else return 0; // shorthand notation, for those interested //return totalCount > 0 ? totalWeight / totalCount : 0; } // comment public String toString() { return "Wacket: " + totalCount + " male gremlins, " + format.format(totalWeight) + " weight"; } // comment public void add(double newWeight) {add(1, newWeight);} public void add(Wacket wacket) {add(wacket.getCount(), wacket.getWeight());} public void add(int addCount, double addWeight) { if (addCount > 0 && addWeight > 0) { // arguable, both should be positive totalCount += addCount; totalWeight += addWeight; } // NOTE: Does not need an else clause } }