-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItem.java
More file actions
41 lines (32 loc) · 1.04 KB
/
Copy pathItem.java
File metadata and controls
41 lines (32 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.example.cleancoder.liftupconditionals;
public class Item {
public String name;
public int sellIn;
public int quality;
protected Item(String name, int sellIn, int quality) {
this.name = name;
this.sellIn = sellIn;
this.quality = quality;
}
public static Item of(String name, int sellIn, int quality) {
return switch (name) {
case "Sulfuras, Hand of Ragnaros" -> new Sulfuras(sellIn, quality);
case "Backstage passes to a TAFKAL80ETC concert" -> new Backsage(sellIn, quality);
case "Aged Brie" -> new AgedBrie(sellIn, quality);
default -> new Item(name, sellIn, quality);
};
}
protected void updateQuality() {
if (quality > 0) {
quality = quality - 1;
}
sellIn = sellIn - 1;
if (sellIn < 0 && quality > 0) {
quality = quality - 1;
}
}
@Override
public String toString() {
return this.name + ", " + this.sellIn + ", " + this.quality;
}
}