Advertisement
Guest User

Flower Pot

a guest
Feb 19th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Flowers
  3. {
  4. static Scanner sc= new Scanner (System.in);
  5. String color;
  6. int height;
  7. int count=0;
  8. String address;
  9. static Perah[]Adanit= new Perah[10];
  10.  
  11. public Flowers(String address){
  12. for (int i = 0; i < 10; i++) {
  13. System.out.println("Choose the height of the flower");
  14. this.height= sc.nextInt();
  15. System.out.println("What is the flower color?");
  16. sc.nextLine();
  17. this.color= sc.nextLine();
  18. Flowers.Adanit[i]=new Perah(color,height);
  19.  
  20. }
  21. }
  22. /**
  23. * watering all the flowers
  24. * the boolean change to true while one of the flowers is dead
  25. */
  26. public void allFlowers(){
  27. for (int i = 0; i < Adanit.length; i++) {
  28. boolean dead=Adanit[i].watering();
  29. if(dead){
  30. count =count+1;
  31. }
  32. }
  33. if (count<6){
  34. count=0;
  35. }
  36. }
  37. /**
  38. *
  39. * @return, the action returns the number of the dying flowers.
  40. */
  41. public boolean mostAreDead(){
  42. if(count>=6){
  43. return true;
  44. }
  45. else{
  46. return false;
  47. }
  48. }
  49. public String getColor(){
  50. return color;
  51. }
  52. public static void main(String[] args) {
  53.  
  54. System.out.println("Where do you want to place your planter?");
  55. String address= sc.nextLine();
  56. Flowers Flowers= new Flowers(address);
  57. int count=0;
  58. while(count<6){
  59. Flowers.allFlowers();
  60. boolean mostDead=Flowers.mostAreDead();
  61. if(mostDead){
  62. System.out.println("most of the flowers in "+Flowers.address+" are dead. You should buy new flowers");
  63. System.out.println("There are"+ Flowers.Adanit.length + "flowers in the planter");
  64. System.out.print("The flowers colors are: ");
  65. for (int j=0;j<Adanit.length;j++){
  66. System.out.println(Flowers.Adanit[j].getColor());
  67. }
  68. break;
  69. }
  70. }
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement