Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Plants {
- public static void main(String[] args) {
- Grass red = new Grass ("Red Grass", 50, 25,true);
- String grass = red.toString();
- System.out.println(grass);
- Flower daisy = new Flower("Daisy", "Green",25.4, 2,63,false);
- String daIsy = daisy.toString();
- System.out.println(daIsy);
- Tree big = new Tree("Big", 54.4,555,false,false);
- String tre = big.toString();
- System.out.println(tre);
- Oak bigBoy = new Oak ("Daddy Oak", 60.64,444,true,true,43533333);
- String biggy = bigBoy.toString();
- System.out.println(biggy);
- Daisy daisy1 = new Daisy("Tetraneuris acaulis","white", 40,3,60,true, "Europe"," Angelita daisy");
- String dais = daisy1.toString();
- System.out.println(dais);
- }
- }
- class Plant
- {
- private String name;
- private boolean photosynthesis;
- private double height /*sm*/;
- public Plant(String name, double height, boolean photosynthesis){
- this.name=name;
- this.height=height;
- this.photosynthesis=photosynthesis;
- }
- public String getName() { return name; }
- public double getHeight() {
- return height;
- }
- public boolean isPhotosynthesis() {
- return photosynthesis;
- }
- }
- class Grass extends Plant
- {
- private int grassArea ;
- public Grass (String name, int grassArea, double height, boolean photosynthesis)
- {
- super(name, height, photosynthesis);
- this.grassArea=grassArea;
- }
- public int getGrassArea() {
- return grassArea;
- }
- @Override
- public String toString()
- {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());
- }
- }
- class Flower extends Plant
- {
- private int numberOfBud;
- private int timeOfBloom /*days*/;
- private String colour;
- public Flower (String name, String colour,double height,int numberOfBud, int timeOfBloom, boolean photosynthesis)
- {
- super(name, height, photosynthesis);
- this.colour=colour;
- this.numberOfBud=numberOfBud;
- this.timeOfBloom=timeOfBloom;
- }
- public String getColour() {
- return colour;
- }
- public int getNumberOfBud() {
- return numberOfBud;
- }
- public int getTimeOfBloom() {
- return timeOfBloom;
- }
- @Override
- public String toString()
- {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 ," +
- " it %.2f sm height and what about photosynthesis it is %s",getName() ,getColour(),getNumberOfBud(),getTimeOfBloom(),getHeight(),isPhotosynthesis());
- }
- }
- class Daisy extends Flower
- { private String habitat;
- private String subspecies;
- public String getHabitat() {
- return habitat;
- }
- public String getSubspecies() {
- return subspecies;
- }
- public Daisy(String name, String colour, double height, int numberOfBud, int timeOfBloom, boolean photosynthesis,String habitat, String subspecies) {
- super(name, colour, height, numberOfBud, timeOfBloom, photosynthesis);
- this.habitat=habitat;
- this.subspecies=subspecies;
- }
- @Override
- public String toString()
- {
- 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 , " +
- "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());
- }
- }
- class Tree extends Plant
- {
- private int age;
- private boolean alive;
- public Tree (String name, double height,int age, boolean alive, boolean photosynthesis)
- {
- super(name, height, photosynthesis);
- this.age=age;
- this.alive=alive;
- }
- public int getAge() {
- return age;
- }
- public boolean isAlive() {
- return alive;
- }
- @Override
- public String toString()
- {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," +
- " that it's what about photosynthesis it is %s",getName() ,getAge(),getHeight(),isAlive(),isPhotosynthesis());
- }
- }
- class Oak extends Tree {
- private int acorns;
- public Oak(String name, double height, int age, boolean alive, boolean photosynthesis,int acorns) {
- super(name, height, age, alive, photosynthesis);
- this.acorns=acorns;
- }
- public int getNumberOfAcorns() {
- return acorns;
- }
- @Override
- public String toString()
- {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 ," +
- " at least %d, i think. What about photosynthesis it is %s",getName() ,getAge(),getHeight(),getNumberOfAcorns(),isPhotosynthesis());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement