Advertisement
HarrJ

Day 17 sample

Jul 11th, 2023 (edited)
1,419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.01 KB | None | 0 0
  1. package week3training;
  2.  
  3. public class Day17B {
  4.     public static void main(String[] args) {
  5.         Pig callPig = new Pig();
  6.         System.out.println("What can a pig do?");
  7.         callPig.makeSounds();
  8.         callPig.movement();
  9.         callPig.eat();
  10.     }
  11. }
  12.  
  13. class Animal {
  14.    
  15.     public void makeSounds() {
  16.         System.out.println("Most animals make sounds");
  17.     }
  18.    
  19.     public void movement() {
  20.         System.out.println("It walks on all fours");
  21.     }
  22.    
  23.     public void eat() {
  24.         System.out.println("Its an omnivore");
  25.     }
  26. }
  27.  
  28. class Pig extends Animal {
  29.     @Override
  30.     public void makeSounds() {
  31.         System.out.println("A pig goes oink oink");
  32.     }
  33. }
  34. //---------------------------------------------------------------------------
  35. package week3training;
  36.  
  37. public class Day17C {
  38.     public static void main(String[] args) {
  39.         PlantProduce callPlant = new PlantProduce("green","normal");
  40.         callPlant.foodColor();
  41.         callPlant.foodTaste();
  42.        
  43.         Ampalaya callAmpalaya = new Ampalaya();
  44.         callAmpalaya.foodColor();
  45.         callAmpalaya.foodTaste();
  46.        
  47.         Kiwi callKiwi = new Kiwi();
  48.         callKiwi.foodColor();
  49.         callKiwi.foodTaste();
  50.     }
  51. }
  52.  
  53. class PlantProduce {
  54.     String produceName = "food";
  55.     String color;
  56.     String taste;
  57.  
  58.     public PlantProduce(String color, String taste) {
  59.         this.color = color;
  60.         this.taste = taste;
  61.     }
  62.    
  63.     public void foodColor() {
  64.         System.out.println(String.format("The %s have a color of %s",produceName, color));
  65.     }
  66.    
  67.     public void foodTaste() {
  68.         System.out.println(String.format("The %s taste %s",produceName, taste));
  69.     }
  70.    
  71. }
  72.  
  73. class Ampalaya extends PlantProduce {
  74.     public Ampalaya() {
  75.         super("green", "bitter");
  76.         this.produceName = "Bitter melon";
  77.     }
  78. }
  79.  
  80. class Kiwi extends PlantProduce {
  81.     public Kiwi() {
  82.         super("brown", "salty");
  83.         this.produceName = "Kiwi";
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement