Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. package com.gildedrose;
  2.  
  3. class GildedRose{
  4. Item[] items;
  5.  
  6. private static final String AGED_BRIE = "Aged Brie";
  7. private static final String SULFURAS_HAND_RAGNAROS = "Sulfuras, Hand of Ragnaros";
  8. private static final String BACKSTAGE_PASS_CONCERT = "Backstage passes to a TAFKAL80ETC concert";
  9.  
  10. private static final int LOWEST_QUALITY_VALUE_POSSIBLE = 0;
  11. private static final int HIGHEST_QUALITY_VALUE_POSSIBLE = 50;
  12.  
  13. public GildedRose(Item[] items){
  14. this.items = items;
  15. }
  16.  
  17. /*
  18. Méthode qui renvoi un boolean répresentant
  19. le test de la qualité par rapport à la valeur maximale de la Qualité
  20. */
  21. private boolean isQualityValueUnderHighest(Item item){
  22. return item.quality < HIGHEST_QUALITY_VALUE_POSSIBLE;
  23. }
  24.  
  25. /*
  26. Incrémenter de 1 la valeur de qualité d'un objet
  27. */
  28. private IncrementByOneItemQualityValue(Item item){
  29. return item.quality + 1;
  30. }
  31.  
  32. /*
  33. Décrementer de 1 la valeur de qualité d'un objet
  34. */
  35. private DecrementByOneItemQualityValue(Item item){
  36. return item.quality - 1;
  37. }
  38.  
  39. public void updateQuality() {
  40.  
  41. /*
  42. Modification de la boucle for
  43. Au lieu d'utiliser les étapes d'initialisation, de test et d'incrementation
  44. Nous itérons sur chaque élement
  45.  
  46. */
  47.  
  48. for (Item item : items) {
  49. if (!item.name.equals(AGED_BRIE)
  50. && !item.name.equals(BACKSTAGE_PASS_CONCERT)) {
  51. if (item.quality > LOWEST_QUALITY_VALUE_POSSIBLE) {
  52. if (!item.name.equals(SULFURAS_HAND_RAGNAROS)) {
  53.  
  54. DecrementByOneItemQualityValue(item);
  55. }
  56. }
  57. } else {
  58. if (isQualityValueUnderHighest(item)) {
  59. IncrementByOneItemQualityValue(item)
  60.  
  61. if (item.name.equals(BACKSTAGE_PASS_CONCERT)) {
  62. if (item.sellIn < 11) {
  63. if (isQualityValueUnderHighest(item)) {
  64. IncrementByOneItemQualityValue(item)
  65. }
  66. }
  67.  
  68. if (item.sellIn < 6) {
  69. if (isQualityValueUnderHighest(item)) {
  70.  
  71. IncrementByOneItemQualityValue(item)
  72. }
  73. }
  74. }
  75. }
  76. }
  77.  
  78. if (!item.name.equals(SULFURAS_HAND_RAGNAROS)) {
  79. item.sellIn = item.sellIn - 1;
  80. }
  81.  
  82. if (item.sellIn < LOWEST_QUALITY_VALUE_POSSIBLE) {
  83. if (!item.name.equals(AGED_BRIE)) {
  84. if (!item.name.equals(BACKSTAGE_PASS_CONCERT)) {
  85. if (item.quality > LOWEST_QUALITY_VALUE_POSSIBLE) {
  86. if (!item.name.equals(SULFURAS_HAND_RAGNAROS)) {
  87.  
  88. DecrementByOneItemQualityValue(item);
  89. }
  90. }
  91. } else {
  92. item.quality = item.quality - item.quality;
  93. }
  94. } else {
  95. if (isQualityValueUnderHighest(item)) {
  96.  
  97. IncrementByOneItemQualityValue(item)
  98. }
  99. }
  100. }
  101. }
  102. }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement