-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package model; | ||
|
||
public class Box { | ||
private Water water; | ||
private Sugar sugar; | ||
private Cup cup; | ||
private Milktea milktea; | ||
private Coffee coffee; | ||
|
||
public Box(){ | ||
water = new Water(); | ||
sugar = new Sugar(); | ||
cup = new Cup(); | ||
milktea = new Milktea(); | ||
coffee = new Coffee(); | ||
} | ||
|
||
public Water getWater() { | ||
return water; | ||
} | ||
|
||
public Sugar getSugar() { | ||
return sugar; | ||
} | ||
|
||
public Cup getCup() { | ||
return cup; | ||
} | ||
|
||
public Milktea getMilktea() { | ||
return milktea; | ||
} | ||
|
||
public Coffee getCoffee() { | ||
return coffee; | ||
} | ||
public boolean isNotEmpty(){ | ||
return !water.isEmpty()&& | ||
!coffee.isEmpty()&& | ||
!milktea.isEmpty()&& | ||
!sugar.isEmpty()&& | ||
!cup.isEmpty(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package model; | ||
|
||
public class Coffee extends Material { | ||
|
||
private final int MAX_NUM = 100; | ||
protected final int ONE_CUP = 10; | ||
protected final int HALF_CUP = 5; | ||
|
||
public void fill() { | ||
this.setQuantity(MAX_NUM); | ||
} | ||
|
||
public void useOneCup(){ | ||
this.setQuantity(this.quantity-=ONE_CUP); | ||
} | ||
public void useHalfCup(){ | ||
this.setQuantity(this.quantity-=HALF_CUP); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package model; | ||
|
||
public enum CoffeeKind { | ||
ESSPRESO,LIGHT,MILKTEA; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package model; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Coin { | ||
private int num = 0; | ||
private List<CoinObserver> list; | ||
|
||
public Coin(){ | ||
list = new ArrayList<CoinObserver>(); | ||
} | ||
public void addObserver(CoinObserver co){ | ||
list.add(co); | ||
} | ||
public void removeObserver(CoinObserver co){ | ||
list.remove(co); | ||
} | ||
public void updateAll(){ | ||
for(CoinObserver co:list){ | ||
co.update(num); | ||
} | ||
} | ||
public void putCoin(){ | ||
num++; | ||
updateAll(); | ||
} | ||
|
||
public void getCoin(){ | ||
if(num>0){ | ||
num--; | ||
updateAll(); | ||
} | ||
} | ||
|
||
public int getNum() { | ||
return num; | ||
} | ||
|
||
public boolean isEmpty(){ | ||
return num==0; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package model; | ||
|
||
import javax.swing.JLabel; | ||
|
||
public class CoinNumberLabel extends JLabel implements CoinObserver { | ||
|
||
private static CoinNumberLabel anInstance; | ||
|
||
public static CoinNumberLabel getAnInstance(){ | ||
if(anInstance == null){ | ||
anInstance = new CoinNumberLabel(); | ||
} | ||
return anInstance; | ||
} | ||
|
||
private CoinNumberLabel(){ | ||
this.setText("0"); | ||
} | ||
|
||
public void update(int num) { | ||
this.setText(""+num); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package model; | ||
|
||
public interface CoinObserver { | ||
public void update(int num); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package model; | ||
|
||
public class Cup extends Material { | ||
|
||
private final int MAX_NUM = 10; | ||
private final int ONE_CUP = 1; | ||
|
||
public void fill() { | ||
this.setQuantity(MAX_NUM); | ||
} | ||
|
||
public void useOneCup() { | ||
this.setQuantity(quantity-=ONE_CUP); | ||
} | ||
|
||
} |