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

fix bugs #104

Merged
merged 1 commit into from
Nov 14, 2023
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
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() + ")";
}
}
Loading