Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zhong ming branch data base #185

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/main/java/seedu/dietbook/database/DataBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void printAllData() {
System.out.println("Finished Printing out all data");
}

// -------- Search functions --------
// ----- Food search functions -------

/**
* This method searchs the whole data base and returns the first food item whose name contains the provided string.
Expand All @@ -134,6 +134,10 @@ public Food searchFoodByName(String food) {
return foodStream().filter(x -> x.getName().contains(food)).findFirst().orElseThrow();
}

public Food searchFoodByIndex(int index) {
return foodStream().skip(index - 1).findFirst().orElseThrow();
}

/**
* This method searchs the whole data base and returns all of the food whose name contains the provided string.
* @param food part of the name of the food e.g. chicken
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/seedu/dietbook/database/data.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,15 @@ Ayam Penyet Set|699|0|0|0
Steamed Chicken Set |475|0|0|0
Ikan Grouper Penyet Set|669|0|0|0
&%UP
Michelin Star Restaurant
Bouillabaisse with cock crab and poached lobster|520|45|35|56
Chicken wings with Reblochon pomme purée|450|25|32|66
Sea bass with prawn tortellini, fennel purée and white wine sauce|530|76|25|43
Korean
kimchi fried rice|520|45|35|56
ginseng chicken|450|25|32|66
ramen|530|76|25|43
&%UP
Gong Cha
gong cha green tea|100|0|0|0
gong cha ooloong tea|100|0|0|0
gong cha bubble tea|200|0|0|0
&%UP
&%UP
&%STOP
Expand Down
31 changes: 18 additions & 13 deletions src/main/resources/data.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,27 @@
&%START
Science canteen
Halal Mini Wok
Prawn Mee Soup(Dry)(Large)|490|0|0|0
Prawn Mee Soup(Dry)(Small)|390|0|0|0
Fried Hokkien Prawn Mee(Large)|470|0|0|0
Fried Hokkien Prawn Mee(Small)|350|0|0|0
Clay Pot Chicken|440|0|0|0
Black Pepper Chicken|490|0|0|0
Prawn Mee Soup(Dry)(Large)|490|30|20|26
Prawn Mee Soup(Dry)(Small)|390|25|15|19
Fried Hokkien Prawn Mee(Large)|470|40|20|20
Fried Hokkien Prawn Mee(Small)|350|30|15|15
Clay Pot Chicken|440|34|15|15
Black Pepper Chicken|490|34|16|16
&%UP
Ayam Penyet
Ayam Penyet Set|699|0|0|0
Steamed Chicken Set |475|0|0|0
Ikan Grouper Penyet Set|669|0|0|0
Ayam Penyet Set|699|45|30|30
Steamed Chicken Set |475|35|20|20
Ikan Grouper Penyet Set|669|50|40|50
&%UP
Michelin Star Restaurant
Bouillabaisse with cock crab and poached lobster|520|45|35|56
Chicken wings with Reblochon pomme purée|450|25|32|66
Sea bass with prawn tortellini, fennel purée and white wine sauce|530|76|25|43
Korean
kimchi fried rice|520|45|35|56
ginseng chicken|450|25|32|66
ramen|530|76|25|43
&%UP
Gong Cha
gong cha green tea|100|0|0|0
gong cha ooloong tea|100|0|0|0
gong cha bubble tea|200|0|0|0
&%UP
&%UP
&%STOP
Expand Down
22 changes: 18 additions & 4 deletions src/test/java/seedu/dietbook/database/DataBaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,26 @@ public static void main(String[] args) {
database.printAllData();

// ---- Using stream version to print -----
System.out.println("------------ printing using food stream ------------");
database.foodStream().forEach(System.out::println);
// System.out.println("------------ printing using food stream ------------");
// database.foodStream().forEach(System.out::println);

// ---- Printing out as list -----
System.out.println("---------- printing food using list --------------");
database.getFoodList().forEach(System.out::println);
// System.out.println("---------- printing food using list --------------");
// database.getFoodList().forEach(System.out::println);

// ---- get food list string ----
System.out.print(database.getFoodListString());

// ---- search food by index test ----
System.out.println("-------- testing the searchFoodByIndex function --------");
System.out.println("Input : 1 ## OutPut : " + database.searchFoodByIndex(1));
System.out.println("Input : 10 ## Output : " + database.searchFoodByIndex(10));
System.out.println("Trying a negative test case : Input : 10000");
try {
database.searchFoodByIndex(10000);
} catch (NoSuchElementException e) {
System.out.println("The index is too high!" + e);
}

// ---- search food by name test -----
try {
Expand Down
53 changes: 53 additions & 0 deletions src/test/resources/data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#####################################################################
# 3 LEVEL DATA BASE #
# Canteen -----> Store ------> Food #
# Commands : #
# &%START : start reading data from the data base #
# &%STOP : stop reading data from the data base #
# &%UP : goes down 1 level e.g. Canteen ---> Store #
# &%DOWN : goes down 1 level e.g. Canteen ---> Store #
# &%ADD format : adds the item with the given format #
# #
# Comments : any line that starts with # is ignored #
# #
# Canteen format : {name} #
# Store format : {name} #
# Food format : {name}|{Calorie}|{Carb}|{Protein}|{Fat} #
#####################################################################

######################################################################
# Version 0.1 : #
# there is only UP, once a store or canteen is #
# specified we automatically go down 1 level , for this version #
# there is no going out of a store and then coming back to add more#
# Units : Calorie : kcal : Carbs : g Protein : g : Fats : g #
######################################################################

&%START
Science canteen
Halal Mini Wok
Prawn Mee Soup(Dry)(Large)|490|30|20|26
Prawn Mee Soup(Dry)(Small)|390|25|15|19
Fried Hokkien Prawn Mee(Large)|470|40|20|20
Fried Hokkien Prawn Mee(Small)|350|30|15|15
Clay Pot Chicken|440|34|15|15
Black Pepper Chicken|490|34|16|16
&%UP
Ayam Penyet
Ayam Penyet Set|699|45|30|30
Steamed Chicken Set |475|35|20|20
Ikan Grouper Penyet Set|669|50|40|50
&%UP
Korean
kimchi fried rice|520|45|35|56
ginseng chicken|450|25|32|66
ramen|530|76|25|43
&%UP
Gong Cha
gong cha green tea|100|0|0|0
gong cha ooloong tea|100|0|0|0
gong cha bubble tea|200|0|0|0
&%UP
&%UP
&%STOP