Skip to content

Commit

Permalink
ch1 p80-82
Browse files Browse the repository at this point in the history
  • Loading branch information
amoseui committed Mar 5, 2015
1 parent 0ab1779 commit d30e79e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
4 changes: 2 additions & 2 deletions OOAD/src/FindGuitarTester.java
Expand Up @@ -9,7 +9,7 @@ public static void main(String[] args) {
Inventory inventory = new Inventory();
initializeInventory(inventory);

GuitarSpec whatErinLikes = new GuitarSpec(Builder.FENDER, "Stratocaster", Type.ELECTRIC, Wood.ALDER, Wood.ALDER);
GuitarSpec whatErinLikes = new GuitarSpec(Builder.FENDER, "Stratocaster", Type.ELECTRIC, 12, Wood.ALDER, Wood.ALDER);

List<Guitar> matchingGuitars = inventory.search(whatErinLikes);
if (!matchingGuitars.isEmpty()) {
Expand All @@ -31,7 +31,7 @@ public static void main(String[] args) {

private static void initializeInventory(Inventory inventory) {
// 기타들을 재고 목록에 등
GuitarSpec spec = new GuitarSpec(Builder.FENDER, "Stratocaster", Type.ELECTRIC, Wood.ALDER, Wood.ALDER);
GuitarSpec spec = new GuitarSpec(Builder.FENDER, "Stratocaster", Type.ELECTRIC, 12, Wood.ALDER, Wood.ALDER);
inventory.addGuitar("V95693", 1499.95, spec);
inventory.addGuitar("V9512", 1549.95, spec);
}
Expand Down
23 changes: 22 additions & 1 deletion OOAD/src/GuitarSpec.java
Expand Up @@ -4,13 +4,16 @@ public class GuitarSpec {
private Builder builder;
private String model;
private Type type;
private int numStrings;
private Wood backWood;
private Wood topWood;
public GuitarSpec(Builder builder, String model, Type type, Wood backWood,

public GuitarSpec(Builder builder, String model, Type type, int numStrings, Wood backWood,
Wood topWood) {
this.builder = builder;
this.model = model;
this.type = type;
this.numStrings = numStrings;
this.backWood = backWood;
this.topWood = topWood;
}
Expand All @@ -27,11 +30,29 @@ public Type getType() {
return type;
}

public int getNumStrings() {
return numStrings;
}

public Wood getBackWood() {
return backWood;
}

public Wood getTopWood() {
return topWood;
}

public boolean matches(GuitarSpec otherSpec) {
if (builder != otherSpec.builder)
return false;
if ((model != null) && (!model.equals("")) && (!model.equals(otherSpec.model)))
return false;
if (type != otherSpec.type)
return false;
if (backWood != otherSpec.backWood)
return false;
if (topWood != otherSpec.topWood)
return false;
return true;
}
}
18 changes: 3 additions & 15 deletions OOAD/src/Inventory.java
Expand Up @@ -29,21 +29,9 @@ public List<Guitar> search(GuitarSpec searchSpec) {
List<Guitar> matchingGuitars = new LinkedList<Guitar>();
for (Iterator<Guitar> i = guitars.iterator(); i.hasNext(); ) {
Guitar guitar = (Guitar)i.next();
GuitarSpec guitarSpec = guitar.getSpec();
// 일련번호는 유일한 값이니까 무시
// 가격은 유일한 값이니깐 무시
if (searchSpec.getBuilder() != guitarSpec.getBuilder())
continue;
String model = searchSpec.getModel().toLowerCase();
if ((model != null) && (!model.equals("")) && (!model.equals(guitarSpec.getModel().toLowerCase())))
continue;
if (searchSpec.getType() != guitarSpec.getType())
continue;
if (searchSpec.getBackWood() != guitarSpec.getBackWood())
continue;
if (searchSpec.getTopWood() != guitarSpec.getTopWood())
continue;
matchingGuitars.add(guitar);
if (guitar.getSpec().matches(searchSpec)) {
matchingGuitars.add(guitar);
}
}
return matchingGuitars;
}
Expand Down

0 comments on commit d30e79e

Please sign in to comment.