Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
Fix the bugs that unable to see the category enum and category parse class.
  • Loading branch information
MrOPPA1 committed Nov 14, 2023
1 parent d3e8ce6 commit 20aee5d
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 6 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# Gradle build files
/.gradle/
/build/
src/main/resources/docs/

# MacOS custom attributes files created by Finder
.DS_Store
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/seedu/duke/TipsException.java
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;
}
}
2 changes: 1 addition & 1 deletion src/main/java/seedu/duke/commands/meal/AddCommand.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package seedu.duke.commands.meal;

import seedu.duke.commands.CommandResult;
import seedu.duke.data.meal.Meal;
import seedu.duke.meal.*;
import seedu.duke.data.Date;

import java.util.List;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/duke/commands/meal/DeleteCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.duke.commands.meal;

import seedu.duke.commands.CommandResult;
import seedu.duke.meal.*;

import java.util.List;

Expand Down
4 changes: 1 addition & 3 deletions src/main/java/seedu/duke/commands/meal/ListCommand.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package seedu.duke.commands.meal;

import seedu.duke.commands.CommandResult;
import seedu.duke.data.meal.Category;
import seedu.duke.data.meal.CategoryParser;
import seedu.duke.data.meal.Meal;
import seedu.duke.meal.*;

import java.util.ArrayList;
import java.util.List;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/duke/commands/meal/MealCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import seedu.duke.commands.Command;
import seedu.duke.commands.CommandResult;
import seedu.duke.data.meal.Meal;
import seedu.duke.meal.*;

public class MealCommand extends Command {
protected static ArrayList<Meal> meals;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/seedu/duke/meal/Category.java
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
}
19 changes: 19 additions & 0 deletions src/main/java/seedu/duke/meal/CategoryParser.java
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.");
}
}
}
}
22 changes: 22 additions & 0 deletions src/main/java/seedu/duke/meal/Meal.java
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() + ")";
}
}

0 comments on commit 20aee5d

Please sign in to comment.