Skip to content

Commit c36b5d1

Browse files
committed
initial commit
0 parents  commit c36b5d1

5 files changed

Lines changed: 399 additions & 0 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
bin
2+
.settings
3+
.project
4+
.classpath

README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# The Gilded Rose Code Kata
2+
3+
This is a Java version of the Gilded Rose Kata, original found
4+
[here](http://www.iamnotmyself.com/2011/02/13/RefactorThisTheGildedRoseKata.aspx).
5+
6+
7+
## A few small changes
8+
9+
* After seeing jim weirich [ruby port](http://github.com/jimweirich/gilded_rose_kata) I also included tests in the project for the original functionality.
10+
11+
* I have moved the hard coded items to the default constructor and gave an alternative constructor to allows the tests to inject the list of items.
12+
13+
14+
## Setup
15+
16+
This has been setup as an eclipse project. I have not provided an ant build file or a maven pom.
17+
* To setup create a new java project in eclipse. (check out the code from git hub directly or import it into your java project)
18+
* add the junit 4 library to your build path.
19+
* include both the test and src directory as "Source Folders"
20+
* right click the project and run as JUnit test
21+
22+
23+
## Branches
24+
25+
* The 'master' branch contains the starting point for the kata. It is
26+
also tagged as 'start-here'.
27+
28+
* The 'solution' branch is my first solution for this kata. Feedback welcome!
29+
30+
It was fun. You should give it a try!
31+
32+
Alex
33+
34+
35+
# Original Description of the Gilded Rose
36+
37+
Hi and welcome to team Gilded Rose. As you know, we are a small inn
38+
with a prime location in a prominent city ran by a friendly innkeeper
39+
named Allison. We also buy and sell only the finest
40+
goods. Unfortunately, our goods are constantly degrading in quality as
41+
they approach their sell by date. We have a system in place that
42+
updates our inventory for us. It was developed by a no-nonsense type
43+
named Leeroy, who has moved on to new adventures. Your task is to add
44+
the new feature to our system so that we can begin selling a new
45+
category of items. First an introduction to our system:
46+
47+
- All items have a SellIn value which denotes the number of days we
48+
have to sell the item
49+
- All items have a Quality value which denotes how valuable the item
50+
is
51+
- At the end of each day our system lowers both values for every item
52+
53+
Pretty simple, right? Well this is where it gets interesting:
54+
55+
- Once the sell by date has passed, Quality degrades twice as fast
56+
- The Quality of an item is never negative
57+
- "Aged Brie" actually increases in Quality the older it gets
58+
- The Quality of an item is never more than 50
59+
- "Sulfuras", being a legendary item, never has to be sold or
60+
decreases in Quality
61+
- "Backstage passes", like aged brie, increases in Quality as it's
62+
SellIn value approaches; Quality increases by 2 when there are 10
63+
days or less and by 3 when there are 5 days or less but Quality
64+
drops to 0 after the concert
65+
66+
We have recently signed a supplier of conjured items. This requires an update to our system:
67+
68+
- "Conjured" items degrade in Quality twice as fast as normal items
69+
70+
Feel free to make any changes to the UpdateQuality method and add any
71+
new code as long as everything still works correctly. However, do not
72+
alter the Item class or Items property as those belong to the goblin
73+
in the corner who will insta-rage and one-shot you as he doesn't
74+
believe in shared code ownership (you can make the UpdateQuality
75+
method and Items property static if you like, we'll cover for
76+
you). Your work needs to be completed by Friday, February 18, 2011
77+
08:00:00 AM PST.
78+
79+
Just for clarification, an item can never have its Quality increase
80+
above 50, however "Sulfuras" is a legendary item and as such its
81+
Quality is 80 and it never alters.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package com.alexaitken.gildedrose;
2+
3+
public class Inventory {
4+
5+
private Item[] items;
6+
7+
public Inventory(Item[] items) {
8+
super();
9+
this.items = items;
10+
}
11+
12+
public Inventory() {
13+
super();
14+
items = new Item[] {
15+
new Item("+5 Dexterity Vest", 10, 20),
16+
new Item("Aged Brie", 2, 0),
17+
new Item("Elixir of the Mongoose", 5, 7),
18+
new Item("Sulfuras, Hand of Ragnaros", 0, 80),
19+
new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20),
20+
new Item("Conjured Mana Cake", 3, 6)
21+
};
22+
23+
}
24+
25+
public void updateQuality() {
26+
for (int i = 0; i < items.length; i++) {
27+
if (items[i].getName() != "Aged Brie"
28+
&& items[i].getName() != "Backstage passes to a TAFKAL80ETC concert") {
29+
if (items[i].getQuality() > 0) {
30+
if (items[i].getName() != "Sulfuras, Hand of Ragnaros") {
31+
items[i].setQuality(items[i].getQuality() - 1);
32+
}
33+
}
34+
} else {
35+
if (items[i].getQuality() < 50) {
36+
items[i].setQuality(items[i].getQuality() + 1);
37+
38+
if (items[i].getName() == "Backstage passes to a TAFKAL80ETC concert") {
39+
if (items[i].getSellIn() < 11) {
40+
if (items[i].getQuality() < 50) {
41+
items[i].setQuality(items[i].getQuality() + 1);
42+
}
43+
}
44+
45+
if (items[i].getSellIn() < 6) {
46+
if (items[i].getQuality() < 50) {
47+
items[i].setQuality(items[i].getQuality() + 1);
48+
}
49+
}
50+
}
51+
}
52+
}
53+
54+
if (items[i].getName() != "Sulfuras, Hand of Ragnaros") {
55+
items[i].setSellIn(items[i].getSellIn() - 1);
56+
}
57+
58+
if (items[i].getSellIn() < 0) {
59+
if (items[i].getName() != "Aged Brie") {
60+
if (items[i].getName() != "Backstage passes to a TAFKAL80ETC concert") {
61+
if (items[i].getQuality() > 0) {
62+
if (items[i].getName() != "Sulfuras, Hand of Ragnaros") {
63+
items[i].setQuality(items[i].getQuality() - 1);
64+
}
65+
}
66+
} else {
67+
items[i].setQuality(items[i].getQuality()
68+
- items[i].getQuality());
69+
}
70+
} else {
71+
if (items[i].getQuality() < 50) {
72+
items[i].setQuality(items[i].getQuality() + 1);
73+
}
74+
}
75+
}
76+
}
77+
}
78+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
*
3+
*/
4+
package com.alexaitken.gildedrose;
5+
6+
public class Item {
7+
8+
private String name;
9+
private int sellIn;
10+
11+
private int quality;
12+
13+
public Item(String name, int sellIn, int quality) {
14+
super();
15+
this.name = name;
16+
this.sellIn = sellIn;
17+
this.quality = quality;
18+
}
19+
20+
public String getName() {
21+
return name;
22+
}
23+
24+
public void setName(String name) {
25+
this.name = name;
26+
}
27+
28+
public int getSellIn() {
29+
return sellIn;
30+
}
31+
32+
public void setSellIn(int sellIn) {
33+
this.sellIn = sellIn;
34+
}
35+
36+
public int getQuality() {
37+
return quality;
38+
}
39+
40+
public void setQuality(int quality) {
41+
this.quality = quality;
42+
}
43+
}

0 commit comments

Comments
 (0)