Skip to content

Commit

Permalink
Merge pull request #39 from saradj/b-genericList
Browse files Browse the repository at this point in the history
Adding a GenericList we can use for ingredient list, order list, task list, dish list... renaming Dishes to Dish, and some changes in packages, Also added Fridge Storage(storing the ingrediants already there) and Task Storage
  • Loading branch information
JiahanYu authored Oct 23, 2019
2 parents 7a8257b + 1fcfe90 commit 3617a67
Show file tree
Hide file tree
Showing 47 changed files with 639 additions and 345 deletions.
30 changes: 30 additions & 0 deletions Fridge.uml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<Diagram>
<ID>JAVA</ID>
<OriginalElement>duke.fridge.Fridge</OriginalElement>
<nodes>
<node x="37.0" y="0.0">duke.ingredient.Ingredient</node>
<node x="0.0" y="257.0">duke.fridge.Fridge</node>
</nodes>
<notes />
<edges>
<edge source="duke.fridge.Fridge" target="duke.ingredient.Ingredient">
<point x="-72.75" y="-158.5" />
<point x="72.75" y="232.0" />
<point x="91.25" y="232.0" />
<point x="-54.25" y="103.5" />
</edge>
</edges>
<settings layout="Hierarchic Group" zoom="1.0904024767801856" x="209.90086910464152" y="286.767461669506" />
<SelectedNodes />
<Categories>
<Category>Constructors</Category>
<Category>Methods</Category>
<Category>Inner Classes</Category>
<Category>Fields</Category>
<Category>Properties</Category>
</Categories>
<SCOPE>All</SCOPE>
<VISIBILITY>private</VISIBILITY>
</Diagram>

Empty file added data/fridge.txt
Empty file.
3 changes: 2 additions & 1 deletion data/tasks.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ T|1|read book
D|1|return book|09/09/09 2359
T|0|beef 16/10/2019
T|0|test 09/09/09
T|0|test1 16/10/2019
T|1|test1 16/10/2019
T|0|read books
T|0|sleep
14 changes: 14 additions & 0 deletions duke.plantuml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@startuml

title __DUKE's Component Diagram__\n



right footer


PlantUML diagram generated by SketchIt! (https://bitbucket.org/pmesmeur/sketch.it)
For more information about this tool, please contact [email protected]
endfooter

@enduml
2 changes: 1 addition & 1 deletion src/main/java/duke/Dishes/DishList.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ public void clearList() {
public String toString(Dishes dish) {
return dish.getDishname();
}
}
}
4 changes: 4 additions & 0 deletions src/main/java/duke/Dishes/Dishes.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,8 @@ public void addIngredients(String ingredients) {
// public String toString() {
// return dishname;
// }
<<<<<<< HEAD
}
=======
}
>>>>>>> 7a8257b6995584c461da76d397bd91d8497d6357
35 changes: 22 additions & 13 deletions src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
@@ -1,39 +1,48 @@
package duke;

import duke.command.Cmd;
import duke.dish.Dish;
import duke.exception.DukeException;
import duke.fridge.Fridge;
import duke.order.Order;
import duke.order.OrderList;
import duke.parser.Parser;
import duke.Dishes.DishList;
import duke.dish.DishList;
import duke.storage.FridgeStorage;
import duke.storage.Storage;
import duke.storage.TaskStorage;
import duke.task.Task;
import duke.task.TaskList;
import duke.ui.Ui;

import java.lang.reflect.Field;
import java.lang.reflect.Type;

