GameNCode

SuperDelicacy

Sep 4th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. /**
  2. * Created by roywe on 9/4/2017.
  3. */
  4. public class SuperDelicacy {
  5. private Delicacy[] dc;
  6. private int Delicacies;
  7. private String Supermarket;
  8.  
  9. public SuperDelicacy(String Supermarket)
  10. {
  11. this.Supermarket = Supermarket;
  12. this.dc = new Delicacy[1000];
  13. this.Delicacies = 0;
  14. }
  15.  
  16. public Delicacy[] getDc() {
  17. return dc;
  18. }
  19.  
  20. public void setDc(Delicacy[] dc) {
  21. this.dc = dc;
  22. }
  23.  
  24. public int getDelicacies() {
  25. return Delicacies;
  26. }
  27.  
  28. public void setDelicacies(int delicacies) {
  29. Delicacies = delicacies;
  30. }
  31.  
  32. public String getSupermarket() {
  33. return Supermarket;
  34. }
  35.  
  36. public void setSupermarket(String supermarket) {
  37. Supermarket = supermarket;
  38. }
  39.  
  40. public void addDc()
  41. {
  42. if(this.Delicacies < this.dc.length)
  43. {
  44. this.dc[Delicacies] = new Delicacy();
  45. this.Delicacies++;
  46. System.out.println("Added a Delicacy");
  47. System.out.println();
  48. }
  49. else
  50. {
  51. System.out.println("Failed to add Delicacy");
  52. System.out.println();
  53. }
  54. }
  55.  
  56. public void print()
  57. {
  58. System.out.println("SuperDelicacy: ");
  59. System.out.println("Supermarket: " + this.getSupermarket());
  60. System.out.println("Delicacy: " + this.getDelicacies());
  61. System.out.println();
  62. }
  63.  
  64. public void cheapestDc()
  65. {
  66. double min = this.getDc()[0].getPrice();
  67. String name = "";
  68. String company = "";
  69. for(int i = 0; 1 < this.getDc().length; i++)
  70. {
  71. if(min > this.getDc()[i].getPrice())
  72. {
  73. min = this.getDc()[i].getPrice();
  74. name = this.getDc()[i].getName();
  75. company = this.getDc()[i].getCompany();
  76. }
  77. }
  78. System.out.println("The cheapest Delicacy is: " + name + " by " + company);
  79. System.out.println();
  80. }
  81.  
  82. public boolean inStock(String name)
  83. {
  84. boolean temp = false;
  85. double price = 0;
  86. for(int i = 0; i < this.getDc().length; i++)
  87. {
  88. if(this.getDc()[i].getName().equals(name) == true)
  89. {
  90. temp = true;
  91. price = this.getDc()[i].getPrice();
  92. }
  93. }
  94. if(price == 0)
  95. {
  96. System.out.println(0);
  97. }
  98. else
  99. {
  100. System.out.println("The price is: " + price);
  101. }
  102. return temp;
  103. }
  104.  
  105. public void companyDc(String company)
  106. {
  107. String[] check = new String[this.getDc().length];
  108. int counter = 0;
  109. for(int i = 0; i < this.getDc().length; i++)
  110. {
  111. if(company.equals(this.getDc()[i].getCompany()))
  112. {
  113. boolean flag = false;
  114. for(int j = 0; j < counter; j++) {
  115. if(check[j].equals(this.getDc()[i].getName()))
  116. {
  117. flag = true;
  118. }
  119. }
  120. if(!(flag))
  121. {
  122. check[counter] = this.getDc()[i].getName();
  123. counter++;
  124. }
  125. }
  126. }
  127. System.out.println("The delicacies by " + company + " are: ");
  128. System.out.println();
  129. for(int i = 0; i < counter; i++)
  130. {
  131. System.out.print(check[i]);
  132. }
  133. }
  134. }
Add Comment
Please, Sign In to add comment