mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 22:41:30 +00:00
修改Item且增加4支subclass
This commit is contained in:
parent
98ff07fb44
commit
56c16eaa70
20
Java/src/main/java/com/gildedrose/AgedBrieItem.java
Normal file
20
Java/src/main/java/com/gildedrose/AgedBrieItem.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package com.gildedrose;
|
||||||
|
|
||||||
|
public class AgedBrieItem extends Item {
|
||||||
|
|
||||||
|
public AgedBrieItem(String name, int sellIn, int quality) {
|
||||||
|
super(name, sellIn, quality);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update() {
|
||||||
|
this.sellIn = this.sellIn - 1;
|
||||||
|
|
||||||
|
this.increaseQuality();
|
||||||
|
|
||||||
|
if (this.sellIn < 0) {
|
||||||
|
this.increaseQuality();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
28
Java/src/main/java/com/gildedrose/BackstagePassesItem.java
Normal file
28
Java/src/main/java/com/gildedrose/BackstagePassesItem.java
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package com.gildedrose;
|
||||||
|
|
||||||
|
public class BackstagePassesItem extends Item {
|
||||||
|
|
||||||
|
public BackstagePassesItem(String name, int sellIn, int quality) {
|
||||||
|
super(name, sellIn, quality);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update() {
|
||||||
|
this.sellIn = this.sellIn - 1;
|
||||||
|
|
||||||
|
this.increaseQuality();
|
||||||
|
|
||||||
|
if (this.sellIn < 10) {
|
||||||
|
this.increaseQuality();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.sellIn < 5) {
|
||||||
|
this.increaseQuality();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.sellIn < 0) {
|
||||||
|
this.quality = this.quality - this.quality;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -2,20 +2,36 @@ package com.gildedrose;
|
|||||||
|
|
||||||
public class Item {
|
public class Item {
|
||||||
|
|
||||||
public String name;
|
public String name;
|
||||||
|
|
||||||
public int sellIn;
|
public int sellIn;
|
||||||
|
|
||||||
public int quality;
|
public int quality;
|
||||||
|
|
||||||
public Item(String name, int sellIn, int quality) {
|
public Item(String name, int sellIn, int quality) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.sellIn = sellIn;
|
this.sellIn = sellIn;
|
||||||
this.quality = quality;
|
this.quality = quality;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void update() {
|
||||||
public String toString() {
|
|
||||||
return this.name + ", " + this.sellIn + ", " + this.quality;
|
}
|
||||||
}
|
|
||||||
|
public void decreaseQuality() {
|
||||||
|
if (this.quality > 0) {
|
||||||
|
this.quality = this.quality - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void increaseQuality() {
|
||||||
|
if (this.quality < 50) {
|
||||||
|
this.quality = this.quality + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return this.name + ", " + this.sellIn + ", " + this.quality;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
19
Java/src/main/java/com/gildedrose/NormalItem.java
Normal file
19
Java/src/main/java/com/gildedrose/NormalItem.java
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
package com.gildedrose;
|
||||||
|
|
||||||
|
public class NormalItem extends Item {
|
||||||
|
|
||||||
|
public NormalItem(String name, int sellIn, int quality) {
|
||||||
|
super(name, sellIn, quality);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update() {
|
||||||
|
this.sellIn = this.sellIn - 1;
|
||||||
|
|
||||||
|
this.decreaseQuality();
|
||||||
|
if (this.sellIn < 0) {
|
||||||
|
this.decreaseQuality();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
13
Java/src/main/java/com/gildedrose/SulfurasItem.java
Normal file
13
Java/src/main/java/com/gildedrose/SulfurasItem.java
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package com.gildedrose;
|
||||||
|
|
||||||
|
public class SulfurasItem extends Item {
|
||||||
|
|
||||||
|
public SulfurasItem(String name, int sellIn, int quality) {
|
||||||
|
super(name, sellIn, quality);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user