You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AppleCrate.java 997B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import java.io.Serializable;
  2. import java.io.IOException;
  3. /**
  4. * This class represents an apple crate that is used for transporting apples.
  5. * The apples are contained in an array of <CODE>Apple</CODE> objects.
  6. *
  7. * @author Mik Kersten
  8. * @version $Version$
  9. *
  10. * @see Apple
  11. */
  12. public class AppleCrate implements Serializable
  13. {
  14. Apple[] crateContents = null;
  15. /**
  16. * Default constructor.
  17. *
  18. * @param newCrateContents an array of <CODE>Apple</CODE> objects
  19. */
  20. public AppleCrate( Apple[] newCrateContents )
  21. {
  22. crateContents = newCrateContents;
  23. }
  24. /**
  25. * A crate is sellable if the apples are bruised 50% or less on average.
  26. *
  27. * @return <CODE>true</CODE> if the the apples can be sold
  28. */
  29. public boolean isSellable()
  30. {
  31. int bruising = 0;
  32. for ( int i = 0; i < crateContents.length; i++ )
  33. {
  34. bruising = bruising + crateContents[i].getBruising();
  35. }
  36. if ( (bruising/crateContents.length) > 50 )
  37. {
  38. return false;
  39. }
  40. else
  41. {
  42. return true;
  43. }
  44. }
  45. }