Advertisement
Guest User

Untitled

a guest
Oct 4th, 2015
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.41 KB | None | 0 0
  1. package Birds;
  2.  
  3. public class Birds {
  4.  
  5. static String[][] store = new String[100][3];
  6. static String[][] sales = new String[1000][4];
  7.  
  8. static int storeLength = 0;
  9. static int salesLength = 0;
  10.  
  11.  
  12. public static void main(String[] args) {
  13.  
  14. initializer();
  15.  
  16. System.out.println("Report1: Printing store (less then 3):");
  17. printStore(3);
  18. System.out.println();
  19.  
  20. System.out.println("Report2: How many birds was saled:");
  21. System.out.println(totalBirdSaled());
  22. System.out.println();
  23.  
  24. System.out.println("Report3: How many Eagles in the store:");
  25. System.out.println(birdAmount("Eagle"));
  26. System.out.println();
  27.  
  28. System.out.println("Report4: Total income:");
  29. System.out.println(totalIncome() + "$");
  30. System.out.println();
  31.  
  32. System.out.println("Report5: month №6 sales:");
  33. System.out.println(monthIncome(6));
  34. System.out.println();
  35.  
  36. }
  37.  
  38. static void addToStore(String birdName, int amount){
  39. int i = getBirdId(birdName);
  40. if (i>=0){
  41. //add amount (only change)
  42. store[i][2]=String.valueOf(Integer.valueOf(store[i][2])+amount);
  43. } else {
  44. //add row
  45. store[storeLength][0]=birdName;
  46. store[storeLength][1]="0";
  47. store[storeLength][2]=String.valueOf(amount);
  48. storeLength++;
  49. }
  50.  
  51. }
  52.  
  53. static int getBirdId(String birdName){
  54. for (int i = 0; i<storeLength;i++){
  55. if (store[i][0].equals(birdName)) {
  56. return i;
  57. }
  58. }
  59.  
  60. return -1;
  61. }
  62.  
  63.  
  64. static void changePrice(String birdName, int newPrice){
  65. int i = getBirdId(birdName);
  66. if (i>=0) {
  67. store[i][1] = String.valueOf(newPrice);
  68. }
  69.  
  70. }
  71.  
  72.  
  73. static void initializer(){
  74. System.out.println("Initial data for store:");
  75. addToStore("Duck",5); changePrice("Duck",30);
  76. addToStore("Eagle",3); changePrice("Eagle",40);
  77. addToStore("Parrot",8); changePrice("Parrot",20);
  78. addToStore("Chiken",2); changePrice("Chiken",10);
  79. addToStore("Pinguine",6); changePrice("Pinguine",50);
  80. addToStore("Parrot",2);
  81. addToStore("Chiken",8);
  82. printStore(0);
  83. System.out.println();
  84. System.out.println("Change price for Duck (set 25):");
  85. changePrice("Duck",25);
  86. printStore(0);
  87.  
  88. System.out.println();
  89. System.out.println("Initial data for sales:");
  90. System.out.println(makeSale("Duck",2,20150604));
  91. System.out.println(makeSale("Duck",3,20150605));
  92. System.out.println(makeSale("Duck",1,20150606));
  93. System.out.println(makeSale("Pinguine",1,20150707));
  94. System.out.println(makeSale("dfgerkguerg",10,20150808));
  95.  
  96. System.out.println();
  97. System.out.println("Printing all store:");
  98. printStore(0);
  99. System.out.println();
  100. System.out.println("Printing all sales:");
  101. printSales();
  102. System.out.println();
  103.  
  104. }
  105.  
  106.  
  107. static void printStore(int lessThen) {
  108. for (int i = 0; i < storeLength; i++) {
  109. if (lessThen == 0 || Integer.valueOf(store[i][2]) < lessThen) {
  110. System.out.println(store[i][0] + " " + store[i][1] + " " + store[i][2]);
  111. }
  112. }
  113. }
  114.  
  115. static void printSales(){
  116. for (int i = 0; i < salesLength;i++){
  117. System.out.println(sales[i][0] + " "+ sales[i][1] + " " + sales[i][2] + " " + sales[i][3]);
  118. }
  119. }
  120.  
  121. static String makeSale(String birdName, int amount, int date){
  122. int i = getBirdId(birdName);
  123. if (i>=0) {
  124. if (Integer.valueOf(store[i][2])>=amount){
  125. store[i][2]=String.valueOf(Integer.valueOf(store[i][2])-amount);
  126.  
  127. sales[salesLength][0] = String.valueOf(date);
  128. sales[salesLength][1] = birdName;
  129. sales[salesLength][2] = String.valueOf(amount);
  130. sales[salesLength][3] = String.valueOf(Integer.valueOf(store[i][1])*amount);
  131. salesLength++;
  132.  
  133. return amount + " " + birdName + " was saled successfuly." ;
  134. } else {
  135. return "Not anought " + birdName + "s in the store. Sale cancelled!";
  136. }
  137. }
  138. return "Unknown bird name: " + birdName + ".";
  139.  
  140. }
  141.  
  142. static int totalBirdSaled(){
  143. int sum = 0;
  144. for (int i = 0; i < salesLength;i++){
  145. sum += Integer.valueOf(sales[i][2]);
  146. }
  147. return sum;
  148. }
  149.  
  150. static int birdAmount(String birdName){
  151. int i = getBirdId(birdName);
  152. if (i>=0) {
  153. return Integer.valueOf(store[i][2]);
  154. }
  155.  
  156. return 0;
  157. }
  158.  
  159. static int totalIncome(){
  160. int sum = 0;
  161. for (int i = 0; i < salesLength;i++){
  162. sum += Integer.valueOf(sales[i][3]);
  163. }
  164. return sum;
  165. }
  166.  
  167. static long monthIncome(int month){
  168. long income = 0;
  169.  
  170. for (int i = 0; i<salesLength; i++){
  171. long temp = Integer.valueOf(sales[i][0])/100;
  172. if (temp%100 == month){
  173. income += Integer.valueOf(sales[i][3]);
  174. }
  175. }
  176.  
  177. return income;
  178. }
  179.  
  180.  
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement