Advertisement
Guest User

Fruit.java

a guest
Dec 14th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.64 KB | None | 0 0
  1. package me;
  2.  
  3. import java.util.Random;
  4.  
  5. /**
  6.  * This class represents a piece of fruit, it can be eaten
  7.  */
  8. public abstract class Fruit {
  9.  
  10.     /**
  11.      * This function eats the fruit... no more fruit.
  12.      * @return whether it was eaten successfully.
  13.      */
  14.     abstract boolean eat();
  15.  
  16.     /**
  17.      * This function throws out the fruit as it's mouldy.
  18.      * @return
  19.      */
  20.     abstract boolean throwOut();
  21.  
  22.     /**
  23.      * Pre-programmed, hard coded logic to determine if a fruit is mouldy.
  24.      * @return true if mouldy, false otherwise.
  25.      */
  26.     public boolean isMouldy() {
  27.         return new Random().nextBoolean();
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement