Advertisement
nadejdachitakova

FishinheritedByAnimal

Feb 17th, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.59 KB | None | 0 0
  1. package uni.fmi.bachelors;
  2.  
  3. import java.util.Random;
  4.  
  5. public class Fish extends Animal{
  6.  
  7.     private boolean givesBirth;
  8.    
  9.     public Fish(String type, boolean givesBirth) {
  10.         super(type);   
  11.         this.givesBirth = givesBirth;
  12.     }
  13.  
  14.     @Override
  15.     public void moveTo(String to) {    
  16.         System.out.println("Swimmed to " + to);
  17.        
  18.         Random random = new Random();
  19.        
  20.         if(random.nextInt(10) > 3) {
  21.             System.out.println("Saw a hook and ate it!");
  22.             System.out.println("Now is in the frying pan!");
  23.         }
  24.        
  25.     }
  26.  
  27.     @Override
  28.     public void eat() {    
  29.         System.out.println("Eats worms and stuff");
  30.     }
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement