File tree Expand file tree Collapse file tree 9 files changed +195
-0
lines changed Expand file tree Collapse file tree 9 files changed +195
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+ <classpath >
3
+ <classpathentry kind =" src" path =" src" />
4
+ <classpathentry kind =" con" path =" org.eclipse.jdt.launching.JRE_CONTAINER" />
5
+ <classpathentry kind =" output" path =" bin" />
6
+ </classpath >
Original file line number Diff line number Diff line change
1
+ bin /
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+ <projectDescription >
3
+ <name >Miam</name >
4
+ <comment ></comment >
5
+ <projects >
6
+ </projects >
7
+ <buildSpec >
8
+ <buildCommand >
9
+ <name >org.eclipse.jdt.core.javabuilder</name >
10
+ <arguments >
11
+ </arguments >
12
+ </buildCommand >
13
+ </buildSpec >
14
+ <natures >
15
+ <nature >org.eclipse.jdt.core.javanature</nature >
16
+ </natures >
17
+ </projectDescription >
Original file line number Diff line number Diff line change
1
+ import my .stomach .Stomach ;
2
+
3
+ /**
4
+ * @author pteyssier
5
+ *
6
+ */
7
+ public class Main {
8
+
9
+ /**
10
+ * @param args
11
+ */
12
+ public static void main (String [] args ) {
13
+ Stomach stomach = new Stomach ();
14
+ System .out .println (stomach );
15
+ }
16
+
17
+ }
Original file line number Diff line number Diff line change
1
+ package my .food ;
2
+
3
+ import java .util .ArrayList ;
4
+ import java .util .List ;
5
+
6
+
7
+ public class ChaShaoBao implements Food {
8
+
9
+ List <String > ingredients = new ArrayList <String >();
10
+
11
+ /* Exercise 1: implement Constructor */
12
+
13
+ @ Override
14
+ public List <String > getIngredients () {
15
+ return ingredients ;
16
+ }
17
+
18
+ @ Override
19
+ public String getCountryOrigin () {
20
+ // TODO Auto-generated method stub
21
+ return null ;
22
+ }
23
+
24
+ @ Override
25
+ public Integer getCalory () {
26
+ // TODO Auto-generated method stub
27
+ return null ;
28
+ }
29
+
30
+ }
Original file line number Diff line number Diff line change
1
+ package my .food ;
2
+
3
+ import java .util .ArrayList ;
4
+ import java .util .List ;
5
+
6
+ public class DanDanMian implements Food {
7
+ List <String > ingredients = new ArrayList <String >();
8
+
9
+ /* Exercise 1: implement Constructor */
10
+
11
+ @ Override
12
+ public List <String > getIngredients () {
13
+ return ingredients ;
14
+ }
15
+
16
+ @ Override
17
+ public String getCountryOrigin () {
18
+ // TODO Auto-generated method stub
19
+ return null ;
20
+ }
21
+
22
+ @ Override
23
+ public Integer getCalory () {
24
+ // TODO Auto-generated method stub
25
+ return null ;
26
+ }
27
+
28
+ }
Original file line number Diff line number Diff line change
1
+ package my .food ;
2
+
3
+ import java .util .List ;
4
+
5
+ /**
6
+ * @author pteyssier
7
+ *
8
+ */
9
+ public interface Food {
10
+
11
+ public List <String > getIngredients ();
12
+
13
+ public String getCountryOrigin ();
14
+
15
+ /* Exercise 4 */
16
+ public Integer getCalory ();
17
+
18
+ }
Original file line number Diff line number Diff line change
1
+ package my .food ;
2
+
3
+ import java .util .ArrayList ;
4
+ import java .util .List ;
5
+
6
+ /*
7
+ * Class Food sample Pizza :
8
+ * do not modify!
9
+ * do not feed after midnight!
10
+ * */
11
+ public class Pizza implements Food {
12
+
13
+ List <String > ingredients = new ArrayList <String >();
14
+
15
+ public Pizza () {
16
+ ingredients .add ("ham" );
17
+ ingredients .add ("mozzarella" );
18
+ ingredients .add ("tomato" );
19
+ }
20
+
21
+ @ Override
22
+ public List <String > getIngredients () {
23
+ return ingredients ;
24
+ }
25
+
26
+ @ Override
27
+ public String getCountryOrigin () {
28
+ // TODO Auto-generated method stub
29
+ return null ;
30
+ }
31
+
32
+ @ Override
33
+ public Integer getCalory () {
34
+ // TODO Auto-generated method stub
35
+ return null ;
36
+ }
37
+
38
+ }
Original file line number Diff line number Diff line change
1
+ package my .stomach ;
2
+
3
+ import java .util .ArrayList ;
4
+ import java .util .List ;
5
+
6
+ import com .sun .xml .internal .ws .util .StringUtils ;
7
+
8
+ import my .food .ChaShaoBao ;
9
+ import my .food .DanDanMian ;
10
+ import my .food .Food ;
11
+ import my .food .Pizza ;
12
+
13
+ public class Stomach {
14
+
15
+ List <Food > foodsInside = new ArrayList <Food >();
16
+
17
+ public Stomach () {
18
+ foodsInside .add (new Pizza ());
19
+ /* Exercise 2 : add your food */
20
+ }
21
+ @ Override
22
+ public String toString () {
23
+ StringBuilder sb = new StringBuilder ("My stomach contains " + foodsInside .size () + " food(s):\n \n " );
24
+ for (Food food : foodsInside ) {
25
+ sb .append (foodsInside .indexOf (food ) + 1 + ")" );
26
+
27
+ /* Display the name of the food object */
28
+ sb .append (food .getClass ().getSimpleName () + ":" );
29
+ sb .append ("\n " );
30
+
31
+ /* Display the list of ingredients */
32
+ sb .append (food .getIngredients ());
33
+ sb .append ("\n \n " );
34
+
35
+ /* Exercise 3: Display the country of origin see class Country */
36
+
37
+ }
38
+ return sb .toString ();
39
+ }
40
+ }
You can’t perform that action at this time.
0 commit comments