Skip to content

Commit

Permalink
该吃饭了
Browse files Browse the repository at this point in the history
  • Loading branch information
pteyssier committed May 30, 2014
0 parents commit 1ca8fcb
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bin/
17 changes: 17 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Miam</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
17 changes: 17 additions & 0 deletions src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import my.stomach.Stomach;

/**
* @author pteyssier
*
*/
public class Main {

/**
* @param args
*/
public static void main(String[] args) {
Stomach stomach = new Stomach();
System.out.println(stomach);
}

}
30 changes: 30 additions & 0 deletions src/my/food/ChaShaoBao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package my.food;

import java.util.ArrayList;
import java.util.List;


public class ChaShaoBao implements Food {

List<String> ingredients = new ArrayList<String>();

/* Exercise 1: implement Constructor */

@Override
public List<String> getIngredients() {
return ingredients;
}

@Override
public String getCountryOrigin() {
// TODO Auto-generated method stub
return null;
}

@Override
public Integer getCalory() {
// TODO Auto-generated method stub
return null;
}

}
28 changes: 28 additions & 0 deletions src/my/food/DanDanMian.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package my.food;

import java.util.ArrayList;
import java.util.List;

public class DanDanMian implements Food {
List<String> ingredients = new ArrayList<String>();

/* Exercise 1: implement Constructor */

@Override
public List<String> getIngredients() {
return ingredients;
}

@Override
public String getCountryOrigin() {
// TODO Auto-generated method stub
return null;
}

@Override
public Integer getCalory() {
// TODO Auto-generated method stub
return null;
}

}
18 changes: 18 additions & 0 deletions src/my/food/Food.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package my.food;

import java.util.List;

/**
* @author pteyssier
*
*/
public interface Food {

public List<String> getIngredients();

public String getCountryOrigin();

/* Exercise 4 */
public Integer getCalory();

}
38 changes: 38 additions & 0 deletions src/my/food/Pizza.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package my.food;

import java.util.ArrayList;
import java.util.List;

/*
* Class Food sample Pizza :
* do not modify!
* do not feed after midnight!
* */
public class Pizza implements Food {

List<String> ingredients = new ArrayList<String>();

public Pizza() {
ingredients.add("ham");
ingredients.add("mozzarella");
ingredients.add("tomato");
}

@Override
public List<String> getIngredients() {
return ingredients;
}

@Override
public String getCountryOrigin() {
// TODO Auto-generated method stub
return null;
}

@Override
public Integer getCalory() {
// TODO Auto-generated method stub
return null;
}

}
40 changes: 40 additions & 0 deletions src/my/stomach/Stomach.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package my.stomach;

import java.util.ArrayList;
import java.util.List;

import com.sun.xml.internal.ws.util.StringUtils;

import my.food.ChaShaoBao;
import my.food.DanDanMian;
import my.food.Food;
import my.food.Pizza;

public class Stomach {

List<Food> foodsInside = new ArrayList<Food>();

public Stomach() {
foodsInside.add(new Pizza());
/* Exercise 2 : add your food */
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder("My stomach contains " + foodsInside.size() + " food(s):\n\n");
for (Food food : foodsInside) {
sb.append(foodsInside.indexOf(food) + 1 + ")");

/* Display the name of the food object */
sb.append(food.getClass().getSimpleName() + ":");
sb.append("\n");

/* Display the list of ingredients */
sb.append(food.getIngredients());
sb.append("\n\n");

/* Exercise 3: Display the country of origin see class Country */

}
return sb.toString();
}
}

0 comments on commit 1ca8fcb

Please sign in to comment.