forked from nus-cs2113-AY2324S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the bugs that unable to see the category enum and category parse class.
- Loading branch information
Showing
9 changed files
with
76 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package seedu.duke; | ||
|
||
/** | ||
* Any excption will be throw in this type, which contains information about | ||
* this exception and the possible solution. | ||
* It's suggested to use toString() to show the content of this exception so | ||
* that the tester can have a clear view of the error reason and the possible | ||
* solution to solve this error. | ||
*/ | ||
public class TipsException extends Exception { | ||
public String error, tips; | ||
|
||
/** | ||
* Creating a new Tips Exception. | ||
*/ | ||
public TipsException(String error, String tips) { | ||
this.error = error; | ||
this.tips = tips; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Error: " + error | ||
+ "\nTips: " + tips; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package seedu.duke.meal; | ||
|
||
public enum Category { | ||
staple_food, snack, beverage | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package seedu.duke.meal; | ||
|
||
public class CategoryParser { | ||
private static Category[] categories = Category.values(); | ||
|
||
public static Category Parse(String categoryString) throws Exception { | ||
try { | ||
int index = Integer.parseInt(categoryString); | ||
return categories[index]; | ||
} catch (Exception exception1) { | ||
try { | ||
return Category.valueOf(categoryString); | ||
} catch (Exception exception2) { | ||
throw new Exception( | ||
"Unable to parse Category String into Category enum.\nPlease input a number ranging in 0~2 or a valid category type."); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package seedu.duke.meal; | ||
|
||
import seedu.duke.data.Date; | ||
|
||
public class Meal { | ||
public String name; | ||
public int calories; | ||
public Date time; | ||
public Category category; | ||
|
||
public Meal(String name, int calories, String category, Date time) throws Exception { | ||
this.name = name; | ||
this.calories = calories; | ||
this.time = time; | ||
this.category = CategoryParser.Parse(category); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return name + "(" + calories + " calories, " + category + ", on " + time.toString() + ")"; | ||
} | ||
} |