修改Item且增加4支subclass

This commit is contained in:
liaolizhen 2020-08-17 09:44:10 +08:00
parent 98ff07fb44
commit 56c16eaa70
5 changed files with 108 additions and 12 deletions

View 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();
}
}
}

View 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;
}
}
}

View File

@ -2,20 +2,36 @@ package com.gildedrose;
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) {
this.name = name;
this.sellIn = sellIn;
this.quality = quality;
}
public Item(String name, int sellIn, int quality) {
this.name = name;
this.sellIn = sellIn;
this.quality = quality;
}
@Override
public String toString() {
return this.name + ", " + this.sellIn + ", " + this.quality;
}
public void update() {
}
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;
}
}

View 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();
}
}
}

View 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() {
}
}