123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
-
- public class Inventory {
- private Item[] items;
-
- public Inventory(Item[] items) {
- super();
- this.items = items;
- }
-
- public void updateQuality() {
- for (int i = 0; i < items.length; i++) {
- if (items[i].getName().equals("Aged Brie")
- || items[i].getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
- //level 2 - quality
- if (items[i].getQuality() < 50) {
- increaseQualityBy1(items[i]);
- //level 3 - item type
- if (items[i].getName() == "Backstage passes to a TAFKAL80ETC concert") {
- //level 4 - sell in date
- if (items[i].getSellIn() < 11) {
- //level 5 - quality
- if (items[i].getQuality() < 50) {
- increaseQualityBy1(items[i]);
- }
- }
- //level 4 - sell in date
- if (items[i].getSellIn() < 6) {
- //level 5 - quality
- if (items[i].getQuality() < 50) {
- increaseQualityBy1(items[i]);
- }
- }
- }
- }
- //level 1 - item type
- } else {
- //level 2 - quality
- if (items[i].getQuality() > 0) {
- //level 3 - item type
- if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
- reduceQualityBy1(items[i]);
- }
- }
- }
-
- if(!items[i].getName().equals("Sulfuras, Hand of Ragnaros")){
- updateSellInDays(items[i]);
- }
- updateExpiredItems(items[i]);
- }
- }
-
- public void reduceQualityBy1(Item item){
- item.setQuality(item.getQuality() -1);
- }
-
- public void increaseQualityBy1(Item item){
- item.setQuality(item.getQuality() + 1);
- }
-
- public void setQualityTo0(Item item){
- item.setQuality(item.getQuality() - item.getQuality());
- }
-
- public void updateSellInDays(Item item){
- item.setSellIn(item.getSellIn() - 1);
- }
-
- public void updateExpiredItems(Item item){
- if (item.getSellIn() < 0) {
- //level 2 - item type
- if (item.getName().equals("Aged Brie")) {
- //level 3 - quality
- if (item.getQuality() < 50) {
- increaseQualityBy1(item);
- }
- //level 2 - item type
- } else if (item.getName().equals("Backstage passes to a TAFKAL80ETC concert")){
- setQualityTo0(item);
- //level 3 - item type
- } else {
- //level 4 - quality
- if (item.getQuality() > 0) {
- //level 5 - item type
- if (!item.getName().equals("Sulfuras, Hand of Ragnaros")) {
- reduceQualityBy1(item);
- }
- }
- }
- }
- }
- }
|