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.

Apple.java 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import java.io.Serializable;
  2. import java.io.IOException;
  3. /**
  4. * This class represents an apple that has the following two attributes
  5. * <UL>
  6. * <LI>a variety (i.e. "Macintosh" or "Granny Smith")
  7. * <LI>a brusing factor represnting how badly bruised the apple is
  8. * </UL>
  9. *
  10. * @author Mik Kersten
  11. * @version $Version$
  12. */
  13. public class Apple implements Serializable
  14. {
  15. private String variety = null;
  16. private int bruising = 0;
  17. /**
  18. * Default constructor.
  19. *
  20. * @param newVariety the type of variety for this apple
  21. */
  22. public Apple( String newVariety )
  23. {
  24. variety = newVariety;
  25. }
  26. /**
  27. * This inner class represents apple seeds.
  28. */
  29. public class AppleSeed {
  30. private int weight = 0;
  31. private SeedContents seedContents = null;
  32. /**
  33. * This is how you get poison from the apple.
  34. */
  35. public void getArsenic() {
  36. System.out.println( ">> getting arsenic" );
  37. }
  38. /**
  39. * Reperesents the contents of the seeds.
  40. */
  41. public class SeedContents {
  42. public String core = null;
  43. public String shell = null;
  44. }
  45. }
  46. /**
  47. * Sets the bruising factor of the apple.
  48. *
  49. * @param bruiseFactor the new bruising factor
  50. */
  51. public void bruise( int bruiseFactor )
  52. {
  53. bruising = bruising + bruiseFactor;
  54. if ( bruising > 100 ) bruising = 100;
  55. if ( bruising < 0 ) bruising = 0;
  56. }
  57. /**
  58. * Returns the bruising factor.
  59. *
  60. * @return bruising the bruising factor associated with the apple
  61. */
  62. public int getBruising()
  63. {
  64. return bruising;
  65. }
  66. /**
  67. * Serializes the apple object.
  68. *
  69. * @param oos stream that the object is written to
  70. */
  71. private void writeObject( java.io.ObjectOutputStream oos )
  72. throws IOException
  73. {
  74. // TODO: implement
  75. }
  76. /**
  77. * Reads in the apple object.
  78. *
  79. * @param ois stream that the object is read from
  80. */
  81. private void readObject( java.io.ObjectInputStream ois )
  82. throws IOException, ClassNotFoundException
  83. {
  84. // TODO: implement
  85. }
  86. }
  87. /**
  88. * Stub class to represent apple peeling.
  89. */
  90. class ApplePealer
  91. {
  92. /**
  93. * Stub for peeling the apple.
  94. */
  95. public void peelApple() {
  96. System.out.println( ">> peeling the apple..." );
  97. }
  98. }