Commit 1ca72264da1ab305842ee5f3034f8f8f753aa1c1
1 parent
32676647
Exists in
master
random food
Showing
6 changed files
with
193 additions
and
0 deletions
Show diff stats
@@ -0,0 +1,6 @@ | @@ -0,0 +1,6 @@ | ||
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/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> | ||
5 | + <classpathentry kind="output" path="bin"/> | ||
6 | +</classpath> |
@@ -0,0 +1,17 @@ | @@ -0,0 +1,17 @@ | ||
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<projectDescription> | ||
3 | + <name>FOOD</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> |
@@ -0,0 +1,11 @@ | @@ -0,0 +1,11 @@ | ||
1 | +eclipse.preferences.version=1 | ||
2 | +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
3 | +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 | ||
4 | +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
5 | +org.eclipse.jdt.core.compiler.compliance=1.6 | ||
6 | +org.eclipse.jdt.core.compiler.debug.lineNumber=generate | ||
7 | +org.eclipse.jdt.core.compiler.debug.localVariable=generate | ||
8 | +org.eclipse.jdt.core.compiler.debug.sourceFile=generate | ||
9 | +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
10 | +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
11 | +org.eclipse.jdt.core.compiler.source=1.6 |
No preview for this file type
@@ -0,0 +1,150 @@ | @@ -0,0 +1,150 @@ | ||
1 | +package food; | ||
2 | + | ||
3 | +import java.io.File; | ||
4 | +import java.io.FileNotFoundException; | ||
5 | +import java.lang.reflect.Array; | ||
6 | +import java.text.DateFormat; | ||
7 | +import java.text.SimpleDateFormat; | ||
8 | +import java.util.ArrayList; | ||
9 | +import java.util.Arrays; | ||
10 | +import java.util.Calendar; | ||
11 | +import java.util.Date; | ||
12 | +import java.util.Random; | ||
13 | +import java.util.Scanner; | ||
14 | + | ||
15 | +public class food { | ||
16 | + | ||
17 | + static ArrayList<String> food = new ArrayList<String>(); | ||
18 | + static String[] forday = new String[10]; | ||
19 | + static String[] fordaycheck = new String[10]; | ||
20 | + static String[] foreat = new String[10]; | ||
21 | + static DateFormat TypeDate = new SimpleDateFormat("EEEE ·Õè dd"); | ||
22 | + | ||
23 | + public static void main(String[] args) throws FileNotFoundException { | ||
24 | + int today = 100, yesterday = 99, twodayago = 98,threedayago=97; | ||
25 | + File file = new File("food.txt"); | ||
26 | + Scanner scname = new Scanner(file); | ||
27 | + Scanner sc = new Scanner(System.in); | ||
28 | + String Inputday = sc.nextLine(); | ||
29 | + Random random = new Random(); | ||
30 | + String name; | ||
31 | + | ||
32 | + // get food name | ||
33 | + while (scname.hasNext()) { | ||
34 | + name = scname.nextLine(); | ||
35 | + food.add(name); | ||
36 | + } | ||
37 | + boolean[] checkfood = new boolean[food.size()+1]; | ||
38 | + Calendar c = Calendar.getInstance(); | ||
39 | + | ||
40 | + // Set the calendar to monday of the current week | ||
41 | + c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); | ||
42 | + | ||
43 | + // Print dates of the current week starting on Monday to Friday | ||
44 | + DateFormat CheckDate = new SimpleDateFormat("dd/M/yyyy"); | ||
45 | + for (int i = 0; i < 10; i++) { | ||
46 | + int dayOfWeek = c.get(Calendar.DAY_OF_WEEK); | ||
47 | + forday[i] = TypeDate.format(c.getTime()); | ||
48 | + fordaycheck[i] = CheckDate.format(c.getTime()); | ||
49 | + if (dayOfWeek == Calendar.FRIDAY) { // If it's Friday so skip to | ||
50 | + // Monday | ||
51 | + c.add(Calendar.DATE, 3); | ||
52 | + } else if (dayOfWeek == Calendar.SATURDAY) { // If it's Saturday | ||
53 | + // skip to Monday | ||
54 | + c.add(Calendar.DATE, 2); | ||
55 | + } else { | ||
56 | + c.add(Calendar.DATE, 1); | ||
57 | + } | ||
58 | + } | ||
59 | + | ||
60 | + if (food.size() > 3) { | ||
61 | + for (int j = 0; j < foreat.length; j++) { | ||
62 | + today = random.nextInt(food.size()); | ||
63 | + checkfood[checkfood.length-1]=false; | ||
64 | + checkfood = checkdupi(today,checkfood); | ||
65 | + if(checkfood[checkfood.length-1]){ | ||
66 | + if (today == yesterday || today == twodayago||today == threedayago) { | ||
67 | + j = j - 1; | ||
68 | + checkfood[today]=false; | ||
69 | + continue; | ||
70 | + } else { | ||
71 | + foreat[j] = forday[j] + " " + food.get(today); | ||
72 | + } | ||
73 | + threedayago = twodayago; | ||
74 | + twodayago = yesterday; | ||
75 | + yesterday = today; | ||
76 | + } | ||
77 | + else{ | ||
78 | + j = j - 1; | ||
79 | + continue; | ||
80 | + } | ||
81 | + } | ||
82 | + } | ||
83 | + else { | ||
84 | + System.out.println("cannot create list food [Need more food list] "); | ||
85 | + System.exit(0); | ||
86 | + } | ||
87 | + | ||
88 | + selectdayforprint(Inputday); | ||
89 | + } | ||
90 | + | ||
91 | + //for print | ||
92 | + public static void selectdayforprint(String Inputday){ | ||
93 | + if ("".equals(Inputday)) { | ||
94 | + Date t = new Date(); | ||
95 | + int j = 0; | ||
96 | + String x = TypeDate.format(t.getTime()); | ||
97 | + for (int i = 0; i < forday.length; i++) { | ||
98 | + if (x.equals(forday[i])) { | ||
99 | + j = i; | ||
100 | + break; | ||
101 | + } | ||
102 | + } | ||
103 | + for (int k = j; k < 10; k++) { | ||
104 | + System.out.println(foreat[k]); | ||
105 | + } | ||
106 | + } else { | ||
107 | + int j = -1; | ||
108 | + for (int i = 0; i < fordaycheck.length; i++) { | ||
109 | + if (Inputday.equals(fordaycheck[i])) { | ||
110 | + j = i; | ||
111 | + break; | ||
112 | + } | ||
113 | + } | ||
114 | + if (j == -1) { | ||
115 | + System.out.println("No Have Day"); | ||
116 | + } else { | ||
117 | + for (int k = j; k < 10; k++) | ||
118 | + System.out.println(foreat[k]); | ||
119 | + } | ||
120 | + } | ||
121 | + } | ||
122 | + | ||
123 | + //check dupicate food | ||
124 | + public static boolean[] checkdupi(int food,boolean[] checkfood){ | ||
125 | + boolean checkfull = true; | ||
126 | + if(checkfood[food] == false){ | ||
127 | + checkfood[food]=true; | ||
128 | + checkfood[checkfood.length-1]=true; | ||
129 | + checkfull=false; | ||
130 | + } | ||
131 | + else{ | ||
132 | + for(int i =0;i<checkfood.length-1;i++){ | ||
133 | + if(checkfood[i]==false){ | ||
134 | + checkfull=false; | ||
135 | + break; | ||
136 | + } | ||
137 | + } | ||
138 | + } | ||
139 | + if(checkfull){ | ||
140 | + clearboolean(checkfood); | ||
141 | + } | ||
142 | + return checkfood; | ||
143 | + } | ||
144 | + | ||
145 | + public static void clearboolean (boolean[] checkfood){ | ||
146 | + for(int i=0;i<checkfood.length;i++){ | ||
147 | + checkfood[i]=false; | ||
148 | + } | ||
149 | + } | ||
150 | +} |