/**
* MAIN CLASS DUKE, start from main function.
*/
public class Duke {

private Storage storage;
private Storage taskStorage;
private Storage fridgeStorage;
private TaskList tasks;
private Ui ui;
private DishList dish;
private OrderList order;
private Fridge fridge;

/**
* The constructor method for Duke.
* @param filePath used to specify the location of the file in the hard disc.
*/
public Duke(String filePath) {
String fridgeFilePath= "data/fridge.txt";
dish = new DishList();
order = new OrderList();
fridge = new Fridge();
ui = new Ui();
storage = new Storage(filePath);
taskStorage = new TaskStorage(filePath);
fridgeStorage = new FridgeStorage(fridgeFilePath);
try {
tasks = new TaskList(storage.load());
tasks = new TaskList(taskStorage.load());
fridge = new Fridge (fridgeStorage.load());
} catch (DukeException e) {
ui.showLoadingError();
tasks = new TaskList();
Expand All @@ -52,18 +61,18 @@ public void run() {
ui.showLine();
// Command c = Parser.parse(fullCommand, tasks.size());
if (fullCommand.startsWith("order")) {
Cmd<OrderList> c = Parser.Parse(fullCommand); //execute the orderCommands, add order etc
c.execute(order, ui, storage);
Cmd<Order> c = Parser.Parse(fullCommand); //execute the orderCommands, add order etc
c.execute(order, ui, taskStorage);
isExit = c.isExit();
}
else if (fullCommand.startsWith("dish")) {
Cmd<DishList> c = Parser.Parse(fullCommand); //execute the recipeCommands, add dishes etc
c.execute(dish, ui, storage);
Cmd<Dish> c = Parser.Parse(fullCommand); //execute the recipeCommands, add dishes etc
c.execute(dish, ui, taskStorage);
isExit = c.isExit();
}
else {
Cmd<TaskList> c = Parser.parse(fullCommand, tasks.size()); //execute the ingredientCommands, add dishes etc
c.execute(tasks, ui, storage);
Cmd<Task> c = Parser.parse(fullCommand, tasks.size()); //execute the ingredientCommands, add dishes etc
c.execute(tasks, ui, taskStorage);
isExit = c.isExit();
}
} catch (DukeException e) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/duke/command/Cmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import duke.command.ingredientCommand.ExitCommand;
import duke.exception.DukeException;
import duke.list.GenericList;
import duke.storage.Storage;
import duke.ui.Ui;

public abstract class Cmd<T> {
public abstract void execute(T tasklist, Ui ui, Storage storage) throws DukeException;
public abstract void execute(GenericList<T> tasklist, Ui ui, Storage storage) throws DukeException;
/**
* Returns the boolean indicating that it is( not) an {@link ExitCommand}.
*
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/duke/command/FindIngredientCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package duke.command;

import duke.exception.DukeException;
import duke.list.GenericList;
import duke.storage.Storage;
import duke.ingredient.*;
import duke.task.TaskList;
import duke.ui.Ui;

/**
* Represents a specific {@link Cmd} used to find a String occurring in the {@link TaskList}.
*/
public class FindIngredientCommand extends Cmd<Ingredient> {

private String toFind;

public FindIngredientCommand(String toFind) {
this.toFind = toFind;
}



@Override
public void execute(GenericList<Ingredient> tasklist, Ui ui, Storage storage) throws DukeException {

}
}
37 changes: 20 additions & 17 deletions src/main/java/duke/command/dishesCommand/AddDishCommand.java
Original file line number Diff line number Diff line change
@@ -1,54 +1,57 @@
package duke.command.dishesCommand;

import duke.Dishes.DishList;
import duke.Dishes.Dishes;
import duke.command.ingredientCommand.AddCommand;
import duke.dish.DishList;
import duke.dish.Dish;
import duke.command.Cmd;
import duke.exception.DukeException;
import duke.storage.Storage;
import duke.ui.Ui;

public class AddDishCommand extends Cmd<DishList> {
public class AddDishCommand extends AddCommand<Dish> {

private Dishes dish;
private Dish dish;
private int amount;
private int Nb;

public AddDishCommand(Dishes dish, int amount) {

public AddDishCommand(Dish dish, int amount) {
super(dish);
this.dish = dish;
this.amount = amount;
}

@Override
public void execute(DishList dish1, Ui ui, Storage storage) throws DukeException {
public void execute(DishList dishList, Ui ui, Storage storage) throws DukeException {
boolean flag = true;
try {
if(dish1.getSize() == 0) {
dish1.addDish(dish);
dish1.getDish(0).setNumberOfOrders(amount);
if(dishList.size() == 0) {
dishList.addEntry(dish);
dishList.getEntry(0).setNumberOfOrders(amount);
ui.showAddedDishes(dish.getDishname(), amount);
}
else {
for( int i = 0; i < dish1.getSize(); i++) {
if(dish1.getDish(i).getDishname().equals(dish.getDishname())){
for( int i = 0; i < dishList.size(); i++) {
if(dishList.getEntry(i).getDishname().equals(dish.getDishname())){
Nb = i;
flag = false; //dish already exist in list
break;
}
}
if(flag) {
dish1.addDish(dish); // add dish into list found in dishes class
dish1.getDish(dish1.getSize() - 1).setNumberOfOrders(amount);
ui.showAddedDishes(dish.getDishname(), dish1.getDish(dish1.getSize() - 1).getTotalNumberOfOrders());
dishList.addEntry(dish); // add dish into list found in dishes class
dishList.getEntry(dishList.size() - 1).setNumberOfOrders(amount);
ui.showAddedDishes(dish.getDishname(), dishList.getEntry(dishList.size() - 1).getTotalNumberOfOrders());
}
else {
dish1.getDish(Nb).setNumberOfOrders(amount);
dishList.getEntry(Nb).setNumberOfOrders(amount);
System.out.println("\t your updated orders:\n\t "
+ dish.getDishname() + "\t amount: " +
String.valueOf(dish1.getDish(Nb).getTotalNumberOfOrders()));
String.valueOf(dishList.getEntry(Nb).getTotalNumberOfOrders()));
}
}
} catch (Exception e) {
throw new DukeException("unable to add dish");
}
}

}
20 changes: 12 additions & 8 deletions src/main/java/duke/command/dishesCommand/AddIngredient.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
package duke.command.dishesCommand;

import duke.Dishes.DishList;
import duke.command.ingredientCommand.AddCommand;
import duke.dish.DishList;
import duke.command.Cmd;
import duke.exception.DukeException;
import duke.ingredient.Ingredient;
import duke.ingredient.IngredientsList;
import duke.storage.Storage;
import duke.ui.Ui;

public class AddIngredient extends Cmd<DishList> {
public class AddIngredient extends AddCommand<Ingredient> {

private String ingredient;
private Ingredient ingredient;
private int Nb;

public AddIngredient(String ingredient, int Nb) {
public AddIngredient(Ingredient ingredient, int Nb) {
super(ingredient);
this.ingredient = ingredient;
this.Nb = Nb;
}

@Override
public void execute(DishList dish1, Ui ui, Storage storage) throws DukeException {

public void execute(DishList dishList, Ui ui, Storage storage) throws DukeException {
try {
dish1.getDish(Nb - 1).addIngredients(ingredient);
System.out.println("\t added ingredient: " + ingredient + "\n\t to dish: " + dish1.getDish(Nb - 1).getDishname());
dishList.getEntry(Nb - 1).addIngredients(ingredient);
System.out.println("\t added ingredient: " + ingredient + "\n\t to dish: " + dishList.getEntry(Nb - 1).getDishname());
} catch (Exception e) {
throw new DukeException("cannot add ingredient");
}
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/duke/command/dishesCommand/DeleteDishCommand.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
package duke.command.dishesCommand;

import duke.Dishes.DishList;
import duke.command.ingredientCommand.DeleteCommand;
import duke.dish.Dish;
import duke.dish.DishList;
import duke.command.Cmd;
import duke.exception.DukeException;
import duke.storage.Storage;
import duke.ui.Ui;

public class DeleteDishCommand extends Cmd<DishList> {
public class DeleteDishCommand extends DeleteCommand<Dish> {

private int Nb;

public DeleteDishCommand(int dishNb) {
super(dishNb);
this.Nb = dishNb;
}

@Override
public void execute(DishList dish1, Ui ui, Storage storage) throws DukeException {
try {
ui.showDeletedDIsh(dish1.getDish(Nb - 1).getDishname());
dish1.deleteDish(Nb - 1);
ui.showDeletedDIsh(dish1.getEntry(Nb - 1).getDishname());
dish1.removeEntry(Nb - 1);
} catch (Exception e) {
throw new DukeException("dish does not exist");
}
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/duke/command/dishesCommand/InitCommand.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
package duke.command.dishesCommand;

import duke.Dishes.DishList;
import duke.dish.Dish;
import duke.dish.DishList;
import duke.command.Cmd;
import duke.exception.DukeException;
import duke.list.GenericList;
import duke.storage.Storage;
import duke.ui.Ui;

public class InitCommand extends Cmd<DishList> {
public class InitCommand extends Cmd<Dish> {

public InitCommand() {
//clears all the amount in dishes
}

@Override
public void execute(DishList dish1, Ui ui, Storage storage) throws DukeException {
public void execute(GenericList<Dish> dish1, Ui ui, Storage storage) throws DukeException {
System.out.println("\t are you sure you want to clear list? (yes or no)");
String command = ui.readCommand();
if(command.equals("yes")){
Expand Down
16 changes: 9 additions & 7 deletions src/main/java/duke/command/dishesCommand/ListDishCommand.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
package duke.command.dishesCommand;

import duke.Dishes.DishList;
import duke.dish.Dish;
import duke.dish.DishList;
import duke.command.Cmd;
import duke.exception.DukeException;
import duke.list.GenericList;
import duke.storage.Storage;
import duke.ui.Ui;


public class ListDishCommand extends Cmd<DishList> {
public class ListDishCommand extends Cmd<Dish> {

@Override
public void execute(DishList dish1, Ui ui, Storage storage) throws DukeException {
if (dish1.getSize() == 0) {
public void execute(GenericList<Dish> dish1, Ui ui, Storage storage) throws DukeException {
if (dish1.size() == 0) {
throw new DukeException("No Dishes yet!");
} else {
System.out.println("\t Here are the dishes in your list:");
for (int i = 1; i <= dish1.getSize(); i++) { // looping to print all the saved tasks
ui.showDishes("\t " + i + "." + dish1.getDish(i - 1).getDishname()
, dish1.getDish(i - 1).getTotalNumberOfOrders());
for (int i = 1; i <= dish1.size(); i++) { // looping to print all the saved tasks
ui.showDishes("\t " + i + "." + dish1.getEntry(i - 1).getDishname()
, dish1.getEntry(i - 1).getTotalNumberOfOrders());
}
}
}
Expand Down
Loading

0 comments on commit 3617a67

Please sign in to comment.