Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Plant {
- protected String type;
- protected boolean sunLovely;
- protected String bloomingSeason;
- public Plant(){
- }
- public Plant(String type, boolean sunLovely, String bloomingSeason){
- this.type = type;
- this.sunLovely = sunLovely;
- this.bloomingSeason = bloomingSeason;
- }
- public void bloom(String season){
- if (this.bloomingSeason.equals(season)) {
- System.out.println("The plant is blooming!");
- }
- else{
- System.out.println("The plant can't bloom right now ;(");
- }
- }
- @Override
- public String toString() {
- String sunStatus;
- if(sunLovely){
- sunStatus = "loves sun";
- }
- else{
- sunStatus = "prefers shadows";
- }
- return "type " + type + ", " + sunStatus + " and it's blooming season is " + bloomingSeason;
- }
- public String getType() {
- return type;
- }
- public void setType(String type) {
- this.type = type;
- }
- public boolean isSunLovely() {
- return sunLovely;
- }
- public void setSunLovely(boolean sunLovely) {
- this.sunLovely = sunLovely;
- }
- public String getBloomingSeason() {
- return bloomingSeason;
- }
- public void setBloomingSeason(String bloomingSeason) {
- this.bloomingSeason = bloomingSeason;
- }
- }
- class AppleTree extends Plant{
- private int applesOnTheTree;
- public AppleTree(){
- }
- public AppleTree(String type, boolean sunLovely, String bloomingSeason, int applesOnTheTree){
- super(type, sunLovely, bloomingSeason);
- this.applesOnTheTree = applesOnTheTree;
- }
- public void takingApples(int applesTaken){
- this.applesOnTheTree = this.applesOnTheTree - applesTaken;
- }
- @Override
- public String toString() {
- return "Your apple tree is " + super.toString() + '\n' + "It also has " + applesOnTheTree + " apples in the leaves!" + '\n';
- }
- public int getApplesOnTheTree() {
- return applesOnTheTree;
- }
- public void setApplesOnTheTree(int applesOnTheTree) {
- this.applesOnTheTree = applesOnTheTree;
- }
- }
- class Rose extends Plant{
- public Rose(){
- }
- public Rose(String type, boolean sunLovely, String bloomingSeason){
- super(type, sunLovely, bloomingSeason);
- }
- @Override
- public String toString() {
- return "Your rose is " + super.toString() + '\n';
- }
- }
- class Test{
- public static void main(String[] args) {
- Rose rose1 = new Rose("White Rose", true, "Summer");
- rose1.bloom("Summer");
- System.out.println(rose1);
- AppleTree appleTree1 = new AppleTree("Green Apples", true, "Spring and Summer", 300);
- appleTree1.bloom("Winter");
- appleTree1.takingApples(20);
- System.out.println(appleTree1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement