From 1ca72264da1ab305842ee5f3034f8f8f753aa1c1 Mon Sep 17 00:00:00 2001 From: Suraputt Suntimitr Date: Tue, 14 Jun 2016 18:05:39 +0700 Subject: [PATCH] random food --- .classpath | 6 ++++++ .project | 17 +++++++++++++++++ .settings/org.eclipse.jdt.core.prefs | 11 +++++++++++ bin/food/food.class | Bin 0 -> 4171 bytes food.txt | 9 +++++++++ src/food/food.java | 150 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 193 insertions(+), 0 deletions(-) create mode 100644 .classpath create mode 100644 .project create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 bin/food/food.class create mode 100644 food.txt create mode 100644 src/food/food.java diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..18d70f0 --- /dev/null +++ b/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..6c00df2 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + FOOD + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..8000cd6 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/bin/food/food.class b/bin/food/food.class new file mode 100644 index 0000000..50c76d5 Binary files /dev/null and b/bin/food/food.class differ diff --git a/food.txt b/food.txt new file mode 100644 index 0000000..83b2a16 --- /dev/null +++ b/food.txt @@ -0,0 +1,9 @@ +1 +2 +3 +4 +5 +6 +7 +8 +9 \ No newline at end of file diff --git a/src/food/food.java b/src/food/food.java new file mode 100644 index 0000000..66323c2 --- /dev/null +++ b/src/food/food.java @@ -0,0 +1,150 @@ +package food; + +import java.io.File; +import java.io.FileNotFoundException; +import java.lang.reflect.Array; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Date; +import java.util.Random; +import java.util.Scanner; + +public class food { + + static ArrayList food = new ArrayList(); + static String[] forday = new String[10]; + static String[] fordaycheck = new String[10]; + static String[] foreat = new String[10]; + static DateFormat TypeDate = new SimpleDateFormat("EEEE ·Υθ dd"); + + public static void main(String[] args) throws FileNotFoundException { + int today = 100, yesterday = 99, twodayago = 98,threedayago=97; + File file = new File("food.txt"); + Scanner scname = new Scanner(file); + Scanner sc = new Scanner(System.in); + String Inputday = sc.nextLine(); + Random random = new Random(); + String name; + + // get food name + while (scname.hasNext()) { + name = scname.nextLine(); + food.add(name); + } + boolean[] checkfood = new boolean[food.size()+1]; + Calendar c = Calendar.getInstance(); + + // Set the calendar to monday of the current week + c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); + + // Print dates of the current week starting on Monday to Friday + DateFormat CheckDate = new SimpleDateFormat("dd/M/yyyy"); + for (int i = 0; i < 10; i++) { + int dayOfWeek = c.get(Calendar.DAY_OF_WEEK); + forday[i] = TypeDate.format(c.getTime()); + fordaycheck[i] = CheckDate.format(c.getTime()); + if (dayOfWeek == Calendar.FRIDAY) { // If it's Friday so skip to + // Monday + c.add(Calendar.DATE, 3); + } else if (dayOfWeek == Calendar.SATURDAY) { // If it's Saturday + // skip to Monday + c.add(Calendar.DATE, 2); + } else { + c.add(Calendar.DATE, 1); + } + } + + if (food.size() > 3) { + for (int j = 0; j < foreat.length; j++) { + today = random.nextInt(food.size()); + checkfood[checkfood.length-1]=false; + checkfood = checkdupi(today,checkfood); + if(checkfood[checkfood.length-1]){ + if (today == yesterday || today == twodayago||today == threedayago) { + j = j - 1; + checkfood[today]=false; + continue; + } else { + foreat[j] = forday[j] + " " + food.get(today); + } + threedayago = twodayago; + twodayago = yesterday; + yesterday = today; + } + else{ + j = j - 1; + continue; + } + } + } + else { + System.out.println("cannot create list food [Need more food list] "); + System.exit(0); + } + + selectdayforprint(Inputday); + } + + //for print + public static void selectdayforprint(String Inputday){ + if ("".equals(Inputday)) { + Date t = new Date(); + int j = 0; + String x = TypeDate.format(t.getTime()); + for (int i = 0; i < forday.length; i++) { + if (x.equals(forday[i])) { + j = i; + break; + } + } + for (int k = j; k < 10; k++) { + System.out.println(foreat[k]); + } + } else { + int j = -1; + for (int i = 0; i < fordaycheck.length; i++) { + if (Inputday.equals(fordaycheck[i])) { + j = i; + break; + } + } + if (j == -1) { + System.out.println("No Have Day"); + } else { + for (int k = j; k < 10; k++) + System.out.println(foreat[k]); + } + } + } + + //check dupicate food + public static boolean[] checkdupi(int food,boolean[] checkfood){ + boolean checkfull = true; + if(checkfood[food] == false){ + checkfood[food]=true; + checkfood[checkfood.length-1]=true; + checkfull=false; + } + else{ + for(int i =0;i