Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.88 KB | None | 0 0
  1. public class Plants {
  2. public static void main(String[] args) {
  3.  
  4. Grass red = new Grass ("Red Grass", 50, 25,true);
  5. String grass = red.toString();
  6. System.out.println(grass);
  7. Flower daisy = new Flower("Daisy", "Green",25.4, 2,63,false);
  8. String daIsy = daisy.toString();
  9. System.out.println(daIsy);
  10. Tree big = new Tree("Big", 54.4,555,false,false);
  11. String tre = big.toString();
  12. System.out.println(tre);
  13. Oak bigBoy = new Oak ("Daddy Oak", 60.64,444,true,true,43533333);
  14. String biggy = bigBoy.toString();
  15. System.out.println(biggy);
  16. Daisy daisy1 = new Daisy("Tetraneuris acaulis","white", 40,3,60,true, "Europe"," Angelita daisy");
  17. String dais = daisy1.toString();
  18. System.out.println(dais);
  19. }
  20. }
  21.  
  22. class Plant
  23. {
  24. private String name;
  25. private boolean photosynthesis;
  26. private double height /*sm*/;
  27.  
  28.  
  29. public Plant(String name, double height, boolean photosynthesis){
  30.  
  31. this.name=name;
  32. this.height=height;
  33. this.photosynthesis=photosynthesis;
  34. }
  35. public String getName() { return name; }
  36. public double getHeight() {
  37. return height;
  38. }
  39.  
  40. public boolean isPhotosynthesis() {
  41. return photosynthesis;
  42. }
  43. }
  44. class Grass extends Plant
  45. {
  46. private int grassArea ;
  47. public Grass (String name, int grassArea, double height, boolean photosynthesis)
  48. {
  49. super(name, height, photosynthesis);
  50. this.grassArea=grassArea;
  51.  
  52. }
  53.  
  54. public int getGrassArea() {
  55. return grassArea;
  56. }
  57. @Override
  58. public String toString()
  59. {return String.format("This is local grace named %s,it takes %d area , and has %.2f sm height and what about photosynthesis it is %s",getName() ,getGrassArea(),getHeight(),isPhotosynthesis());
  60.  
  61. }
  62. }
  63. class Flower extends Plant
  64. {
  65.  
  66.  
  67. private int numberOfBud;
  68. private int timeOfBloom /*days*/;
  69. private String colour;
  70. public Flower (String name, String colour,double height,int numberOfBud, int timeOfBloom, boolean photosynthesis)
  71. {
  72. super(name, height, photosynthesis);
  73. this.colour=colour;
  74. this.numberOfBud=numberOfBud;
  75. this.timeOfBloom=timeOfBloom;
  76.  
  77. }
  78.  
  79. public String getColour() {
  80. return colour;
  81. }
  82.  
  83. public int getNumberOfBud() {
  84. return numberOfBud;
  85. }
  86.  
  87. public int getTimeOfBloom() {
  88. return timeOfBloom;
  89. }
  90. @Override
  91. public String toString()
  92. {return String.format("This flower's name is %s, and it has %s color,it also has %d buds and this flower bloom time is %d days ," +
  93. " it %.2f sm height and what about photosynthesis it is %s",getName() ,getColour(),getNumberOfBud(),getTimeOfBloom(),getHeight(),isPhotosynthesis());
  94.  
  95. }
  96.  
  97. }
  98. class Daisy extends Flower
  99. { private String habitat;
  100. private String subspecies;
  101.  
  102. public String getHabitat() {
  103. return habitat;
  104. }
  105.  
  106. public String getSubspecies() {
  107. return subspecies;
  108. }
  109.  
  110. public Daisy(String name, String colour, double height, int numberOfBud, int timeOfBloom, boolean photosynthesis,String habitat, String subspecies) {
  111. super(name, colour, height, numberOfBud, timeOfBloom, photosynthesis);
  112. this.habitat=habitat;
  113. this.subspecies=subspecies;
  114. }
  115. @Override
  116. public String toString()
  117. {
  118. return String.format("This is the %s from the %s subspecies , this instance grows in the %s , its characteristic is %s color and %d number of buds , " +
  119. "this flower is %.2f sm height, its time of bloom is %d days, and what about photosynthesis it is %s ",getName(),getSubspecies(),getHabitat(),getColour(),getNumberOfBud(),getHeight(),getTimeOfBloom(),isPhotosynthesis());
  120. }
  121. }
  122. class Tree extends Plant
  123. {
  124.  
  125. private int age;
  126. private boolean alive;
  127. public Tree (String name, double height,int age, boolean alive, boolean photosynthesis)
  128. {
  129. super(name, height, photosynthesis);
  130. this.age=age;
  131. this.alive=alive;
  132.  
  133. }
  134.  
  135. public int getAge() {
  136. return age;
  137. }
  138.  
  139. public boolean isAlive() {
  140.  
  141. return alive;
  142.  
  143. }
  144. @Override
  145. public String toString()
  146. {return String.format("This tree named %s, and it live %s years, it %.2f sm height and I think it's %s that this alive," +
  147. " that it's what about photosynthesis it is %s",getName() ,getAge(),getHeight(),isAlive(),isPhotosynthesis());
  148.  
  149. }
  150.  
  151. }
  152. class Oak extends Tree {
  153. private int acorns;
  154. public Oak(String name, double height, int age, boolean alive, boolean photosynthesis,int acorns) {
  155. super(name, height, age, alive, photosynthesis);
  156. this.acorns=acorns;
  157. }
  158.  
  159. public int getNumberOfAcorns() {
  160. return acorns;
  161. }
  162. @Override
  163. public String toString()
  164. {return String.format("This big tree is %s, and it live %s years, it has about of %.2f sm height and this has a lot of acorns ," +
  165. " at least %d, i think. What about photosynthesis it is %s",getName() ,getAge(),getHeight(),getNumberOfAcorns(),isPhotosynthesis());
  166.  
  167. }
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement