diff --git a/.gitignore b/.gitignore
index 838db96..18794cf 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
/bin/
./.classpath
-./.project
\ No newline at end of file
+./.project
+/.settings/
\ No newline at end of file
diff --git a/docs/DesignPattern.md b/docs/DesignPattern.md
new file mode 100644
index 0000000..0a4a6b5
--- /dev/null
+++ b/docs/DesignPattern.md
@@ -0,0 +1,360 @@
+# API 说明文档
+
+# 1 题材综述
+
+# 1.1 介绍
+
+基于欢乐农场的选题,开发了包括牲畜养殖,田地种植,人员任务分配,资源管理等功能的framework。
+
+# 1.2 成员
+
+组长:
+赵伟
+组员:
+黄耀贤
+徐伟喆
+俞杨
+李庆国
+张宇
+侯禹志
+成佳杰
+覃敏溢
+冯玉山
+
+# 2 Design Pattern 汇总表
+
+见 "汇总表.docx"
+
+# 3 实现
+
+## 3.1 State
+
+### 3.1.1 一套实现
+
+#### 3.1.1.1 API描述
+
+Plant类维护一个PlantState子类的实例,这个实例定义为当前状态,PlantState类封装一个与Plant类特定状态相关的行为,而其子类实现一个与Plant类一个状态相关的行为,如成熟时可以收割等,同时提供接口实现状态的转换
+
+#### 3.1.1.2 class diagram
+
+ 
+
+ ## 3.2 FlyWeight
+
+### 3.2.1 一套实现
+
+#### 3.2.1.1 API描述
+
+StylePool类创建并管理BorderStyle对象,当用户请求一个BorderStyle对象时,提供一个已创建的实例或者在请求的实例不存在的情况下,新创建一个BorderStyle实例返回给用户
+
+#### 3.2.1.2 class diagram
+
+ 
+
+ ## 3.3 Strategy
+
+### 3.3.1 一套实现
+
+#### 3.3.1.1 API描述
+
+MachineWork定义一个doWork()接口,而MachineSchedule类通过这个接口来调用MachineIrrigation等类实现的具体算法,如对作物进行浇水和收获等等
+
+#### 3.3.1.2 class diagram
+
+ 
+
+### 3.3.2 一套实现
+
+#### 3.3.2.1 API描述
+
+Buy作为一个购买的抽象父类,提供了addToList()抽象方法,在BuyLivestock和BuySeed中做不同的实现,由此可对于购买牲畜或种子饲料两种不同的行为做出不同的操作。
+
+#### 3.3.2.2 class diagram
+
+ 
+
+### 3.3.3 一套实现
+
+#### 3.3.3.1 API描述
+
+BuyLivestock作为一个购买牲畜的抽象父类,提供了create()抽象方法,在其子类中做不同的实现,由此可对于购买不同牲畜的行为做出不同的操作。
+
+#### 3.3.3.2 class diagram
+
+
+
+ ## 3.4 Mediator
+
+### 3.4.1 一套实现
+
+#### 3.4.1.1 API描述
+
+Carrier类定义了一个carryToWareHouse接口用于Warehouse类和Product类、Plant类之间的协调操作,如将Plant类生产的产品放入仓库,由Warehouse类实例保存
+
+#### 3.4.1.2 class diagram
+
+ 
+
+ ### 3.4.2 一套实现
+
+ #### 3.4.2.1 API描述
+
+ 各种牲畜(pig,ox,cow,chook等)通过livestock类访问livestockstate。livestockstate中封装了牲畜的各种行为,如喂食,饮水及状态转换等操作。
+
+#### 3.4.1.2 class diagram
+
+
+
+ ## 3.5 Abstract Factory
+
+### 3.5.1 一套实现
+
+#### 3.5.1.1 API描述
+
+WorkFactory类既提供接口产生Worker类实例也提供接口生成WorkAdapter类的实例
+
+#### 3.5.1.2 class diagram
+
+ 
+
+ ## 3.6 Builder
+
+### 3.6.1 一套实现
+
+#### 3.6.1.1 API描述
+
+Builder类提供接口产生指定BuildingAction的子类实例,通过调用相同的函数实现不同实例创建
+
+#### 3.6.1.2 class diagram
+
+ 
+
+### 3.6.2 一套实现
+
+#### 3.6.2.1 API描述
+
+LivestockFarm创建并管理各个存储Livestock的ArrayList。Animalhouse通过implement接口BuildingAction来继承接口,Animalhouse实现生成LivestockFarm。LivsetockFarmDirector执行Animalhouse生成LivestockFarm的动作。
+
+#### 3.6.2.2 class diagram
+
+
+
+ ## 3.7 Bridge
+
+### 3.7.1 一套实现
+
+#### 3.7.1.1 API描述
+
+BorderStyle类提供接口供Title类实例进行调用,进而改变样式。StyleA等类实现父类函数
+
+#### 3.7.1.2 class diagram
+
+ 
+
+ ## 3.8 Composite
+
+### 3.8.1 一套实现
+
+#### 3.8.1.1 API描述
+
+Animalhouse类和LivestockFarm类共同继承BuildingAction类,Animalhouse类中含有LivestockFarm类的实例的集合,并提供接口函数
+
+#### 3.8.1.2 class diagram
+
+ 
+
+## 3.9 Decorator
+
+### 3.9.1 一套实现
+
+#### 3.9.1.1 API描述
+
+Manager类实现call函数进行人员工作调用,SuperManager类继承于Manager类,类中保有一个Manager类实例,并重写Manager类的call函数,对其进行装饰,在对人进行命令同时可对机器下达指令
+
+#### 3.9.1.2 class diagram
+
+ 
+
+## 3.10 Proxy
+
+### 3.10.1 一套实现
+
+#### 3.10.1.1 API描述
+
+FarmMaster类和Manager类共同继承于CommandDispatcher类,分别实现了父类中声明的call函数,但FarmMaster类中的call函数实际调用了Manager类中的call函数进实现命令的下达
+
+#### 3.10.1.2 class diagram
+
+ 
+
+## 3.11 Command
+
+### 3.11.1 一套实现
+
+#### 3.11.1.1 API描述
+
+CommandDispatcher类通过call函数下达指令,Worker类作为Receiver提供action来实现命令的实际执行,Command类提供了execute函数进行任务的执行,其中调用指定的Worker的action函数实现命令的执行
+
+#### 3.11.1.2 class diagram
+
+ 
+
+## 3.12 Iterator
+
+### 3.12.1 一套实现
+
+#### 3.12.1.1 API描述
+
+LivestockFarm类作为集合体,保有一系列Livestock的实例,Iterator类作为迭代器,提供hasNext()和next()接口实现访问和遍历
+
+#### 3.12.1.2 class diagram
+
+ 
+
+## 3.13 Observer
+
+### 3.13.1 一套实现
+
+#### 3.13.1.1 API描述
+
+Factory类作为被观察者,保有一个Seller类的实例,而Seller类作为观察者,在Factory类调用dealAndSell()函数是调用Sale类中的静态函数sale()实现生产出产品的直接售卖
+
+#### 3.13.1.2 class diagram
+
+ 
+
+## 3.14 Façade
+
+### 3.14.1 一套实现
+
+#### 3.14.1.1 API描述
+
+在整个农场系统中,FieldContainer类作为整个系统的接口为外界提供开垦田地,播种,浇水,收割等接口,而Land类、Plant类则保有在系统内部,根据FieldContainer类接口的调用来实现响应的功能
+
+#### 3.14.1.2 class diagram
+
+ 
+
+ ## 3.15 Prototype
+
+ ### 3.15.1 一套实现
+
+ #### 3.15.1.1 API描述
+
+ Livestock类创建并管理各种牲畜对象,如pig,cow等,当进行购买动作后,自动新增对应牲畜对象。
+
+#### 3.15.1.2 class diagram
+
+
+### 3.15.2 一套实现
+
+#### 3.15.2.1 API描述
+
+创建一个基类Wstate,然后扩展该类的实体为Sunny,Windy,Rainy。请求调用时调用Wstate中的findandclone函数,就会生成之前从未用过的类型到_states[10]数组中,之后会从该数组中克隆想要的类返会给调用者
+
+#### 3.15.2.2 class diagram
+
+
+
+### 3.15.3 一套实现
+
+#### 3.15.3.1 API描述
+
+创建一个基类 Goods 和扩展了 Goods 类的实体类。下一步是定义类 ShapeCache,该类把 shape 对象存储在一个 Hashtable 中,并在请求的时候返回它们的克隆。
+
+#### 3.15.3.2 class diagram
+
+
+
+## 3.16 Template Method
+
+### 3.16.1 一套实现
+
+#### 3.16.1.1 API描述
+
+BuyLivestock作为泛化父类,其中create()为抽象函数,在start()中使用了create()和已经声明并定义的函数addToList(),作为模板函数。而create()是在BuyLivestock的子类BuyChook、BuyPig、BuyOx,BuySheep等子类中实现的。
+
+#### 3.16.1.2 class diagram
+
+ 
+
+ ## 3.17 Singleton
+
+### 3.17.1 一套实现
+
+#### 3.17.1.1 API描述
+
+ResList类中会声明一个静态对象ResList r,并提供唯一访问接口Instance()来对其进行访问,以此实现全局仅有一个ResList单例用于存储农场的各种信息。
+
+#### 3.17.1.2 class diagram
+
+ 
+
+## 3.18 Factory Method
+
+### 3.18.1 一套实现
+
+#### 3.18.1.1 API描述
+
+在父类BuyLivestock中定义一个返回Livestock类对象的抽象函数create(),并在其子类中进行实现,由此可以在Livestock中有新的子类时,可以新增一个BuyLivestock的子类创建特定的Livestock子类对象。
+
+#### 3.18.1.2 class diagram
+
+ 
+
+### 3.18.2 一套实现
+
+ #### 3.18.2.1 API描述
+
+ Animalhouse、Warehouse、Factory是BuildingAction接口的实现,通过调用BuildingFactory中的produce函数实现房屋实例的创建。
+
+ #### 3.18.2.2 class diagram
+
+ 
+
+## 3.19 Memento
+
+### 3.19.1 一套实现
+
+#### 3.19.1.1 API描述
+
+ResMemento用于保存ResList一个时刻的状态,用于备份和还原。createMemento()可以将ResList中信息保存到ResMemento对象中,形成数据备份;setStateFromMemento()可以将ResMemento对象中的数据还原到ResList单例中。
+
+#### 3.19.1.2 class diagram
+
+ 
+
+ ## 3.20 Visitor
+
+ ### 3.20.1 一套实现
+
+ #### 3.20.1.1 API描述
+
+ 在创建一系列天气类,诸如Sunny,Windy,Rainy类之后,会被存入Wstate中的一个Vector数组array中,只要在array数组首位调用accept函数,在函数参数内new一个ListVisitor就可以由listvisitor访问array数组并输出其中的对象,表示最近的天气状况。
+
+ #### 3.20.1.2 class diagram
+
+ 
+
+ ## 3.21 Chain of Responsibility
+
+ ### 3.21.1 一套实现
+
+ #### 3.21.1.1 API描述
+
+ 抽象类Store中有商品和原材料种类的分级,VegStore和MeatStore是依据级别对应的两种商店,通过调用Sale类的sale函数实现商品的售卖。
+
+ #### 3.21.1.2 class diatram
+
+ 
+ ## 3.22 Adapter
+
+### 3.22.1 一套实现
+
+#### 3.22.1.1 API描述
+
+通过WorkerAdapter类适配MachineSchedule类,使之可以实现Worker类职能
+
+#### 3.22.1.2 class diagram
+
+ 
diff --git a/docs/DesignPattern.pdf b/docs/DesignPattern.pdf
new file mode 100644
index 0000000..262ccda
Binary files /dev/null and b/docs/DesignPattern.pdf differ
diff --git a/docs/image/AbstractFactory.png b/docs/image/AbstractFactory.png
new file mode 100644
index 0000000..6b6b0a9
Binary files /dev/null and b/docs/image/AbstractFactory.png differ
diff --git a/docs/image/Adapter.png b/docs/image/Adapter.png
new file mode 100644
index 0000000..195a551
Binary files /dev/null and b/docs/image/Adapter.png differ
diff --git a/docs/image/Bridge.png b/docs/image/Bridge.png
new file mode 100644
index 0000000..b5c2ba8
Binary files /dev/null and b/docs/image/Bridge.png differ
diff --git a/docs/image/Builder.png b/docs/image/Builder.png
new file mode 100644
index 0000000..e94d0b5
Binary files /dev/null and b/docs/image/Builder.png differ
diff --git a/docs/image/Command.png b/docs/image/Command.png
new file mode 100644
index 0000000..e65d196
Binary files /dev/null and b/docs/image/Command.png differ
diff --git a/docs/image/Decorator.png b/docs/image/Decorator.png
new file mode 100644
index 0000000..db8cd95
Binary files /dev/null and b/docs/image/Decorator.png differ
diff --git "a/docs/image/Fa\303\247ade.png" "b/docs/image/Fa\303\247ade.png"
new file mode 100644
index 0000000..d4ff655
Binary files /dev/null and "b/docs/image/Fa\303\247ade.png" differ
diff --git a/docs/image/Iterator.png b/docs/image/Iterator.png
new file mode 100644
index 0000000..e37f26f
Binary files /dev/null and b/docs/image/Iterator.png differ
diff --git a/docs/image/Observer.png b/docs/image/Observer.png
new file mode 100644
index 0000000..42390b7
Binary files /dev/null and b/docs/image/Observer.png differ
diff --git a/docs/image/Proxy.png b/docs/image/Proxy.png
new file mode 100644
index 0000000..0b772e0
Binary files /dev/null and b/docs/image/Proxy.png differ
diff --git a/docs/image/buy_factory.png b/docs/image/buy_factory.png
new file mode 100644
index 0000000..cf44b71
Binary files /dev/null and b/docs/image/buy_factory.png differ
diff --git a/docs/image/buy_memento.png b/docs/image/buy_memento.png
new file mode 100644
index 0000000..1cecf73
Binary files /dev/null and b/docs/image/buy_memento.png differ
diff --git a/docs/image/buy_singleton.png b/docs/image/buy_singleton.png
new file mode 100644
index 0000000..873254f
Binary files /dev/null and b/docs/image/buy_singleton.png differ
diff --git a/docs/image/buy_stragegy1.png b/docs/image/buy_stragegy1.png
new file mode 100644
index 0000000..3c90657
Binary files /dev/null and b/docs/image/buy_stragegy1.png differ
diff --git a/docs/image/buy_stragegy2.png b/docs/image/buy_stragegy2.png
new file mode 100644
index 0000000..07482f2
Binary files /dev/null and b/docs/image/buy_stragegy2.png differ
diff --git a/docs/image/buy_template.png b/docs/image/buy_template.png
new file mode 100644
index 0000000..1302768
Binary files /dev/null and b/docs/image/buy_template.png differ
diff --git a/docs/image/carrier_mediate.jpg b/docs/image/carrier_mediate.jpg
new file mode 100644
index 0000000..bad2238
Binary files /dev/null and b/docs/image/carrier_mediate.jpg differ
diff --git a/docs/image/composite.png b/docs/image/composite.png
new file mode 100644
index 0000000..37965cf
Binary files /dev/null and b/docs/image/composite.png differ
diff --git a/docs/image/deal_factory.png b/docs/image/deal_factory.png
new file mode 100644
index 0000000..423d769
Binary files /dev/null and b/docs/image/deal_factory.png differ
diff --git a/docs/image/deal_prototype.jpg b/docs/image/deal_prototype.jpg
new file mode 100644
index 0000000..a4fbcf9
Binary files /dev/null and b/docs/image/deal_prototype.jpg differ
diff --git a/docs/image/livestock_Builder.png b/docs/image/livestock_Builder.png
new file mode 100644
index 0000000..85f07e2
Binary files /dev/null and b/docs/image/livestock_Builder.png differ
diff --git a/docs/image/livestock_mediator.png b/docs/image/livestock_mediator.png
new file mode 100644
index 0000000..2910828
Binary files /dev/null and b/docs/image/livestock_mediator.png differ
diff --git a/docs/image/livestock_prototype.png b/docs/image/livestock_prototype.png
new file mode 100644
index 0000000..cf7e036
Binary files /dev/null and b/docs/image/livestock_prototype.png differ
diff --git a/docs/image/logo_flyWeight.jpg b/docs/image/logo_flyWeight.jpg
new file mode 100644
index 0000000..e9f26ee
Binary files /dev/null and b/docs/image/logo_flyWeight.jpg differ
diff --git a/docs/image/machine_strategy.jpg b/docs/image/machine_strategy.jpg
new file mode 100644
index 0000000..0c5cc31
Binary files /dev/null and b/docs/image/machine_strategy.jpg differ
diff --git a/docs/image/plant_state.jpg b/docs/image/plant_state.jpg
new file mode 100644
index 0000000..15f8fb2
Binary files /dev/null and b/docs/image/plant_state.jpg differ
diff --git a/docs/image/sale_rolechain.png b/docs/image/sale_rolechain.png
new file mode 100644
index 0000000..94b9878
Binary files /dev/null and b/docs/image/sale_rolechain.png differ
diff --git a/docs/image/weather_clone.jpg b/docs/image/weather_clone.jpg
new file mode 100644
index 0000000..c3bfa34
Binary files /dev/null and b/docs/image/weather_clone.jpg differ
diff --git a/docs/image/weather_visitor.jpg b/docs/image/weather_visitor.jpg
new file mode 100644
index 0000000..cd44607
Binary files /dev/null and b/docs/image/weather_visitor.jpg differ
diff --git a/docs/tester.docx b/docs/tester.docx
new file mode 100644
index 0000000..cf5eed0
Binary files /dev/null and b/docs/tester.docx differ
diff --git "a/docs/\346\261\207\346\200\273\350\241\250.docx" "b/docs/\346\261\207\346\200\273\350\241\250.docx"
new file mode 100644
index 0000000..1871308
Binary files /dev/null and "b/docs/\346\261\207\346\200\273\350\241\250.docx" differ
diff --git a/src/.classpath b/src/.classpath
new file mode 100644
index 0000000..3f3893a
--- /dev/null
+++ b/src/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/src/.gitignore b/src/.gitignore
new file mode 100644
index 0000000..f7a9d95
--- /dev/null
+++ b/src/.gitignore
@@ -0,0 +1,10 @@
+/BuyDemo.class
+/FieldDemo.class
+/LogoDemo.class
+/MachineworkDemo.class
+/PlantProductDemo.class
+/WorkerDemo.class
+/Main.class
+/DealAndSaleDemo.class
+/WeatherDemo.class
+/Demo.class
diff --git a/src/.project b/src/.project
new file mode 100644
index 0000000..0f6f6a7
--- /dev/null
+++ b/src/.project
@@ -0,0 +1,17 @@
+
+
+ src
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/src/BuyDemo.java b/src/BuyDemo.java
new file mode 100644
index 0000000..ebb4d76
--- /dev/null
+++ b/src/BuyDemo.java
@@ -0,0 +1,48 @@
+import java.util.Vector;
+
+import buy.*;
+import livestock.*;
+public class BuyDemo {
+
+ public static void main(String[] args) {
+ // TODO Auto-generated method stub
+
+ //The amount of money at first
+ System.out.print("You have "+ResList.Instance().money+" at first.\n\n");
+ //buy a chook
+ Vector newChook=new BuyChook().start(1);
+ System.out.print("The chook's ID is "+newChook.get(0).getId()+".\n\n");
+
+ //buy a cow
+ Vector newCow=new BuyCow().start(1);
+ System.out.print("The cow's ID is "+newCow.get(0).getId()+".\n\n");
+
+ //buy an ox
+ Vector newOx=new BuyOx().start(1);
+ System.out.print("The ox's ID is "+newOx.get(0).getId()+".\n\n");
+
+ //buy a pig
+ Vector newPig=new BuyPig().start(1);
+ System.out.print("The pig's ID is "+newPig.get(0).getId()+".\n\n");
+
+ //buy a sheep
+ Vector newSheep=new BuySheep().start(1);
+ System.out.print("The sheep's ID is "+newSheep.get(0).getId()+".\n\n");
+
+ //buy 5 units of cabbage seed
+ new BuySeedOrFeed().addToList(0, 5);
+
+ //buy 5 units of carrot seed
+ new BuySeedOrFeed().addToList(1, 5);
+
+ //buy 5 units of apple seed
+ new BuySeedOrFeed().addToList(2, 5);
+
+ //buy 5 units of pear seed
+ new BuySeedOrFeed().addToList(3, 5);
+
+ //buy 5 units of feed
+ new BuySeedOrFeed().addToList(4, 5);
+ }
+
+}
diff --git a/src/DealAndSaleDemo.java b/src/DealAndSaleDemo.java
new file mode 100644
index 0000000..aec3ef4
--- /dev/null
+++ b/src/DealAndSaleDemo.java
@@ -0,0 +1,32 @@
+
+import construction.BuildingFactory;
+import construction.Factory;
+import construction.Sale;
+import thing.Goods;
+import thing.Product;
+
+public class DealAndSaleDemo {
+
+
+ public static void main(String[] args) {
+
+ BuildingFactory test=new BuildingFactory(); //Build a factory
+ Factory aaa=(Factory)test.produce("factory");
+
+ Product a=new Product(); //Get a product
+ a.setType(2);
+ a.setNumber(4);
+ a.setPrice(5);
+ Goods s=aaa.deal(a); //Deal the product
+ Sale.sale(s); //Sale the product
+
+ Product b=new Product(); //Get a product
+ b.setNumber(3);
+ b.setPrice(8);
+ b.setType(7);
+ Sale.sale(b); //Sale the product
+
+ aaa.dealAndSell(b);
+ }
+
+}
diff --git a/src/Demo.java b/src/Demo.java
new file mode 100644
index 0000000..5ea34bb
--- /dev/null
+++ b/src/Demo.java
@@ -0,0 +1,30 @@
+import construction.*;
+import thing.Goods;
+import thing.Product;
+
+public class Demo {
+ public static void main(String[] args) {
+ Farm farm = Farm.getInstance();
+
+ Warehouse ware=farm.getWarehouse();
+ Factory factory=farm.getFactory();
+
+ System.out.println("Show the list:");
+ ware.showAmount();
+
+ Product a=new Product(); //Get a product
+ a.setType(2);
+ a.setNumber(4);
+ a.setPrice(5);
+ ware.store(a);
+
+ System.out.println("\nShow the list:");
+ ware.showAmount();
+
+ Product aa = ware.getProduct(2, 2);
+ factory.dealAndSell(aa); //Deal the product
+
+ System.out.println("\nShow the list:");
+ ware.showAmount();
+ }
+}
diff --git a/src/FieldDemo.java b/src/FieldDemo.java
new file mode 100644
index 0000000..83d1b0f
--- /dev/null
+++ b/src/FieldDemo.java
@@ -0,0 +1,17 @@
+import thing.FieldContainer;
+
+public class FieldDemo {
+
+ public static void main(String[] args) { //state pattern
+ // TODO Auto-generated method stub
+ FieldContainer fc = FieldContainer.getInstance();
+ System.out.println("-----");
+ fc.makeNewLand();
+ fc.sow(0, 0); //the initial state of a new plant is raw
+ fc.fertilize(0); //after fertilization it changes to FertilizedButNotIrrigated
+ fc.irrigate(0); //after fertilization and irrigation, it changes to Matured
+ fc.harvest(0); //when it's matured, it can be harvest, if else not
+
+ }
+
+}
diff --git a/src/LivestockDemo.java b/src/LivestockDemo.java
new file mode 100644
index 0000000..e980f20
--- /dev/null
+++ b/src/LivestockDemo.java
@@ -0,0 +1,54 @@
+import java.util.Vector;
+
+import livestock.*;
+import thing.*;
+public class LivestockDemo {
+ public static void main(String[] args) {
+ //new a chook
+ Chook newchook=new Chook(1);
+ //let chook drink
+ newchook.nowstate.Drink();
+ //feed chook
+ newchook.nowstate.Feed();
+ //get egg
+ newchook.getEgg();
+
+ //new a cow
+ Cow newcow=new Cow(1);
+ //let cow drink
+ newcow.nowstate.Drink();
+ //feed it
+ newcow.nowstate.Feed();
+ //get milk
+ newcow.getMilk();
+
+ //new a ox;
+ Ox newox=new Ox(1);
+ //let ox drink;
+ newox.nowstate.Drink();
+ //feed it
+ newox.nowstate.Feed();
+ //slaughter
+ newox.slaughter();
+
+ //new a sheep
+ Sheep newsheep=new Sheep(1);
+ // let sheep drink
+ newsheep.nowstate.Drink();
+ //feed it
+ newsheep.nowstate.Feed();
+ //get wool
+ newsheep.getWool();
+
+ //new a pig
+ Pig newpig=new Pig(1);
+ //let pig drink
+ newpig.nowstate.Drink();
+ //feed it
+ newpig.nowstate.Feed();
+ //slaughter
+ newpig.slaughter();
+
+ }
+
+}
\ No newline at end of file
diff --git a/src/LogoDemo.java b/src/LogoDemo.java
new file mode 100644
index 0000000..ebc35dd
--- /dev/null
+++ b/src/LogoDemo.java
@@ -0,0 +1,11 @@
+import logo.*;
+import java.lang.ref.*;
+public class LogoDemo { //flyweight pattern
+ public static void main(String[] args) { //Title is a singleton
+ Title.getTitleInstance().setStyle(0); //there're totally 3 styles, so the param should be between 0 and 2
+ Title.getTitleInstance().setContent("fly"); //the style is the shared object
+ Title.getTitleInstance().printLogo(); //see logo.Title
+ Title.getTitleInstance().setStyle(1);
+ Title.getTitleInstance().printLogo();
+ }
+}
diff --git a/src/MachineworkDemo.java b/src/MachineworkDemo.java
new file mode 100644
index 0000000..1489332
--- /dev/null
+++ b/src/MachineworkDemo.java
@@ -0,0 +1,23 @@
+import thing.*;
+
+import java.util.ArrayList;
+
+import machine.*;
+
+public class MachineworkDemo { //strategy pattern
+ public static void main(String[] args) {
+ FieldContainer fc = FieldContainer.getInstance();
+ System.out.println("-----");
+ fc.makeNewLand();
+ fc.makeNewLand();
+ ArrayListlands=fc.getEmptyLands();
+ int size=lands.size();
+ for(int i=0;i fivePigs=new BuyPig().start(5);
- for(int i=0;i<5;i++)
- {
- System.out.print(fivePigs.get(i).getId());
- }
- //ʾ5
- new BuySeedOrFeed().addToList(0, 6);
-
- //float a = s_type.price(0);
- }
-
-}
diff --git a/src/MementoDemo.java b/src/MementoDemo.java
new file mode 100644
index 0000000..05b431e
--- /dev/null
+++ b/src/MementoDemo.java
@@ -0,0 +1,17 @@
+import buy.*;
+public class MementoDemo {
+ public static void main(String[] args) {
+ ResList resList = ResList.Instance();
+
+ //amount of money at first
+ System.out.print("You have "+ resList.money + " at first.\n\n");
+ //create and store the memento
+ ResMemento memento=resList.createMemento();
+ //buy a cow to change the state of reslist
+ new BuyCow().start(1);
+ //use memento to set state
+ resList.setStateFromMemento(memento);
+ //amount of money after recovering
+ System.out.print("\nNow you have "+ resList.money + " again.\n\n");
+ }
+}
diff --git a/src/PlantProductDemo.java b/src/PlantProductDemo.java
new file mode 100644
index 0000000..d8c01f2
--- /dev/null
+++ b/src/PlantProductDemo.java
@@ -0,0 +1,13 @@
+import thing.Carrier;
+import thing.Product;
+import thing.ProductType;
+
+public class PlantProductDemo { //mediate pattern
+ public static void main(String[] args) {
+ Carrier newCarrier=new Carrier(new Product(ProductType.CABBAGE,1));
+ newCarrier.carryToWareHouse(); //carrier is a mediate works between a harvest operation
+ //and the store operation of a certain product of warehouse
+ //Here ONLY to show the inside pattern
+ //User or Client directly using the carrier is !DISCOURAGED!
+ }
+}
diff --git a/src/WeatherDemo.java b/src/WeatherDemo.java
new file mode 100644
index 0000000..6cc34d9
--- /dev/null
+++ b/src/WeatherDemo.java
@@ -0,0 +1,28 @@
+import weather.Listvisitor;
+import weather.Weather;
+import weather.Wstate;
+
+import java.util.ArrayList;
+
+public class WeatherDemo {
+ public static void main(String[]args)
+ {
+ ArrayListinput=new ArrayList();
+ input.add(Weather.sunny);
+ input.add(Weather.rainy);
+ input.add(Weather.windy);
+ input.add(Weather.sunny);
+ input.add(Weather.rainy);
+ input.add(Weather.windy);
+ input.add(Weather.windy);
+ input.add(Weather.sunny);
+ input.add(Weather.rainy);
+ int num_states=input.size();
+ Wstate[]state=new Wstate[num_states];
+ for(int i=0;i start(int num){//
- int id1 = reslist.l_list.get(type).size();
- for(int i = 0; i < num; i++){
- llist.addElement(create(id1));
- id1++;
- }
- addToList(type, num);
- return llist;
- }
}
\ No newline at end of file
diff --git a/src/buy/BuyCow.java b/src/buy/BuyCow.java
index b5d963f..e841438 100644
--- a/src/buy/BuyCow.java
+++ b/src/buy/BuyCow.java
@@ -1,27 +1,18 @@
package buy;
import livestock.*;
-import java.util.Vector;
import buy.ResList.l_type;
public class BuyCow extends BuyLivestock{
- private int type = l_type.cow.id();//ָtypeӦö
-
+ public BuyCow(){
+ type = l_type.cow.id();
+ }
@Override
public Livestock create(int id) {
Livestock cow = new Cow(id);
return cow;
}
- @Override
- public Vector start(int num){//
- int id1 = reslist.l_list.get(type).size();
- for(int i = 0; i < num; i++){
- llist.addElement(create(id1));
- id1++;
- }
- addToList(type, num);
- return llist;
- }
+
}
\ No newline at end of file
diff --git a/src/buy/BuyLivestock.java b/src/buy/BuyLivestock.java
index 6de2f1b..93a27d3 100644
--- a/src/buy/BuyLivestock.java
+++ b/src/buy/BuyLivestock.java
@@ -5,11 +5,39 @@
public abstract class BuyLivestock extends Buy{
ResList reslist = ResList.Instance();
public Vector llist = new Vector();
+ public int type = -1;
- public void addToList(int type, int num){//б
+ public void addToList(int type, int num){//Add new livestock to the list
reslist.l_list.get(type).addAll(llist);
+ switch (type){
+ case 0:
+ reslist.money -= 1000*num;
+ break;
+ case 1:
+ reslist.money -= 500*num;
+ break;
+ case 2:
+ reslist.money -= 5*num;
+ break;
+ case 3:
+ reslist.money -= 20*num;
+ break;
+ case 4:
+ reslist.money -= 300*num;
+ break;
+ };
}
- public abstract Livestock create(int id); //øú
- public abstract Vector start(int num);//øúָ
+ public abstract Livestock create(int id); //Call this function to generate new livestock
+
+ public Vector start(int num){//
+ int id1 = reslist.l_list.get(type).size();
+ for(int i = 0; i < num; i++){
+ llist.addElement(create(id1));
+ id1++;
+ }
+ addToList(type, num);
+ System.out.print("You have bought "+num+" Livestock(s) successfully. You still have "+reslist.money+" left.\n");
+ return llist;
+ }
}
diff --git a/src/buy/BuyOx.java b/src/buy/BuyOx.java
index 93f6c98..0b08d86 100644
--- a/src/buy/BuyOx.java
+++ b/src/buy/BuyOx.java
@@ -1,27 +1,17 @@
package buy;
import livestock.*;
-import java.util.Vector;
import buy.ResList.l_type;
public class BuyOx extends BuyLivestock{
- private int type = l_type.ox.id();//ָtypeӦö
-
+ public BuyOx(){
+ type = l_type.ox.id();
+ }
@Override
public Livestock create(int id) {
Livestock ox = new Ox(id);
return ox;
}
- @Override
- public Vector start(int num){//
- int id1 = reslist.l_list.get(type).size();
- for(int i = 0; i < num; i++){
- llist.addElement(create(id1));
- id1++;
- }
- addToList(type, num);
- return llist;
- }
}
diff --git a/src/buy/BuyPig.java b/src/buy/BuyPig.java
index 8347454..f5d9926 100644
--- a/src/buy/BuyPig.java
+++ b/src/buy/BuyPig.java
@@ -1,27 +1,17 @@
package buy;
import livestock.*;
-import java.util.Vector;
import buy.ResList.l_type;
public class BuyPig extends BuyLivestock{
- private int type = l_type.pig.id();//ָtypeӦö
-
+ public BuyPig(){
+ type = l_type.pig.id();
+ }
@Override
public Livestock create(int id) {
Livestock pig = new Pig(id);
return pig;
}
- @Override
- public Vector start(int num){//
- int id1 = reslist.l_list.get(type).size();
- for(int i = 0; i < num; i++){
- llist.addElement(create(id1));
- id1++;
- }
- addToList(type, num);
- return llist;
- }
}
\ No newline at end of file
diff --git a/src/buy/BuySeedOrFeed.java b/src/buy/BuySeedOrFeed.java
index ae08edf..2a8ab7e 100644
--- a/src/buy/BuySeedOrFeed.java
+++ b/src/buy/BuySeedOrFeed.java
@@ -1,17 +1,37 @@
package buy;
-import buy.ResList.s_type;
-
public class BuySeedOrFeed extends Buy {
@Override
public void addToList(int type, int num) {
ResList reslist = ResList.Instance();
reslist.s_list[type] += num;
- //switch type{
-
- //}
- //reslist.money-=();
+ String typeName = "";
+ switch (type) {
+ case 0:
+ typeName = "cabbage seed";
+ reslist.money -= num;
+ break;
+ case 1:
+ typeName = "carrot seed";
+ reslist.money -= num;
+ break;
+ case 2:
+ typeName = "apple seed";
+ reslist.money -= num;
+ break;
+ case 3:
+ typeName = "pear seed";
+ reslist.money -= num;
+ break;
+ case 4:
+ typeName = "feed";
+ reslist.money -= 2 * num;
+ break;
+ }
+ ;
+ System.out.print("You have bought " + num + " unit(s) of " + typeName + " successfully. You still have "
+ + reslist.money + " left.\n\n");
}
}
diff --git a/src/buy/BuySheep.java b/src/buy/BuySheep.java
index 608e330..b92a1b1 100644
--- a/src/buy/BuySheep.java
+++ b/src/buy/BuySheep.java
@@ -1,28 +1,17 @@
package buy;
import livestock.*;
-import java.util.Vector;
import buy.ResList.l_type;
public class BuySheep extends BuyLivestock{
- private int type = l_type.sheep.id();//ָtypeӦö
-
+ public BuySheep(){
+ type = l_type.sheep.id();
+ }
@Override
public Livestock create(int id) {
Livestock sheep = new Sheep(id);
return sheep;
}
-
- @Override
- public Vector start(int num){
- //
- int id1 = reslist.l_list.get(type).size();
- for(int i = 0; i < num; i++){
- llist.addElement(create(id1));
- id1++;
- }
- addToList(type, num);
- return llist;
- }
+
}
\ No newline at end of file
diff --git a/src/buy/ResList.java b/src/buy/ResList.java
index 9f466d4..507e1cd 100644
--- a/src/buy/ResList.java
+++ b/src/buy/ResList.java
@@ -12,7 +12,7 @@ private l_type(int i){
public int id(){
return type;
}
- };//
+ };//Livestock type
public enum s_type{
CabbageSeed(0,1),CarrotSeed(1,1),AppleSeed(2,1),PearSeed(3,1),feed(4,2);
private int type;
@@ -27,18 +27,28 @@ public int id(){
public float price(){
return price;
}
- };//ͻ
- public Vector> l_list = new Vector>(10);//洢ͬ
- public int[] s_list = new int[10];//洢ͬ
- public float money=1000;
+ };//Seed seedling type or feed
+ public Vector> l_list = new Vector>(10);//Store different livestock individuals
+ public int[] s_list = new int[10];//Store different seedlings or feed quantities
+ public float money=10000;
- private final static ResList r = new ResList();//Singleton ģʽ
+ private final static ResList r = new ResList();//Singleton pattern
private ResList(){
for(int i = 0; i < 6; i++){
Vector l = new Vector();
l_list.addElement(l);
}
};
+ public ResMemento createMemento() {
+ return new ResMemento();
+ }
+
+ public void setStateFromMemento(ResMemento memento) {
+ ResList resList = ResList.Instance();
+ resList.l_list = memento.l_list;
+ resList.money = memento.money;
+ resList.s_list = memento.s_list;
+ }
public static ResList Instance(){
return r;
}
diff --git a/src/buy/ResMemento.java b/src/buy/ResMemento.java
new file mode 100644
index 0000000..d13fde7
--- /dev/null
+++ b/src/buy/ResMemento.java
@@ -0,0 +1,19 @@
+package buy;
+
+import java.util.Vector;
+
+import livestock.Livestock;
+
+public class ResMemento {
+ public Vector> l_list;
+ public int[] s_list;
+ public float money;
+
+ public ResMemento() {
+ ResList resList = ResList.Instance();
+ l_list = resList.l_list;
+ money = resList.money;
+ s_list = resList.s_list;
+ }
+
+}
diff --git a/src/construction/.gitignore b/src/construction/.gitignore
new file mode 100644
index 0000000..ad7b2c5
--- /dev/null
+++ b/src/construction/.gitignore
@@ -0,0 +1,17 @@
+/Animalhouse.class
+/BuildingAction.class
+/BuildingFactory.class
+/BuildingTest.class
+/Factory.class
+/Farm.class
+/LivestockFarm$Iterator.class
+/LivestockFarm.class
+/LivsetockFarmDirector.class
+/MeatStore.class
+/Sale.class
+/Store.class
+/VegStore.class
+/Warehouse.class
+/a.class
+/FactoryBuilder.class
+/WarehouseBuilder.class
diff --git a/src/construction/Animalhouse.java b/src/construction/Animalhouse.java
index 70b912c..f50819a 100644
--- a/src/construction/Animalhouse.java
+++ b/src/construction/Animalhouse.java
@@ -1,34 +1,50 @@
package construction;
import java.util.ArrayList;
+
+import buy.ResList;
import construction.LivestockFarm;
+import livestock.Chook;
+import livestock.Cow;
+import livestock.Ox;
+import livestock.Pig;
+import livestock.Sheep;
public class Animalhouse implements BuildingAction {
-
- private LivestockFarm livsetockFarms;
-
+ private ArrayList livestockFarms;
public Animalhouse() {
- livsetockFarms = new LivestockFarm();
- }
-
- public LivestockFarm buildLivestockFarm() {
-
- System.out.println("The animalhouse have been built!");
- return livsetockFarms;
}
-
- @Override
public void build() {
- // TODO Auto-generated method stub
-
+ ResList resList=ResList.Instance();
+ if(resList.money<150) {
+ System.out.println("Your money is not enough");
+ return;
+ }
+ else {
+ resList.money=resList.money-150;
+ }
+ System.out.println("The factory have been built!");
}
-
- @Override
+ public boolean add(LivestockFarm livestockFarm) {
+ return livestockFarms.add(livestockFarm);
+ }
+ public boolean remove(LivestockFarm livestockFarm) {
+ return livestockFarms.remove(livestockFarm);
+ }
+ public LivestockFarm getLivestockFarm(String name) {
+ LivestockFarm live= null;
+ for (LivestockFarm livestockFarm : livestockFarms) {
+ if (name.equals(livestockFarm.getName())) {
+ live = livestockFarm;
+ }
+ }
+ return live;
+ }
public void repair() {
// TODO Auto-generated method stub
diff --git a/src/construction/AnimalhouseBuilder.java b/src/construction/AnimalhouseBuilder.java
new file mode 100644
index 0000000..cfb71f2
--- /dev/null
+++ b/src/construction/AnimalhouseBuilder.java
@@ -0,0 +1,27 @@
+package construction;
+
+public class AnimalhouseBuilder extends Builder{
+ private Animalhouse ah;
+ public Animalhouse buildAnimalhouse() {
+ createContainter();
+ createComponents();
+ return ah;
+ }
+
+ @Override
+ public void createContainter() {
+ // TODO Auto-generated method stub
+ ah = new Animalhouse();
+ }
+
+ @Override
+ public void createComponents() {
+ // TODO Auto-generated method stub
+ ah.add(new LivestockFarm("Chook"));
+ ah.add(new LivestockFarm("Cow"));
+ ah.add(new LivestockFarm("Ox"));
+ ah.add( new LivestockFarm("Pig"));
+ ah.add( new LivestockFarm("Sheep"));
+ }
+
+}
diff --git a/src/construction/Builder.java b/src/construction/Builder.java
new file mode 100644
index 0000000..821d3c4
--- /dev/null
+++ b/src/construction/Builder.java
@@ -0,0 +1,6 @@
+package construction;
+
+public abstract class Builder {
+ public abstract void createContainter();
+ public abstract void createComponents();
+}
diff --git a/src/construction/BuildingFactory.java b/src/construction/BuildingFactory.java
index 3e5e27e..0ad7f3f 100644
--- a/src/construction/BuildingFactory.java
+++ b/src/construction/BuildingFactory.java
@@ -4,11 +4,12 @@ public class BuildingFactory {
public static BuildingAction produce(String BulidingType) {
if("factory".equals(BulidingType)) {
- return new Factory();
+ return new FactoryBuilder().buildFactory();
}else if("warehouse".equals(BulidingType)) {
- return new Warehouse();
+ return new WarehouseBuilder().buildWarehouse();
}else if("animalhouse".equals(BulidingType)) {
- return new Animalhouse();
+
+ return new AnimalhouseBuilder().buildAnimalhouse();
}else {
System.out.println("Input the correct type!");
return null;
diff --git a/src/construction/BuildingTest.java b/src/construction/BuildingTest.java
index 013a047..9139438 100644
--- a/src/construction/BuildingTest.java
+++ b/src/construction/BuildingTest.java
@@ -1,4 +1,5 @@
package construction;
+import thing.Goods;
import thing.Product;
public class BuildingTest {
@@ -6,12 +7,23 @@ public class BuildingTest {
public static void main(String[] args) {
- BuildingFactory test=new BuildingFactory();
- Factory aaa=(Factory)test.produce("factory");
- Product a=new Product();
+ BuildingFactory test=new BuildingFactory(); //���콨��ģ����
+ Factory aaa=(Factory)test.produce("factory"); //���칤��
+
+ Product a=new Product(); //ʵ����ԭ��
a.setType(2);
a.setNumber(4);
- aaa.deal(a);
+ a.setPrice(5);
+ Goods s=aaa.deal(a); //�ӹ�ԭ�ϣ��õ���Ʒ���۸�
+ Sale.sale(s); //������Ʒ
+
+ Product b=new Product();
+ b.setNumber(3);
+ b.setPrice(8);
+ b.setType(7);
+ Sale.sale(b); //����ԭ��
+
+ aaa.dealAndSell(b);
}
}
diff --git a/src/construction/Factory.java b/src/construction/Factory.java
index 844a8ac..d8798dd 100644
--- a/src/construction/Factory.java
+++ b/src/construction/Factory.java
@@ -1,19 +1,40 @@
package construction;
+import buy.ResList;
import thing.*;
+import worker.Seller;
public class Factory implements BuildingAction {
-
+
+ private Seller seller;
+
public Factory() {
GoodsCache.loadCache();
+ seller = new Seller();
}
public void build() {
+ ResList resList=ResList.Instance();
+ if(resList.money<250) {
+ System.out.println("Your money is not enough");
+ return;
+ }
+ else {
+ resList.money=resList.money-250;
+ }
System.out.println("The factory have been built!");
}
public void repair() {
+ ResList resList=ResList.Instance();
+ if(resList.money<25) {
+ System.out.println("Your money is not enough");
+ return;
+ }
+ else {
+ resList.money=resList.money-25;
+ }
System.out.println("The factory is being repaired!");
}
@@ -26,8 +47,15 @@ public Goods deal(Product product) {
clonedGoods.setNumber(product.getNumber());
clonedGoods.setPrice(product.getPrice()*2);
return clonedGoods;
-// System.out.println(clonedGoods.getGoodsType());
-// System.out.println(clonedGoods.getNumber());
+ }
+ public void dealAndSell(Product product) {
+ Goods clonedGoods=(Goods)GoodsCache.getShape(product.getType());
+ clonedGoods.setNumber(product.getNumber());
+ clonedGoods.setPrice(product.getPrice()*2);
+ seller.sell(clonedGoods);
+ }
+ public void dealAndSell() {
+ System.out.println("can't sell it");
}
}
diff --git a/src/construction/FactoryBuilder.java b/src/construction/FactoryBuilder.java
new file mode 100644
index 0000000..ff703fc
--- /dev/null
+++ b/src/construction/FactoryBuilder.java
@@ -0,0 +1,23 @@
+package construction;
+
+public class FactoryBuilder extends Builder{
+ private Factory factory;
+ public Factory buildFactory() {
+ createContainter();
+ createComponents();
+ return factory;
+ }
+
+ @Override
+ public void createContainter() {
+ // TODO Auto-generated method stub
+ factory = new Factory();
+ }
+
+ @Override
+ public void createComponents() {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/src/construction/Farm.java b/src/construction/Farm.java
index 9fb96cd..6fa4a9b 100644
--- a/src/construction/Farm.java
+++ b/src/construction/Farm.java
@@ -3,8 +3,10 @@
public class Farm {
private static Farm instance;
private Warehouse ware;
+ private Factory factory;
private Farm() {
ware=(Warehouse)BuildingFactory.produce("warehouse");
+ factory=(Factory)BuildingFactory.produce("factory");
}
public static Farm getInstance(){
if(instance==null) {
@@ -15,5 +17,7 @@ public static Farm getInstance(){
public Warehouse getWarehouse() {
return ware;
}
-
+ public Factory getFactory() {
+ return factory;
+ }
}
diff --git a/src/construction/LivestockFarm.java b/src/construction/LivestockFarm.java
index 08bee4c..f9ef235 100644
--- a/src/construction/LivestockFarm.java
+++ b/src/construction/LivestockFarm.java
@@ -1,45 +1,53 @@
package construction;
-import java.util.ArrayList;
-public class LivestockFarm {
+import java.util.ArrayList;
- private static LivestockFarm instance = null;
-
+import livestock.Livestock;
- private ArrayList LivsetockFarmPig;
- private ArrayList LivsetockFarmCow;
- private ArrayList LivsetockFarmOx;
- private ArrayList LivsetockFarmChook;
- private ArrayList LivsetockFarmSheep;
- LivestockFarm() {
-
- LivsetockFarmPig = new ArrayList<>();
- LivsetockFarmCow = new ArrayList<>();
- LivsetockFarmOx = new ArrayList<>();
- LivsetockFarmChook = new ArrayList<>();
- LivsetockFarmSheep = new ArrayList<>();
-
+public class LivestockFarm implements BuildingAction{
+ private ArrayList livestocks = new ArrayList<>();
+ public String name;
+ public LivestockFarm(String name) {
+ // TODO Auto-generated constructor stub
+ this.name = name;
}
- public static LivestockFarm getInstance() {
- if (instance==null) {
- instance = new LivestockFarm();
- }
- return instance;
+ public String getName() {
+ return name;
+ }
+ public void addLivestock(Livestock newLivestock) {
+ livestocks.add(newLivestock);
}
- public ArrayList getLivsetockFarmPig() {
- return LivsetockFarmPig;
+ class Iterator{
+ public boolean hasNext() {
+ return livestocks.iterator().hasNext();
+ }
+ public Livestock next() {
+ return livestocks.iterator().next();
+ }
}
- public ArrayList getLivsetockFarmCow() {
- return LivsetockFarmCow;
+ public Livestock getLivestock(int id) {
+ Livestock ls = null;
+ for (Livestock livestock : livestocks) {
+ if (ls.getId() == id) {
+ ls = livestock;
+ }
+ }
+ return ls;
}
- public ArrayList getLivsetockFarmOx() {
- return LivsetockFarmOx;
+ @Override
+ public void build() {
+ // TODO Auto-generated method stub
+
}
- public ArrayList getLivsetockFarmChook() {
- return LivsetockFarmChook;
+ @Override
+ public void repair() {
+ // TODO Auto-generated method stub
+
}
- public ArrayList getLivsetockFarmSheep() {
- return LivsetockFarmSheep;
+ @Override
+ public void destory() {
+ // TODO Auto-generated method stub
+
}
}
diff --git a/src/construction/LivsetockFarmDirector.java b/src/construction/LivsetockFarmDirector.java
deleted file mode 100644
index 235553d..0000000
--- a/src/construction/LivsetockFarmDirector.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package construction;
-
-public class LivsetockFarmDirector {
- public LivestockFarm createLivsetockFarmDirector(Animalhouse LF){
-
- return LF.buildLivestockFarm();
- }
-
-
-}
diff --git a/src/construction/MeatStore.java b/src/construction/MeatStore.java
new file mode 100644
index 0000000..34c9003
--- /dev/null
+++ b/src/construction/MeatStore.java
@@ -0,0 +1,28 @@
+package construction;
+
+import buy.ResList;
+import thing.Goods;
+import thing.Product;
+
+public class MeatStore extends Store{
+ public MeatStore(int level){
+ this.level = level;
+ }
+
+ protected void sale() {
+
+ }
+
+ protected int sale(Product forsale) {
+ System.out.println("MeatStore: $" + forsale.getPrice()*forsale.getNumber());
+ ResList resList = ResList.Instance();
+ resList.money += forsale.getPrice()*forsale.getNumber();
+ return forsale.getPrice()*forsale.getNumber();
+ }
+ protected int sale(Goods forsale) {
+ System.out.println("MeatStore: $" + forsale.getPrice()*forsale.getNumber());
+ ResList resList = ResList.Instance();
+ resList.money += forsale.getPrice()*forsale.getNumber();
+ return forsale.getPrice()*forsale.getNumber();
+ }
+}
diff --git a/src/construction/Sale.java b/src/construction/Sale.java
new file mode 100644
index 0000000..0178fd5
--- /dev/null
+++ b/src/construction/Sale.java
@@ -0,0 +1,31 @@
+package construction;
+
+import thing.Goods;
+import thing.Product;
+
+public class Sale {
+ private static Store getChainOfStores(){
+
+ Store vegStore = new VegStore(Store.VEG);
+ Store meatStore = new MeatStore(Store.MEATS);
+
+ vegStore.setNextStore(meatStore);
+
+ return vegStore;
+ }
+
+ public static void sale(Product product) {
+ Store storeChain = getChainOfStores();
+ storeChain.storeMessage(product);
+ }
+
+ public static void sale(Goods product) {
+ Store storeChain = getChainOfStores();
+ storeChain.storeMessage(product);
+ }
+
+ public static void sale() {
+ System.out.println("can't sell it");
+ }
+
+}
diff --git a/src/construction/Store.java b/src/construction/Store.java
new file mode 100644
index 0000000..94b5b7f
--- /dev/null
+++ b/src/construction/Store.java
@@ -0,0 +1,49 @@
+package construction;
+
+import buy.ResList;
+import thing.Goods;
+import thing.Product;
+
+public abstract class Store {
+ public static int VEG = 3;
+ public static int MEATS = 8;
+
+ protected int level;
+
+ //璐d换閾句腑鐨勪笅涓�涓厓绱�
+ protected Store nextStore;
+
+ public void setNextStore(Store nextStore){
+ this.nextStore = nextStore;
+ }
+
+// public void storeMessage(int level, String message){
+// if(this.level <= level){
+// sale(message);
+// }
+// if(nextStore !=null){
+// nextStore.storeMessage(level, message);
+// }
+// }
+
+ public void storeMessage(Product forsale){
+ if(this.level >= forsale.getType()){
+ ResList.Instance().money += sale(forsale);
+ }
+ else {
+ nextStore.storeMessage(forsale);
+ }
+ }
+
+ public void storeMessage(Goods forsale){
+ if(this.level >= forsale.getId()){
+ ResList.Instance().money += sale(forsale);
+ }
+ else {
+ nextStore.storeMessage(forsale);
+ }
+ }
+
+ abstract protected int sale(Product forsale);
+ abstract protected int sale(Goods forsale);
+}
diff --git a/src/construction/VegStore.java b/src/construction/VegStore.java
new file mode 100644
index 0000000..8e34cf2
--- /dev/null
+++ b/src/construction/VegStore.java
@@ -0,0 +1,26 @@
+package construction;
+
+import buy.*;
+
+import thing.Goods;
+import thing.Product;
+
+public class VegStore extends Store{
+ public VegStore(int level){
+ this.level = level;
+ }
+
+ protected int sale(Product forsale) {
+ System.out.println("VegStore: $" + forsale.getPrice()*forsale.getNumber());
+ ResList resList = ResList.Instance();
+ resList.money += forsale.getPrice()*forsale.getNumber();
+ return forsale.getPrice()*forsale.getNumber();
+ }
+
+ protected int sale(Goods forsale) {
+ System.out.println("VegStore: $" + forsale.getPrice()*forsale.getNumber());
+ ResList resList = ResList.Instance();
+ resList.money += forsale.getPrice()*forsale.getNumber();
+ return forsale.getPrice()*forsale.getNumber();
+ }
+}
diff --git a/src/construction/Warehouse.java b/src/construction/Warehouse.java
index 8ce951f..9c068b6 100644
--- a/src/construction/Warehouse.java
+++ b/src/construction/Warehouse.java
@@ -1,11 +1,45 @@
package construction;
+import java.util.Hashtable;
+
+import buy.ResList;
import thing.Product;
public class Warehouse implements BuildingAction {
- private int [] catalog=new int [4];
+ private int [] catalog=new int [9];
+ private int [] priceList= {1,2,3,5,15,13,2,7,4};
+ private static Hashtable shapeMap;
+
+ private static void initHashtable() {
+ shapeMap=new Hashtable();
+ shapeMap.put(0,"CABBAGE");
+ shapeMap.put(1,"CARROT");
+ shapeMap.put(2,"APPLE");
+ shapeMap.put(3,"PEAR");
+ shapeMap.put(4,"BEEF");
+ shapeMap.put(5,"PORK");
+ shapeMap.put(6,"EGG");
+ shapeMap.put(7,"WOOL");
+ shapeMap.put(8,"MILK");
+ }
+
+ public Warehouse() {
+ initHashtable();
+ }
+
+ public Warehouse(int [] arg) {
+ catalog = arg;
+ }
public void build() {
+ ResList resList=ResList.Instance();
+ if(resList.money<200) {
+ System.out.println("Your money is not enough");
+ return;
+ }
+ else {
+ resList.money=resList.money-200;
+ }
System.out.println("The warehouse have been built!");
for(int i=0;inumber) {
+ if(this.catalog[category]>=number) {
this.catalog[category]=this.catalog[category]-number;
Product product=new Product();
product.setType(category);
product.setNumber(number);
+ product.setPrice(priceList[category]);
return product;
}
else {
- System.out.println("The warehouse has no "+category);
- return null;
+ System.out.println("The warehouse has no "+getName(category));
+ Product product=new Product();
+ return product;
}
}
diff --git a/src/construction/WarehouseBuilder.java b/src/construction/WarehouseBuilder.java
new file mode 100644
index 0000000..3aa0562
--- /dev/null
+++ b/src/construction/WarehouseBuilder.java
@@ -0,0 +1,23 @@
+package construction;
+
+public class WarehouseBuilder extends Builder {
+
+ private Warehouse warehouse;
+ public Warehouse buildWarehouse() {
+ createContainter();
+ createComponents();
+ return warehouse;
+ }
+ @Override
+ public void createContainter() {
+ // TODO Auto-generated method stub
+ warehouse = new Warehouse();
+ }
+
+ @Override
+ public void createComponents() {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/src/construction/a.java b/src/construction/a.java
new file mode 100644
index 0000000..751ad2b
--- /dev/null
+++ b/src/construction/a.java
@@ -0,0 +1,17 @@
+package construction;
+
+import thing.Goods;
+import thing.Product;
+
+public class a {
+
+ public static void main(String[] args) {
+ Goods a=new Goods();
+ a.setNumber(2);
+ a.setPrice(5);
+ a.setId(2);
+ Sale.sale(a);
+
+ }
+
+}
diff --git a/src/livestock/.gitignore b/src/livestock/.gitignore
new file mode 100644
index 0000000..b696e90
--- /dev/null
+++ b/src/livestock/.gitignore
@@ -0,0 +1,7 @@
+/Chook.class
+/Cow.class
+/Livestock$species.class
+/Livestock.class
+/Ox.class
+/Pig.class
+/Sheep.class
diff --git a/src/livestock/Chook.java b/src/livestock/Chook.java
index 67049c2..5b7755e 100644
--- a/src/livestock/Chook.java
+++ b/src/livestock/Chook.java
@@ -4,9 +4,9 @@
import thing.Carrier;
import thing.Product;
import thing.ProductType;
-//̳Livestock
+
public class Chook extends Livestock{
- //캯
+ //Constructor
public Chook (int id)
{
super(id,species.chook,species.chook.getPrice());
@@ -17,20 +17,20 @@ public void getProduct() {
newCarrier.carryToWareHouse();
}
- //ռ
+ //Egg collection
public boolean getEgg() {
- //µ
+ //Chickens have laid eggs
if(nowstate.getState()==1)
{
System.out.println("ü");
- //ü
-
- //ü״̬
+ //Get eggs
+ getProduct();
+ //Reset chicken status
nowstate.setFeedTime();
nowstate.setDrinkTime();
return true;
}
- //δµ
+ //The chicken does not lay eggs
else {
System.out.println("ûм");
return false;
diff --git a/src/livestock/Cow.java b/src/livestock/Cow.java
index 0581834..d59ff20 100644
--- a/src/livestock/Cow.java
+++ b/src/livestock/Cow.java
@@ -17,20 +17,20 @@ public void getProduct() {
Carrier newCarrier=new Carrier(new Product(ProductType.MILK,9));
newCarrier.carryToWareHouse();
}
- //
+ //Milk
public boolean getMilk()
{
if(nowstate.getState() == 1 )
{
- System.out.println("");
- //
+ System.out.println("Milking Success");
+ //Milking Success
nowstate.setDrinkTime();
nowstate.setFeedTime();
getProduct();
return true;
}
else {
- System.out.println("ܼ");
+ System.out.println("Not milking yet.");
return false;
}
}
diff --git a/src/livestock/Livestock.java b/src/livestock/Livestock.java
index a330c65..1053244 100644
--- a/src/livestock/Livestock.java
+++ b/src/livestock/Livestock.java
@@ -3,9 +3,9 @@
import thing.LivestockState;
public abstract class Livestock {
- protected LivestockState nowstate;
+ public LivestockState nowstate=new LivestockState();
private int id;
- //ö٣۸
+ //Species enumeration,includiong prices
public enum species{
ox(1000),sheep(500),chook(5),cow(20),pig(300);
private float price;
@@ -16,13 +16,13 @@ float getPrice() {
return price;
}
};
- //öٱ
+
private species spe;
//private int lingDays;
//private float weight;
//private int place;
- //캯
+ //Constructor
public Livestock(int id,species s,float price)
{
this.id=id;
diff --git a/src/livestock/Ox.java b/src/livestock/Ox.java
index 69e3afa..224d558 100644
--- a/src/livestock/Ox.java
+++ b/src/livestock/Ox.java
@@ -23,14 +23,14 @@ public boolean slaughter()
{
if(nowstate.getState() == 1 )
{
- System.out.println("");
- //
+ System.out.println("slaughter success");
+ //slaughtering success
getProduct();
nowstate.died();
return true;
}
else {
- System.out.println("");
+ System.out.println("Not slaughtering yet.");
return false;
}
}
diff --git a/src/livestock/Pig.java b/src/livestock/Pig.java
index 23f178b..3fa7ee5 100644
--- a/src/livestock/Pig.java
+++ b/src/livestock/Pig.java
@@ -20,14 +20,14 @@ public boolean slaughter()
{
if(nowstate.getState()==1)
{
- System.out.println("");
- //òƷ
+ System.out.println("Slaughter success");
+ //Get pork
getProduct();
nowstate.died();
return true;
}
else {
- System.out.println("");
+ System.out.println("Not slaughtering yet.");
return false;
}
}
diff --git a/src/livestock/Sheep.java b/src/livestock/Sheep.java
index bf397c8..5c4a1d0 100644
--- a/src/livestock/Sheep.java
+++ b/src/livestock/Sheep.java
@@ -1,24 +1,34 @@
package livestock;
import livestock.Livestock.species;
+import thing.Carrier;
+import thing.Product;
+import thing.ProductType;
public class Sheep extends Livestock {
public Sheep(int id)
{
super(id,species.sheep,species.sheep.getPrice());
}
+
+ public void getProduct() {
+ // TODO Auto-generated method stub
+ Carrier newCarrier=new Carrier(new Product(ProductType.WOOL,7));
+ newCarrier.carryToWareHouse();
+
+ }
public boolean getWool() {
if(nowstate.getState()==1)
{
- System.out.println("ëɹ");
- //ë
-
+ System.out.println("Wool cutting success");
+ //Wool cutting success
+ getProduct();
nowstate.setFeedTime();
nowstate.setDrinkTime();
return true;
}
else {
- System.out.println("ܸë");
+ System.out.println("Wool is can not cut now.");
return false;
}
}
diff --git a/src/logo/.gitignore b/src/logo/.gitignore
new file mode 100644
index 0000000..d7e2d38
--- /dev/null
+++ b/src/logo/.gitignore
@@ -0,0 +1,6 @@
+/BorderStyle.class
+/StyleA.class
+/StyleB.class
+/StyleC.class
+/StylePool.class
+/Title.class
diff --git a/src/machine/.gitignore b/src/machine/.gitignore
new file mode 100644
index 0000000..8e32f95
--- /dev/null
+++ b/src/machine/.gitignore
@@ -0,0 +1,5 @@
+/MachineFertilization.class
+/MachineHarvest.class
+/MachineIrrigation.class
+/MachineSchedule.class
+/MachineWork.class
diff --git a/src/machine/MachineHarvest.java b/src/machine/MachineHarvest.java
index 9682b6e..d6863a7 100644
--- a/src/machine/MachineHarvest.java
+++ b/src/machine/MachineHarvest.java
@@ -5,11 +5,11 @@
import thing.FieldContainer;
import thing.Land;
-public class MachineHarvest {
+public class MachineHarvest implements MachineWork{
public void doWork() {
ArrayList lands=FieldContainer.getInstance().getLands();
for(Land l : lands) {
- l.irrigate();
+ l.harvest();
}
}
}
diff --git a/src/machine/MachineIrrigation.java b/src/machine/MachineIrrigation.java
index ed2ecff..96273f6 100644
--- a/src/machine/MachineIrrigation.java
+++ b/src/machine/MachineIrrigation.java
@@ -2,7 +2,7 @@
import java.util.ArrayList;
import thing.*;
-public class MachineIrrigation {
+public class MachineIrrigation implements MachineWork {
public void doWork() {
ArrayList lands=FieldContainer.getInstance().getLands();
for(Land l : lands) {
diff --git a/src/machine/WorkAdapter.java b/src/machine/WorkAdapter.java
new file mode 100644
index 0000000..e2369d7
--- /dev/null
+++ b/src/machine/WorkAdapter.java
@@ -0,0 +1,17 @@
+package machine;
+
+import worker.Worker;
+
+public class WorkAdapter extends Worker{
+ public MachineSchedule machineSchedule;
+ public WorkAdapter(MachineSchedule machineSchedule) {
+ // TODO Auto-generated constructor stub
+ this.machineSchedule = machineSchedule;
+ type = "ALL";
+ }
+ @Override
+ public void action(int id) {
+ // TODO Auto-generated method stub
+ machineSchedule.execute();
+ }
+}
diff --git a/src/plant/.gitignore b/src/plant/.gitignore
new file mode 100644
index 0000000..f2de5c6
--- /dev/null
+++ b/src/plant/.gitignore
@@ -0,0 +1,8 @@
+/AppleTree.class
+/Cabbage.class
+/Carrot.class
+/DisposablePlant.class
+/PearTree.class
+/Plant.class
+/RepeatablePlant.class
+/Seed.class
diff --git a/src/plant/AppleTree.java b/src/plant/AppleTree.java
index 5275b9b..ea9f54c 100644
--- a/src/plant/AppleTree.java
+++ b/src/plant/AppleTree.java
@@ -11,4 +11,10 @@ public void getProduct() {
Carrier newCarrier=new Carrier(new Product(ProductType.APPLE,1));
newCarrier.carryToWareHouse();
}
+
+ @Override
+ public void showType() {
+ // TODO Auto-generated method stub
+ System.out.print("ƻ");
+ }
}
diff --git a/src/plant/Cabbage.java b/src/plant/Cabbage.java
index 557a795..546dba1 100644
--- a/src/plant/Cabbage.java
+++ b/src/plant/Cabbage.java
@@ -10,6 +10,10 @@ public void getProduct() {
Carrier newCarrier=new Carrier(new Product(ProductType.CABBAGE,1));
newCarrier.carryToWareHouse();
}
-
+ @Override
+ public void showType() {
+ // TODO Auto-generated method stub
+ System.out.print("");
+ }
}
diff --git a/src/plant/Carrot.java b/src/plant/Carrot.java
index 682cdfc..2a26a58 100644
--- a/src/plant/Carrot.java
+++ b/src/plant/Carrot.java
@@ -11,4 +11,9 @@ public void getProduct() {
Carrier newCarrier=new Carrier(new Product(ProductType.CARROT,1));
newCarrier.carryToWareHouse();
}
+ @Override
+ public void showType() {
+ // TODO Auto-generated method stub
+ System.out.print("ܲ");
+ }
}
diff --git a/src/plant/DisposablePlant.java b/src/plant/DisposablePlant.java
index a7f3311..6a967e3 100644
--- a/src/plant/DisposablePlant.java
+++ b/src/plant/DisposablePlant.java
@@ -6,7 +6,7 @@ public abstract class DisposablePlant extends Plant {
public boolean harvest() {
// TODO Auto-generated method stub
if(growState.harvest(this)) {
-
+
return false;
}
return true;
diff --git a/src/plant/PearTree.java b/src/plant/PearTree.java
index 98d5ac5..c4cd752 100644
--- a/src/plant/PearTree.java
+++ b/src/plant/PearTree.java
@@ -11,4 +11,9 @@ public void getProduct() {
Carrier newCarrier=new Carrier(new Product(ProductType.PEAR,1));
newCarrier.carryToWareHouse();
}
+ @Override
+ public void showType() {
+ // TODO Auto-generated method stub
+ System.out.print("");
+ }
}
diff --git a/src/plant/Plant.java b/src/plant/Plant.java
index 944221e..de1a974 100644
--- a/src/plant/Plant.java
+++ b/src/plant/Plant.java
@@ -2,9 +2,10 @@
import thing.PlantState;
import thing.Product;
+import thing.Raw;
public abstract class Plant {
- protected PlantState growState; // ֲ״̬
+ protected PlantState growState=Raw.getInstance(); // ֲ״̬
public void showPlantState() {
growState.showState();
}
@@ -26,5 +27,5 @@ public void irrigated() {
public void changeState(PlantState state) {
growState = state;
}
-
+ public abstract void showType();
}
diff --git a/src/prototype_visitor/.gitignore b/src/prototype_visitor/.gitignore
new file mode 100644
index 0000000..fe5a329
--- /dev/null
+++ b/src/prototype_visitor/.gitignore
@@ -0,0 +1,9 @@
+/acceptor.class
+/listvisitor.class
+/rainy.class
+/run.class
+/sunny.class
+/visitor.class
+/weather.class
+/windy.class
+/wstate.class
diff --git a/src/test/.gitignore b/src/test/.gitignore
new file mode 100644
index 0000000..74a37cb
--- /dev/null
+++ b/src/test/.gitignore
@@ -0,0 +1,8 @@
+/Main.class
+/User.class
+/FarmUse.class
+/LandUse.class
+/BuyUse.class
+/DealAndSellUse.class
+/LivestockUse.class
+/WeatherUse.class
diff --git a/src/test/BuyUse.java b/src/test/BuyUse.java
new file mode 100644
index 0000000..877a0b3
--- /dev/null
+++ b/src/test/BuyUse.java
@@ -0,0 +1,146 @@
+package test;
+import buy.*;
+
+import java.util.Scanner;
+
+public class BuyUse {
+ private Scanner in;
+ public BuyUse(Scanner in) {
+ this.in = in;
+ }
+
+ public void menu(){
+ ResList resList = ResList.Instance();
+ System.out.println("-------Welcome to shopping!-------");
+ System.out.println("You have " + ResList.Instance().money + " now.");
+ System.out.println("And you have "
+ + resList.l_list.get(0).size() + " ox(en), "
+ + resList.l_list.get(1).size() + " sheep, " +
+ + resList.l_list.get(2).size() + " chook(s), " +
+ + resList.l_list.get(3).size() + " cow(s), " +
+ + resList.l_list.get(4).size() + " pig(s), \n" +
+ + resList.s_list[0] + " cabbage seed, "
+ + resList.s_list[1] + " carrot seed, " +
+ + resList.s_list[2] + " apple seed, " +
+ + resList.s_list[3] + " pear seed, \nand " +
+ + resList.s_list[4] + " feed " + "now.");
+ System.out.println("-----------------------------------------------");
+ System.out.println("You can buy livestocks, seeds or feed here.");
+ System.out.println("Enter the follwing number to choose what you want ot buy:");
+ System.out.println("-------Livestocks-------");
+ System.out.println("1. Ox");
+ System.out.println("2. Sheep");
+ System.out.println("3. Chook");
+ System.out.println("4. Cow");
+ System.out.println("5. Pig");
+ System.out.println("-----Seeds or Feed------");
+ System.out.println("6. Cabbage Seed");
+ System.out.println("7. Carrot Seed");
+ System.out.println("8. Apple Seed");
+ System.out.println("9. Pear Seed");
+ System.out.println("10. Feed");
+ System.out.println("------------------------");
+ System.out.println("11. Cancel");
+ System.out.print("Please enter the nunber:");
+ int flag = 0;
+ int amount = 0;
+ BuyLivestock buyLivestock = null;
+ if(in.hasNextInt())
+ flag = in.nextInt();
+ switch (flag) {
+ case 1:
+ System.out.print("Please enter the amount you want to buy:");
+ if(in.hasNextInt())
+ amount = in.nextInt();
+
+ buyLivestock = new BuyOx();
+ buyLivestock.start(amount);
+ System.out.println("Now you have " + resList.l_list.get(0).size() + " ox(en) now.");
+ break;
+ case 2:
+ System.out.print("Please enter the amount you want to buy:");
+ if(in.hasNextInt())
+ amount = in.nextInt();
+
+ buyLivestock = new BuySheep();
+ buyLivestock.start(amount);
+ System.out.println("Now you have " + resList.l_list.get(1).size() + " sheep now.");
+ break;
+ case 3:
+ System.out.print("Please enter the amount you want to buy:");
+ if(in.hasNextInt())
+ amount = in.nextInt();
+
+ buyLivestock = new BuyChook();
+ buyLivestock.start(amount);
+ System.out.println("Now you have " + resList.l_list.get(2).size() + " chook(s) now.");
+ break;
+ case 4:
+ System.out.print("Please enter the amount you want to buy:");
+ if(in.hasNextInt())
+ amount = in.nextInt();
+
+ buyLivestock = new BuyCow();
+ buyLivestock.start(amount);
+ System.out.println("Now you have " + resList.l_list.get(3).size() + " cow(s) now.");
+ break;
+ case 5:
+ System.out.print("Please enter the amount you want to buy:");
+ if(in.hasNextInt())
+ amount = in.nextInt();
+
+ buyLivestock = new BuyPig();
+ buyLivestock.start(amount);
+ System.out.println("Now you have " + resList.l_list.get(4).size() + " pig(s) now.");
+ break;
+ case 6:
+
+ System.out.print("Please enter the amount of cabbage seed you want to buy:");
+ if(in.hasNextInt())
+ amount = in.nextInt();
+ new BuySeedOrFeed().addToList(0, amount);
+ System.out.println("Now you have " + resList.s_list[0] + " unit(s) of cabbage seed now.");
+ break;
+ case 7:
+
+ System.out.print("Please enter the amount of carrot seed you want to buy:");
+ if(in.hasNextInt())
+ amount = in.nextInt();
+ new BuySeedOrFeed().addToList(1, amount);
+ System.out.println("Now you have " + resList.s_list[1] + " unit(s) of carrot seed now.");
+ break;
+ case 8:
+
+ System.out.print("Please enter the amount of apple seed you want to buy:");
+ if(in.hasNextInt())
+ amount = in.nextInt();
+ new BuySeedOrFeed().addToList(2, amount);
+ System.out.println("Now you have " + resList.s_list[2] + " unit(s) of apple seed now.");
+ break;
+ case 9:
+
+ System.out.print("Please enter the amount of pear seed you want to buy:");
+ if(in.hasNextInt())
+ amount = in.nextInt();
+ new BuySeedOrFeed().addToList(3, amount);
+ System.out.println("Now you have " + resList.s_list[3] + " unit(s) of pear seed now.");
+ break;
+ case 10:
+
+ System.out.print("Please enter the amount of feed you want to buy:");
+ if(in.hasNextInt())
+ amount = in.nextInt();
+ new BuySeedOrFeed().addToList(4, amount);
+ System.out.println("Now you have " + resList.s_list[4] + " unit(s) of feed seed now.");
+ break;
+ case 11:
+ break;
+ default:
+ System.out.println("wrong input");
+ break;
+ }
+
+ }
+
+}
+
diff --git a/src/test/DealAndSellUse.java b/src/test/DealAndSellUse.java
new file mode 100644
index 0000000..190f151
--- /dev/null
+++ b/src/test/DealAndSellUse.java
@@ -0,0 +1,70 @@
+package test;
+
+import java.util.Scanner;
+
+import construction.Factory;
+import construction.Farm;
+import construction.Sale;
+import construction.Warehouse;
+import thing.FieldContainer;
+import thing.Product;
+import thing.ProductType;
+
+public class DealAndSellUse {
+ private Scanner in;
+ public DealAndSellUse(Scanner in) {
+ // TODO Auto-generated constructor stub
+ this.in = in;
+ }
+
+ public void menu() {
+ System.out.println("\nThe order list");
+ boolean loop = true;
+ Farm farm = Farm.getInstance();
+
+ Warehouse ware=farm.getWarehouse();
+ Factory factory=farm.getFactory();
+ do {
+ System.out.println("\n1.Get the list");
+ System.out.println("2.Sell the products");
+ System.out.println("3.Sell the goods");
+ System.out.println("4.Exit");
+ if (in.hasNextInt()==false) {
+ System.out.println("wrong input");
+ in.next();
+// in.close();
+ continue;
+ }
+ int choice = in.nextInt();
+ switch (choice) {
+ case 1:
+ System.out.println("Show the list:");
+ ware.showAmount();
+ break;
+ case 2:
+ System.out.print("Enter the order of the product you want to sell:\n");
+ int type = in.nextInt();
+ System.out.print("Enter the number of the product you want to sell:\n");
+ int num = in.nextInt();
+ Sale.sale(ware.getProduct(type, num));
+ break;
+ case 3:
+ System.out.print("Enter the order of the goods you want to sell:\n");
+ int type1 = in.nextInt();
+ System.out.print("Enter the number of the goods you want to sell:\n");
+ int num1 = in.nextInt();
+ ware.showAmount();
+ factory.dealAndSell(ware.getProduct(type1, num1));
+ break;
+ case 4:
+ loop = false;
+ break;
+ default:
+ System.out.println("wrong input");
+ break;
+ }
+ }while(loop);
+
+ System.out.println("-------------EXIT-------------");
+ }
+}
diff --git a/src/test/FarmUse.java b/src/test/FarmUse.java
new file mode 100644
index 0000000..a2777ff
--- /dev/null
+++ b/src/test/FarmUse.java
@@ -0,0 +1,73 @@
+package test;
+
+import java.util.ArrayList;
+import java.util.Scanner;
+
+import plant.AppleTree;
+import plant.Cabbage;
+import plant.Carrot;
+import plant.PearTree;
+import thing.FieldContainer;
+import thing.Land;
+
+public class FarmUse {
+ private Scanner in;
+ public FarmUse(Scanner in) {
+ // TODO Auto-generated constructor stub
+ this.in = in;
+ }
+ public void menu() {
+ System.out.println("now you are at farmland\n\n");
+ boolean loop = true;
+ do {
+ System.out.println("Operations:");
+ System.out.println("1.make new land");
+ System.out.println("2.irragation/fertilization/harvest/remove operations");
+ System.out.println("3.show lands state");
+ System.out.println("4.exit");
+// Scanner in = new Scanner(System.in);
+ if (in.hasNextInt()==false) {
+ System.out.println("wrong input");
+ System.out.println("---------"+in.next()+"++++++++++++++");
+// in.close();
+ continue;
+ }
+ int choice = in.nextInt();
+// in.close();
+ switch (choice) {
+ case 1:
+ FieldContainer.getInstance().makeNewLand();
+ break;
+ case 2:
+ new LandUse(in).menu();
+ break;
+ case 3:
+ showLandState();
+ break;
+ case 4:
+ loop = false;
+ break;
+ default:
+ System.out.println("wrong input");
+ break;
+ }
+ } while (loop);
+
+ System.out.println("-------------EXIT-------------");
+ }
+ public void showLandState() {
+ FieldContainer fieldContainer = FieldContainer.getInstance();
+ ArrayList lands = fieldContainer.getLands();
+ ArrayList unlands = fieldContainer.getEmptyLands();
+ System.out.println("you have"+(lands.size()+unlands.size())+"lands: \n");
+ for (Land land : lands) {
+ System.out.println("land"+land.getLandID()+":");
+ land.showState();
+ }
+ for (Land land : unlands) {
+ System.out.println("land "+land.getLandID()+":");
+ System.out.println("uncultivated");
+ }
+ }
+
+}
diff --git a/src/test/LandUse.java b/src/test/LandUse.java
new file mode 100644
index 0000000..9eee423
--- /dev/null
+++ b/src/test/LandUse.java
@@ -0,0 +1,111 @@
+package test;
+
+import java.util.Scanner;
+
+import thing.FieldContainer;
+
+import buy.*;
+public class LandUse {
+ private Scanner in;
+ public LandUse(Scanner in) {
+ // TODO Auto-generated constructor stub
+ this.in = in;
+ }
+ public void menu() {
+ boolean loop = true;
+// Scanner in = new Scanner(System.in);
+ do {
+ System.out.println("choose operation");
+ System.out.println("1.sow");
+ System.out.println("2.irragation");
+ System.out.println("3.fertilization");
+ System.out.println("4.harvest");
+ System.out.println("5.remove");
+ System.out.println("6.exit");
+ if (in.hasNextInt()==false) {
+ System.out.println("wrong input");
+ continue;
+ }
+ int choice = in.nextInt();
+ switch (choice) {
+ case 1:
+ sow();
+ break;
+ case 2:
+ irrigate();
+ break;
+ case 3:
+ fertilize();
+ break;
+ case 4:
+ harvest();
+ break;
+ case 5:
+ remove();
+ break;
+ case 6:
+ loop = false;
+ break;
+ default:
+ System.out.println("wrong input");
+ break;
+ }
+ } while (loop);
+ }
+ public void sow() {
+ int landID = getLandID();
+ int plantType = 0;
+ System.out.println("enter your plant: 0 for cabbage, 1 for carrot, 2 for apple tree, 3 for pear tree");
+ boolean loop = true;
+ do {
+ if (in.hasNextInt()==false) {
+ System.out.println("wrong input");
+ in.next();
+ continue;
+ }
+ plantType = in.nextInt();
+ loop = false;
+ } while (loop);
+ if(plantType>3||plantType<0) {
+ System.out.println("wrong input");
+ return;
+ }
+ if(ResList.Instance().s_list[plantType]<=0) {
+ System.out.println("seed not enough");
+ return;
+ }
+ FieldContainer.getInstance().sow(plantType, landID);
+ }
+ public void remove() {
+ int landID = getLandID();
+ FieldContainer.getInstance().remove(landID);
+ }
+ public void fertilize() {
+ int landID = getLandID();
+ FieldContainer.getInstance().fertilize(landID);
+ }
+ public void irrigate() {
+ int landID = getLandID();
+ FieldContainer.getInstance().irrigate(landID);
+ }
+ public void harvest() {
+ int landID = getLandID();
+ FieldContainer.getInstance().harvest(landID);
+ }
+
+ public int getLandID() {
+ int landID = 0;
+ System.out.println("enter the landID you want to operate");
+ boolean loop = true;
+ do {
+ if (in.hasNextInt()==false) {
+ System.out.println("wrong input");
+ in.next();
+ continue;
+ }
+ landID = in.nextInt();
+ loop = false;
+ } while (loop);
+ return landID;
+ }
+}
diff --git a/src/test/LivestockUse.java b/src/test/LivestockUse.java
new file mode 100644
index 0000000..0f55e1b
--- /dev/null
+++ b/src/test/LivestockUse.java
@@ -0,0 +1,349 @@
+package test;
+
+import java.util.ArrayList;
+import java.util.Scanner;
+
+import livestock.*;
+import thing.*;
+
+public class LivestockUse {
+ private Scanner in;
+ private ArrayList oxList = new ArrayList();
+ private ArrayList cowList = new ArrayList();
+ private ArrayList pigList = new ArrayList();
+ private ArrayList sheepList = new ArrayList();
+ private ArrayList chookList = new ArrayList();
+
+ public LivestockUse(Scanner in) {
+ // TODO Auto-generated constructor stub
+ this.in = in;
+ }
+ public void menu() {
+ System.out.println("You have come to the livestock farm.\n\n");
+ boolean loop = true;
+ do {
+ System.out.println("Now you can choose the following operation.");
+ System.out.println("1.Put in new livestock.");
+ System.out.println("2.Feeding livestock");
+ System.out.println("3.Get products from livestock");
+ System.out.println("4.View livestock status");
+ System.out.println("5.exit");
+// Scanner in = new Scanner(System.in);
+ if (in.hasNextInt()==false) {
+ System.out.println("Error input");
+ System.out.println("---------"+in.next()+"++++++++++++++");
+// in.close();
+ continue;
+ }
+ int choice = in.nextInt();
+// in.close();
+ switch (choice) {
+ case 1:
+ System.out.println("Please choose livestock species.");
+ System.out.println("1.pig");
+ System.out.println("2.ox");
+ System.out.println("3.cow");
+ System.out.println("4.chook");
+ System.out.println("5.sheep");
+ if (in.hasNextInt()==false) {
+ System.out.println("Error input");
+ System.out.println("---------"+in.next()+"++++++++++++++");
+// in.close();
+ continue;
+ }
+ choice = in.nextInt();
+ switch (choice) {
+ case 1:
+ if(pigList.size()==0){
+ pigList.add(new Pig(1));
+ }
+ else pigList.add(new Pig(pigList.get(pigList.size()-1).getId()+1));
+ break;
+ case 2:
+ if(oxList.size()==0)
+ {
+ oxList.add(new Ox(1));
+ }
+ oxList.add(new Ox(oxList.get(oxList.size()-1).getId()+1));
+ break;
+ case 3:
+ if(cowList.size()==0)
+ {
+ cowList.add(new Cow(1));
+ }
+ cowList.add(new Cow(cowList.get(cowList.size()-1).getId()+1));
+ break;
+ case 4:
+ if(chookList.size()==0)
+ {
+ chookList.add(new Chook(1));
+ }
+ chookList.add(new Chook(chookList.get(chookList.size()-1).getId()+1));
+ break;
+ case 5:
+ if(sheepList.size()==0)
+ {
+ sheepList.add(new Sheep(1));
+ }
+ sheepList.add(new Sheep(sheepList.get(sheepList.size()-1).getId()+1));
+ break;
+ }
+ System.out.println("Put into success");
+ break;
+ case 2:
+ feedandDrink();
+ break;
+ case 3:
+ System.out.println("Please choose livestock species.");
+ System.out.println("1.pig");
+ System.out.println("2.ox");
+ System.out.println("3.cow");
+ System.out.println("4.chook");
+ System.out.println("5.sheep");
+ if (in.hasNextInt()==false) {
+ System.out.println("Error input");
+ System.out.println("---------"+in.next()+"++++++++++++++");
+// in.close();
+ continue;
+ }
+ choice = in.nextInt();
+ switch (choice) {
+ case 1:
+ System.out.println("Please input ID.");
+ if (in.hasNextInt()==false) {
+ System.out.println("error input");
+ System.out.println("---------"+in.next()+"++++++++++++++");
+// in.close();
+ continue;
+ }
+ choice = in.nextInt();
+ if(pigList.get(choice).slaughter() == true) {
+ pigList.remove(choice);
+ }
+ else System.out.println("It can't be slaughtered..");
+ case 2:
+ System.out.println("Please input ID.");
+ if (in.hasNextInt()==false) {
+ System.out.println("error input");
+ System.out.println("---------"+in.next()+"++++++++++++++");
+// in.close();
+ continue;
+ }
+ choice = in.nextInt();
+ if(oxList.get(choice).slaughter() == true) {
+ oxList.remove(choice);
+ }
+ else System.out.println("It can't be slaughtered..");
+ case 3:
+ System.out.println("Please input ID.");
+ if (in.hasNextInt()==false) {
+ System.out.println("error input");
+ System.out.println("---------"+in.next()+"++++++++++++++");
+// in.close();
+ continue;
+ }
+ choice = in.nextInt();
+ if(!cowList.get(choice).getMilk())
+ System.out.println("It can't be milked.");
+
+ case 4:
+ System.out.println("Please input ID.");
+ if (in.hasNextInt()==false) {
+ System.out.println("error input");
+ System.out.println("---------"+in.next()+"++++++++++++++");
+// in.close();
+ continue;
+ }
+ choice = in.nextInt();
+ if(!chookList.get(choice).getEgg())
+ System.out.println("It have not egg.");
+ case 5:
+ System.out.println("Please input ID.");
+ if (in.hasNextInt()==false) {
+ System.out.println("error input");
+ System.out.println("---------"+in.next()+"++++++++++++++");
+// in.close();
+ continue;
+ }
+ choice = in.nextInt();
+ if(!sheepList.get(choice).getWool())
+ System.out.println("It can't be wooled.");
+ }
+ System.out.println("Get ahead");
+ break;
+ case 4:
+ System.out.println("\n Pig state(0:young;1:mature):\n");
+ for(Pig A : pigList) {
+ System.out.println("pig:ID "+A.getId()+" state: "+A.nowstate.getState());
+ }
+ System.out.println("\n Ox state(0:young;1:mature):\n");
+ for(Ox A : oxList) {
+ System.out.println("Ox:ID "+A.getId()+" state: "+A.nowstate.getState());
+ }
+ System.out.println("\n cow state(0:young;1:mature):\n");
+ for(Cow A : cowList) {
+ System.out.println("cow:ID "+A.getId()+" state: "+A.nowstate.getState());
+ }
+ System.out.println("\n chook(0:young;1:mature):\n");
+ for(Chook A : chookList) {
+ System.out.println("chook:ID "+A.getId()+" state: "+A.nowstate.getState());
+ }
+ System.out.println("\n sheep(0:young;1:mature):\n");
+ for(Sheep A : sheepList) {
+ System.out.println("sheep:ID "+A.getId()+" state: "+A.nowstate.getState());
+ }
+ break;
+ default:
+ System.out.println("wrong input");
+ break;
+ }
+ } while (loop);
+
+ System.out.println("-------------EXIT-------------");
+ }
+ public void feedandDrink() {
+ int t=1;
+ System.out.println("Please choose livestock species");
+ System.out.println("1.pig ");
+ System.out.println("2.ox ");
+ System.out.println("3.cow ");
+ System.out.println("4.chook ");
+ System.out.println("5.sheep");
+ int choice = in.nextInt();
+ System.out.println("Please import livestock ID");
+ switch (choice) {
+ case 1:
+ choice = in.nextInt();
+ for(int i = 0;i < pigList.size(); i ++){
+ if(pigList.get(i).getId()==choice) {
+ System.out.println("drink or feed");
+ System.out.println("1.feed");
+ System.out.println("2.drink");
+ choice= in.nextInt();
+ if(choice==1)
+ {
+ pigList.get(i).nowstate.Feed();
+ //System.out.println(pigList.get(i).nowstate.getState());
+ System.out.println("feed success");
+ }
+ else if(choice==2)
+ {
+ pigList.get(i).nowstate.Drink();;
+ System.out.println("drink success");
+ }
+ t=0;
+ break;
+ }
+ }
+ if(t==1)
+ System.out.println("The animal does not exist or is dead.");
+ break;
+ case 2:
+ choice = in.nextInt();
+ for(int i = 0;i < oxList.size(); i ++){
+ if(oxList.get(i).getId()==choice) {
+ System.out.println("drink or feed");
+ System.out.println("1.feed");
+ System.out.println("2.drink");
+ choice= in.nextInt();
+ if(choice==1)
+ {
+ oxList.get(i).nowstate.Feed();
+ System.out.println("feed success");
+ }
+ else if(choice==2)
+ {
+ oxList.get(i).nowstate.Drink();;
+ System.out.println("drink success");
+ }
+ t=0;
+ break;
+ }
+ }
+ if(t==1)
+ System.out.println("The animal does not exist or is dead.");
+ break;
+ case 3:
+ choice = in.nextInt();
+ for(int i = 0;i < cowList.size(); i ++){
+ if(cowList.get(i).getId()==choice) {
+ System.out.println("drink or feed");
+ System.out.println("1.feed");
+ System.out.println("2.drink");
+ choice= in.nextInt();
+ if(choice==1)
+ {
+ cowList.get(i).nowstate.Feed();
+ System.out.println("feed success");
+ }
+ else if(choice==2)
+ {
+ cowList.get(i).nowstate.Drink();;
+ System.out.println("drink success");
+ }
+ t=0;
+ break;
+ }
+ }
+ if(t==1)
+ System.out.println("The animal does not exist or is dead.");
+ break;
+ case 4:
+ choice = in.nextInt();
+ for(int i = 0;i < chookList.size(); i ++){
+ if(chookList.get(i).getId()==choice) {
+ System.out.println("drink or feed");
+ System.out.println("1.feed");
+ System.out.println("2.drink");
+ choice= in.nextInt();
+ if(choice==1)
+ {
+ chookList.get(i).nowstate.Feed();
+ System.out.println("feed success");
+ }
+ else if(choice==2)
+ {
+ chookList.get(i).nowstate.Drink();;
+ System.out.println("drink success");
+ }
+ t=0;
+ break;
+ }
+ }
+ if(t==1)
+ System.out.println("The animal does not exist or is dead.");
+ break;
+ case 5:
+ choice = in.nextInt();
+ for(int i = 0;i < sheepList.size(); i ++){
+ if(sheepList.get(i).getId()==choice) {
+ System.out.println("drink or feed");
+ System.out.println("1.feed");
+ System.out.println("2.drink");
+ choice= in.nextInt();
+ if(choice==1)
+ {
+ sheepList.get(i).nowstate.Feed();
+ System.out.println("feed success");
+ }
+ else if(choice==2)
+ {
+ sheepList.get(i).nowstate.Drink();;
+ System.out.println("drink success");
+ }
+ t=0;
+ break;
+ }
+ }
+ if(t==1)
+ System.out.println("The animal does not exist or is dead.");
+ break;
+ default:
+ System.out.println("error input");
+ break;
+
+ }
+
+ }
+
+}
diff --git a/src/test/Main.java b/src/test/Main.java
new file mode 100644
index 0000000..9b2c215
--- /dev/null
+++ b/src/test/Main.java
@@ -0,0 +1,15 @@
+package test;
+
+public class Main {
+
+ public static void main(String[] args) {
+ // TODO Auto-generated method stub
+ User user = new User();
+ user.init();
+
+ user.Menu();
+
+
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/User.java b/src/test/User.java
new file mode 100644
index 0000000..f801fd1
--- /dev/null
+++ b/src/test/User.java
@@ -0,0 +1,60 @@
+package test;
+
+import java.util.Scanner;
+import buy.*;
+public class User {
+ public void init() {
+ System.out.println("welcome to JiaDing Farm");
+
+ }
+ public void Menu() {
+ boolean loop = true;
+ ResList.Instance();
+ do {
+ System.out.println("1.Go to Farm Land");
+ System.out.println("2.Buy");
+ System.out.println("3.Weather ");
+ System.out.println("4.Sell and Deal ");
+ System.out.println("5.go to livestock farm ");
+ System.out.println("6. Exit");
+ Scanner in = new Scanner(System.in);
+ if (in.hasNextInt()==false) {
+ System.out.println("wrong input");
+ in.next();
+ continue;
+ }
+ int choice = in.nextInt();
+ switch (choice) {
+ case 1:
+ new FarmUse(in).menu();
+ break;
+ case 2:
+ new BuyUse(in).menu();
+ break;
+
+ case 3:
+ new WeatherUse(in).menu();
+ break;
+
+ case 4:
+ new DealAndSellUse(in).menu();
+ break;
+
+ case 5:
+ new LivestockUse(in).menu();
+ break;
+ case 6:
+ loop = false;
+ break;
+ default:
+ System.out.println("wrong input");
+ break;
+ }
+
+ } while (loop);
+
+ System.out.println("-------------EXIT-------------");
+ }
+
+
+}
diff --git a/src/test/WeatherUse.java b/src/test/WeatherUse.java
new file mode 100644
index 0000000..9c197cc
--- /dev/null
+++ b/src/test/WeatherUse.java
@@ -0,0 +1,59 @@
+package test;
+
+import weather.*;
+import java.util.Scanner;
+import java.util.ArrayList;
+public class WeatherUse {
+ private Scanner in;
+ public WeatherUse(Scanner in)
+ {
+ this.in = in;
+ }
+ public void menu()
+ {
+ boolean loop = true;
+ ArrayListstate=new ArrayList();
+ do
+ {
+ System.out.println("please select the weather you want:");
+ System.out.println("1.Sunny");
+ System.out.println("2.Windy");
+ System.out.println("3.Rainy");
+ System.out.println("4.Get the latest weather information");
+ System.out.println("5.exit");
+ if (in.hasNextInt()==false) {
+ System.out.println("Wrong Input");
+ continue;
+ }
+ int choice = in.nextInt();
+ switch(choice)
+ {
+ case 1:
+ state.add(Wstate.findandclone(Weather.sunny));
+ System.out.println("It's sunny now");
+ break;
+ case 2:
+ state.add(Wstate.findandclone(Weather.windy));
+ System.out.println("It's windy now");
+ break;
+ case 3:
+ state.add(Wstate.findandclone(Weather.rainy));
+ System.out.println("It's rainy now");
+ break;
+ case 4:
+ if(state.isEmpty())
+ System.out.println("you havn't chosen any weather");
+ else
+ Wstate.array.get(0).accept(new Listvisitor());
+ break;
+ case 5:
+ loop=false;
+ break;
+ default:
+ System.out.println("Wrong Input");
+ break;
+ }
+ }while(loop);
+ }
+
+}
diff --git a/src/thing/.gitignore b/src/thing/.gitignore
new file mode 100644
index 0000000..a87e874
--- /dev/null
+++ b/src/thing/.gitignore
@@ -0,0 +1,25 @@
+/AppleGoods.class
+/BeefGoods.class
+/CabbageGoods.class
+/Carrier.class
+/CarrotGoods.class
+/ChickenGoods.class
+/CornGoods.class
+/EggGoods.class
+/FertilizedButNotIrrigated.class
+/FieldContainer.class
+/Goods.class
+/GoodsCache.class
+/IrrigatedButNotFertilizedState.class
+/Land.class
+/LivestockState.class
+/Matured.class
+/MilkGoods.class
+/PearGoods.class
+/PlantState.class
+/PorkGoods.class
+/Product.class
+/ProductType.class
+/Raw.class
+/Seller.class
+/WoolGoods.class
diff --git a/src/thing/ChickenGoods.java b/src/thing/ChickenGoods.java
new file mode 100644
index 0000000..015b65f
--- /dev/null
+++ b/src/thing/ChickenGoods.java
@@ -0,0 +1,10 @@
+package thing;
+
+
+public class ChickenGoods extends Goods {
+
+ public ChickenGoods() {
+ setGoodsType("ChickenGoods");
+ }
+
+}
diff --git a/src/thing/CornGoods.java b/src/thing/CornGoods.java
new file mode 100644
index 0000000..e391fd2
--- /dev/null
+++ b/src/thing/CornGoods.java
@@ -0,0 +1,9 @@
+package thing;
+
+public class CornGoods extends Goods {
+
+ public CornGoods() {
+ setGoodsType("CornGoods");
+ }
+
+}
diff --git a/src/thing/FertilizedButNotIrrigated.java b/src/thing/FertilizedButNotIrrigated.java
index 8ead21d..f6f3d90 100644
--- a/src/thing/FertilizedButNotIrrigated.java
+++ b/src/thing/FertilizedButNotIrrigated.java
@@ -22,7 +22,7 @@ public void showState() {
@Override
public void fertilized(Plant plant) {
// TODO Auto-generated method stub
- System.out.println("Ҫʩ");
+ System.out.println("no need for fertilization");
// plant.changeState(FertilizedButNotIrrigated.getInstance());
}
@@ -34,7 +34,7 @@ public void irrigated(Plant plant) {
@Override
public boolean harvest(Plant plant) {
// TODO Auto-generated method stub
- System.out.println("ջ");
+ System.out.println("cannot harvest yet");
return false;
}
diff --git a/src/thing/FieldContainer.java b/src/thing/FieldContainer.java
index 8594b8b..2ea9315 100644
--- a/src/thing/FieldContainer.java
+++ b/src/thing/FieldContainer.java
@@ -28,14 +28,25 @@ public static FieldContainer getInstance() {
}
return instance;
}
+ /**
+ *
+ * @return list of cultivatedLands
+ */
public ArrayList getLands(){
return cultivatedLands;
}
+ /**
+ *
+ * @return list of uncoltivatedLands
+ */
+ public ArrayList getEmptyLands(){
+ return uncultivatedLands;
+ }
/**
* һ
*/
public void makeNewLand() {
- int num = cultivatedLands.size()+uncultivatedLands.size()+1;
+ int num = cultivatedLands.size()+uncultivatedLands.size();
uncultivatedLands.add(new Land(num));
System.out.println("Land"+num+"created!");
diff --git a/src/thing/GoodsCache.java b/src/thing/GoodsCache.java
index 7c0ad02..25f7050 100644
--- a/src/thing/GoodsCache.java
+++ b/src/thing/GoodsCache.java
@@ -15,39 +15,39 @@ public static Goods getShape(int id) {
public static void loadCache() {
CabbageGoods cabbageGoods = new CabbageGoods();
- cabbageGoods.setId(1);
+ cabbageGoods.setId(0);
shapeMap.put(cabbageGoods.getId(),cabbageGoods);
CarrotGoods carrotGoods = new CarrotGoods();
- carrotGoods.setId(2);
+ carrotGoods.setId(1);
shapeMap.put(carrotGoods.getId(),carrotGoods);
AppleGoods appleGoods = new AppleGoods();
- appleGoods.setId(3);
+ appleGoods.setId(2);
shapeMap.put(appleGoods.getId(),appleGoods);
PearGoods pearGoods = new PearGoods();
- pearGoods.setId(4);
+ pearGoods.setId(3);
shapeMap.put(pearGoods.getId(),pearGoods);
BeefGoods beefGoods = new BeefGoods();
- beefGoods.setId(5);
+ beefGoods.setId(4);
shapeMap.put(beefGoods.getId(),beefGoods);
PorkGoods porkGoods = new PorkGoods();
- porkGoods.setId(6);
+ porkGoods.setId(5);
shapeMap.put(porkGoods.getId(),porkGoods);
EggGoods eggGoods = new EggGoods();
- eggGoods.setId(7);
+ eggGoods.setId(6);
shapeMap.put(eggGoods.getId(),eggGoods);
WoolGoods woolGoods = new WoolGoods();
- woolGoods.setId(8);
+ woolGoods.setId(7);
shapeMap.put(woolGoods.getId(),woolGoods);
MilkGoods milkGoods = new MilkGoods();
- milkGoods.setId(9);
+ milkGoods.setId(8);
shapeMap.put(milkGoods.getId(),milkGoods);
diff --git a/src/thing/IrrigatedButNotFertilizedState.java b/src/thing/IrrigatedButNotFertilizedState.java
index a7f419c..b15c665 100644
--- a/src/thing/IrrigatedButNotFertilizedState.java
+++ b/src/thing/IrrigatedButNotFertilizedState.java
@@ -33,13 +33,13 @@ public void fertilized(Plant plant) {
@Override
public void irrigated(Plant plant) {
// TODO Auto-generated method stub
- System.out.println("Ҫˮ");
+ System.out.println("no need for irrigation");
// plant.changeState(FertilizedButNotIrrigated.getInstance());
}
@Override
public boolean harvest(Plant plant) {
// TODO Auto-generated method stub
- System.out.println("ջ");
+ System.out.println("cannot harvest yet");
return false;
}
diff --git a/src/thing/Land.java b/src/thing/Land.java
index eccf7b1..107dfeb 100644
--- a/src/thing/Land.java
+++ b/src/thing/Land.java
@@ -30,5 +30,12 @@ public void harvest() {
remove();
}
}
+ public void showState() {
+ System.out.print("ֲ");
+ plant.showType();
+ System.out.print(" ״̬");
+ plant.showPlantState();
+ System.out.print("\n");
+ }
}
diff --git a/src/thing/LivestockState.java b/src/thing/LivestockState.java
index 8697619..ce71fe0 100644
--- a/src/thing/LivestockState.java
+++ b/src/thing/LivestockState.java
@@ -1,6 +1,6 @@
package thing;
-import livestock.Livestock;
+import livestock.*;
import buy.ResList;
import buy.ResList.s_type;
public class LivestockState {
@@ -29,7 +29,7 @@ public void setFeedTime() {
public int getState() {
return this.sta;
}
- //ˮ
+ //��ˮ
public void setState(int i) {
this.sta=i;
}
@@ -42,7 +42,6 @@ public void Drink() {
}
//ιʳ
public void Feed() {
- ResList.Instance().s_list[s_type.feed.id()]--;
this.FeedTime++;
if(this.getState()==0&&this.DrinkTime>=3&&this.FeedTime>=3)
{
diff --git a/src/thing/Matured.java b/src/thing/Matured.java
index 8a1ced9..ae04552 100644
--- a/src/thing/Matured.java
+++ b/src/thing/Matured.java
@@ -22,17 +22,17 @@ public void showState() {
@Override
public void fertilized(Plant plant) {
// TODO Auto-generated method stub
- System.out.println("Ѿջ");
+ System.out.println("Already Matured");
}
@Override
public void irrigated(Plant plant) {
// TODO Auto-generated method stub
- System.out.println("Ѿջ");
+ System.out.println("Already Matured");
}
@Override
public boolean harvest(Plant plant) {
// TODO Auto-generated method stub
-
+ System.out.println("harvest!");
return true;
}
diff --git a/src/thing/Product.java b/src/thing/Product.java
index e0dd55b..a191308 100644
--- a/src/thing/Product.java
+++ b/src/thing/Product.java
@@ -10,15 +10,15 @@ public class Product {
private static Hashtable shapeMap;
private static void initHashtable() {
shapeMap=new Hashtable();
- shapeMap.put(1,"CABBAGE");
- shapeMap.put(2,"CARROT");
- shapeMap.put(3,"APPLE");
- shapeMap.put(4,"PEAR");
- shapeMap.put(5,"BEEF");
- shapeMap.put(6,"PORK");
- shapeMap.put(7,"EGG");
- shapeMap.put(8,"WOOL");
- shapeMap.put(9,"MILK");
+ shapeMap.put(0,"CABBAGE");
+ shapeMap.put(1,"CARROT");
+ shapeMap.put(2,"APPLE");
+ shapeMap.put(3,"PEAR");
+ shapeMap.put(4,"BEEF");
+ shapeMap.put(5,"PORK");
+ shapeMap.put(6,"EGG");
+ shapeMap.put(7,"WOOL");
+ shapeMap.put(8,"MILK");
}
public Product(ProductType ptype,int num) {
@@ -29,7 +29,7 @@ public Product(ProductType ptype,int num) {
number=1;
}
public Product() {
-
+ initHashtable();
}
public String getName(int catalog) {
diff --git a/src/thing/Raw.java b/src/thing/Raw.java
index 90d8914..57d6c35 100644
--- a/src/thing/Raw.java
+++ b/src/thing/Raw.java
@@ -40,7 +40,7 @@ public void irrigated(Plant plant) {
@Override
public boolean harvest(Plant plant) {
// TODO Auto-generated method stub
- System.out.println("ջ");
+ System.out.println("cannot harvest yet");
return false;
}
diff --git a/src/thing/Seller.java b/src/thing/Seller.java
new file mode 100644
index 0000000..e72917e
--- /dev/null
+++ b/src/thing/Seller.java
@@ -0,0 +1,9 @@
+package thing;
+
+import construction.Sale;
+
+public class Seller {
+ public void sellGoods(Goods goods) {
+ Sale.sale(goods);
+ }
+}
diff --git a/src/weather/.gitignore b/src/weather/.gitignore
new file mode 100644
index 0000000..0a0c039
--- /dev/null
+++ b/src/weather/.gitignore
@@ -0,0 +1,9 @@
+/Acceptor.class
+/Listvisitor.class
+/Rainy.class
+/Run.class
+/Sunny.class
+/Visitor.class
+/Weather.class
+/Windy.class
+/Wstate.class
diff --git a/src/weather/Acceptor.java b/src/weather/Acceptor.java
new file mode 100644
index 0000000..35350d0
--- /dev/null
+++ b/src/weather/Acceptor.java
@@ -0,0 +1,5 @@
+package weather;
+
+public interface Acceptor {
+public abstract void accept(Visitor v);
+}
diff --git a/src/weather/Listvisitor.java b/src/weather/Listvisitor.java
new file mode 100644
index 0000000..d5d0789
--- /dev/null
+++ b/src/weather/Listvisitor.java
@@ -0,0 +1,17 @@
+package weather;
+import java.util.Iterator;
+public class Listvisitor extends Visitor {
+
+ @Override
+ public void visit(Wstate state) {
+ // TODO Auto-generated method stub
+ //System.out.println(state.getName());
+ Iterator it=state.iterator();
+ while(it.hasNext())
+ {
+ Wstate s=(Wstate)it.next();
+ System.out.println("It's "+s.getName()+" at time"+s.returnid());
+ }
+ }
+
+}
diff --git a/src/weather/Rainy.java b/src/weather/Rainy.java
new file mode 100644
index 0000000..4220d66
--- /dev/null
+++ b/src/weather/Rainy.java
@@ -0,0 +1,61 @@
+package weather;
+
+public class Rainy extends Wstate{
+ private int _id;
+ private static int _count=1;
+ private static Rainy _freestate;
+ public Rainy() {addPrototype(this);Wstate.array.add(this);num++;_id=num;};
+
+ protected Rainy(int i) {
+ // TODO Auto-generated constructor stub
+ num++;_id=num;
+ }
+
+ @Override
+ protected Weather returnType() {
+ // TODO Auto-generated method stub
+ return Weather.rainy;
+ }
+
+ //protected void finalize() {_count--;};
+
+ @Override
+ public Wstate copy() {
+ // TODO Auto-generated method stub
+ Rainy s=new Rainy(1);
+ Wstate.array.add(s);
+ return s;
+ }
+
+ @Override
+ public void work() {
+ // TODO Auto-generated method stub
+ System.out.println("It's rainy now!");
+ }
+
+ @Override
+ public void accept(Visitor v) {
+ // TODO Auto-generated method stub
+ v.visit(this);
+ }
+
+ @Override
+ public String getName() {
+ // TODO Auto-generated method stub
+ String name="rainy";
+ return name;
+ }
+
+ @Override
+ public int getNumber() {
+ // TODO Auto-generated method stub
+ return _count;
+ }
+
+ @Override
+ public int returnid() {
+ // TODO Auto-generated method stub
+ return _id;
+ }
+
+}
diff --git a/src/weather/Run.java b/src/weather/Run.java
new file mode 100644
index 0000000..f0b8a03
--- /dev/null
+++ b/src/weather/Run.java
@@ -0,0 +1,25 @@
+package weather;
+
+import java.util.ArrayList;
+public class Run {
+public static void main(String[]args)
+{
+ ArrayListinput=new ArrayList();
+ input.add(Weather.sunny);
+ input.add(Weather.rainy);
+ input.add(Weather.windy);
+ input.add(Weather.sunny);
+ input.add(Weather.rainy);
+ input.add(Weather.windy);
+ input.add(Weather.windy);
+ input.add(Weather.sunny);
+ input.add(Weather.rainy);
+ int num_states=input.size();
+ Wstate[]state=new Wstate[num_states];
+ for(int i=0;iarray=new Vector();
+ public static int num=0;
+ public abstract int returnid();
+ protected abstract Weather returnType();
+ protected static void addPrototype(Wstate state)
+ {
+ _states[_nextslot++]=state;
+ }
+ protected abstract Wstate copy();
+ public static Wstate findandclone(Weather s)
+ {
+ for(int i=0;i<_nextslot;i++)
+ if(_states[i].returnType()==s)
+ return _states[i].copy();
+ if(s==Weather.sunny)
+ return new Sunny();
+ else if(s==Weather.rainy)
+ return new Rainy();
+ else
+ return new Windy();
+ }
+ public abstract void work();
+ public abstract String getName();//ȡ
+ public abstract int getNumber();//ȡ
+ public void accept(Visitor v)
+ {
+ v.visit(this);
+ }
+ public Iterator iterator()
+ {
+ return array.iterator();
+ }
+}
diff --git a/src/worker/.gitignore b/src/worker/.gitignore
new file mode 100644
index 0000000..49a0d9c
--- /dev/null
+++ b/src/worker/.gitignore
@@ -0,0 +1,14 @@
+/Command.class
+/Controller.class
+/FarmMaster.class
+/FertilizeCommand.class
+/Fertilizeman.class
+/HarvestCommand.class
+/Harvestman.class
+/IrrigateCommand.class
+/Irrigateman.class
+/Manager.class
+/Seller.class
+/Worker.class
+/WorkerList.class
+/CommandDispatcher.class
diff --git a/src/worker/Command.java b/src/worker/Command.java
new file mode 100644
index 0000000..95e48c8
--- /dev/null
+++ b/src/worker/Command.java
@@ -0,0 +1,12 @@
+package worker;
+
+public abstract class Command {
+ abstract public boolean execute(Worker worker);
+ int number;
+ public int getnumber() {
+ return number;
+ }
+ public void setnumber(int number) {
+ this.number=number;
+ }
+}
diff --git a/src/worker/CommandDispatcher.java b/src/worker/CommandDispatcher.java
new file mode 100644
index 0000000..02aa69c
--- /dev/null
+++ b/src/worker/CommandDispatcher.java
@@ -0,0 +1,5 @@
+package worker;
+
+public abstract class CommandDispatcher {
+ public abstract void call(Command command);
+}
diff --git a/src/worker/Controller.java b/src/worker/Controller.java
new file mode 100644
index 0000000..de65757
--- /dev/null
+++ b/src/worker/Controller.java
@@ -0,0 +1,5 @@
+package worker;
+
+public class Controller {
+
+}
diff --git a/src/worker/FarmMaster.java b/src/worker/FarmMaster.java
new file mode 100644
index 0000000..5697377
--- /dev/null
+++ b/src/worker/FarmMaster.java
@@ -0,0 +1,31 @@
+package worker;
+
+import thing.FieldContainer;
+
+public class FarmMaster {
+ private FarmMaster() {}
+ private static FarmMaster instance = new FarmMaster();
+ private Manager manager = new Manager();
+ public static FarmMaster getInstance() {
+ return instance;
+ }
+ public void setManager(Manager manager) {
+ this.manager = manager;
+ }
+ //ȥ
+ public void call(Command command) {
+ manager.call(command);
+ }
+ //ʩ
+ public void fertilize(int landID) {
+ FieldContainer.getInstance().fertilize(landID);
+ }
+ //
+ public void irrigate(int landID) {
+ FieldContainer.getInstance().irrigate(landID);
+ }
+ //ջ
+ public void harvest(int landID) {
+ FieldContainer.getInstance().harvest(landID);
+ }
+}
diff --git a/src/worker/FertilizeCommand.java b/src/worker/FertilizeCommand.java
new file mode 100644
index 0000000..b355025
--- /dev/null
+++ b/src/worker/FertilizeCommand.java
@@ -0,0 +1,14 @@
+package worker;
+
+public class FertilizeCommand extends Command{
+
+
+ public boolean execute(Worker a) {
+ if(!a.type.equals("harvest")&&!a.type.equals("irrigate")) {
+ a.action(number);
+ return true;
+ }
+ return false;
+ }
+
+}
diff --git a/src/worker/Fertilizeman.java b/src/worker/Fertilizeman.java
new file mode 100644
index 0000000..f5a906f
--- /dev/null
+++ b/src/worker/Fertilizeman.java
@@ -0,0 +1,13 @@
+package worker;
+
+import thing.FieldContainer;
+
+public class Fertilizeman extends Worker {
+ Fertilizeman(){this.type="fertilize";};
+ @Override
+ public void action(int id) {
+ // TODO Auto-generated method stub
+ FieldContainer.getInstance().fertilize(id);
+ }
+
+}
diff --git a/src/worker/HarvestCommand.java b/src/worker/HarvestCommand.java
new file mode 100644
index 0000000..59fe64d
--- /dev/null
+++ b/src/worker/HarvestCommand.java
@@ -0,0 +1,11 @@
+package worker;
+
+public class HarvestCommand extends Command{
+ public boolean execute(Worker a) {
+ if(!a.type.equals("fertilize")&&!a.type.equals("irrigate")) {
+ a.action(number);
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/src/worker/Harvestman.java b/src/worker/Harvestman.java
new file mode 100644
index 0000000..95eb45a
--- /dev/null
+++ b/src/worker/Harvestman.java
@@ -0,0 +1,13 @@
+package worker;
+
+import thing.FieldContainer;
+
+public class Harvestman extends Worker {
+ Harvestman(){this.type="harvest";};
+ @Override
+ public void action(int id) {
+ // TODO Auto-generated method stub
+ FieldContainer.getInstance().harvest(id);
+ }
+
+}
diff --git a/src/worker/IrrigateCommand.java b/src/worker/IrrigateCommand.java
new file mode 100644
index 0000000..b5c1426
--- /dev/null
+++ b/src/worker/IrrigateCommand.java
@@ -0,0 +1,12 @@
+package worker;
+
+public class IrrigateCommand extends Command{
+ public boolean execute(Worker a) {
+ if(!a.type.equals("fertilize")&&!a.type.equals("harvest")) {
+ a.action(number);
+ return true;
+ }
+ return false;
+ }
+
+}
diff --git a/src/worker/Irrigateman.java b/src/worker/Irrigateman.java
new file mode 100644
index 0000000..086920a
--- /dev/null
+++ b/src/worker/Irrigateman.java
@@ -0,0 +1,14 @@
+package worker;
+
+import thing.FieldContainer;
+
+public class Irrigateman extends Worker{
+ Irrigateman(){this.type="irrigate";};
+
+
+ @Override
+ public void action(int id) {
+ // TODO Auto-generated method stub
+ FieldContainer.getInstance().irrigate(id);
+ }
+}
diff --git a/src/worker/Manager.java b/src/worker/Manager.java
new file mode 100644
index 0000000..d59eed4
--- /dev/null
+++ b/src/worker/Manager.java
@@ -0,0 +1,25 @@
+package worker;
+
+
+
+public class Manager {
+ protected Manager() {}
+ private static Manager instance = new Manager();
+ public static Manager getInstance() {
+ return instance;
+ }
+
+ //ȥ
+ public void call(Command command) {
+ WorkerList workerlist = WorkerList.getInstance();
+ for(Worker worker: workerlist.workList) {
+ if(command.execute(worker)) {
+ break;
+ }
+ }
+ }
+
+ public SuperManager LevelUp() {
+ return SuperManager.getInstance(this);
+ }
+}
diff --git a/src/worker/Seller.java b/src/worker/Seller.java
new file mode 100644
index 0000000..e627d6e
--- /dev/null
+++ b/src/worker/Seller.java
@@ -0,0 +1,10 @@
+package worker;
+
+import construction.Sale;
+import thing.Goods;
+
+public class Seller {
+ public void sell(Goods goods) {
+ Sale.sale(goods);
+ }
+}
diff --git a/src/worker/SuperManager.java b/src/worker/SuperManager.java
new file mode 100644
index 0000000..3c2fffe
--- /dev/null
+++ b/src/worker/SuperManager.java
@@ -0,0 +1,37 @@
+package worker;
+
+import machine.MachineFertilization;
+import machine.MachineHarvest;
+import machine.MachineIrrigation;
+import machine.MachineSchedule;
+import machine.WorkAdapter;
+
+public class SuperManager extends Manager {
+ private static Manager instance;
+ private SuperManager(Manager manager) {
+ // TODO Auto-generated constructor stub
+ instance = manager;
+ }
+ public static SuperManager getInstance(Manager manager) {
+
+ return new SuperManager(manager);
+ }
+ @Override
+ public void call(Command command) {
+ WorkerList workerlist = WorkerList.getInstance();
+ WorkAdapter workAdapter = new WorkAdapter(new MachineSchedule());
+ workAdapter.machineSchedule.setStrategy(new MachineIrrigation());
+ WorkAdapter workAdapter2 = new WorkAdapter(new MachineSchedule());
+ workAdapter.machineSchedule.setStrategy(new MachineFertilization());
+ WorkAdapter workAdapter3 = new WorkAdapter(new MachineSchedule());
+ workAdapter.machineSchedule.setStrategy(new MachineHarvest());
+ workerlist.add(workAdapter);
+ workerlist.add(workAdapter2);
+ workerlist.add(workAdapter3);
+ instance.call(command);
+ workerlist.remove(workAdapter);
+ workerlist.remove(workAdapter2);
+ workerlist.remove(workAdapter3);
+
+ }
+}
diff --git a/src/worker/Worker.java b/src/worker/Worker.java
new file mode 100644
index 0000000..df3a61d
--- /dev/null
+++ b/src/worker/Worker.java
@@ -0,0 +1,11 @@
+package worker;
+
+
+public abstract class Worker {
+ //Ա
+ protected String type;
+ public abstract void action(int id);
+
+
+ }
+
diff --git a/src/worker/WorkerFactory.java b/src/worker/WorkerFactory.java
new file mode 100644
index 0000000..69275d5
--- /dev/null
+++ b/src/worker/WorkerFactory.java
@@ -0,0 +1,23 @@
+package worker;
+
+import machine.MachineSchedule;
+import machine.WorkAdapter;
+
+public class WorkerFactory {
+ public static Worker createNormalWorker(int type) {
+ switch (type) {
+ case 1:
+ return new Fertilizeman();
+ case 2:
+ return new Irrigateman();
+ case 3:
+ return new Harvestman();
+ default:
+ break;
+ }
+ return null;
+ }
+ public static Worker createMachine() {
+ return new WorkAdapter(new MachineSchedule());
+ }
+}
diff --git a/src/worker/WorkerList.java b/src/worker/WorkerList.java
new file mode 100644
index 0000000..31335c6
--- /dev/null
+++ b/src/worker/WorkerList.java
@@ -0,0 +1,28 @@
+package worker;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.management.InstanceAlreadyExistsException;
+public class WorkerList {
+ public List workList = new ArrayList();
+ private static WorkerList instance;
+ public static WorkerList getInstance() {
+ if (instance == null) {
+ instance = new WorkerList();
+ }
+ return instance;
+ }
+ private WorkerList(){
+ //Աб
+ workList.add(new Harvestman());
+ workList.add(new Fertilizeman());
+ workList.add(new Irrigateman());
+ }
+ public boolean remove(Worker worker) {
+ return workList.remove(worker);
+ }
+ public boolean add(Worker worker) {
+ return workList.add(worker);
+ }
+}