Skip to content

Commit

Permalink
Merge pull request #4 from VirginiaYu/master
Browse files Browse the repository at this point in the history
Order
  • Loading branch information
9hafidz6 authored Oct 16, 2019
2 parents 22da31b + 55069fa commit a7dbee0
Show file tree
Hide file tree
Showing 14 changed files with 798 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/duke/command/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void execute(dishlist dish1, TaskList taskList, Ui ui, Storage storage) t
fileContent.remove(taskNb); // changing the file content
Files.write(storage.getPath(), fileContent, StandardCharsets.UTF_8);
} catch (IOException e) {
throw new DukeException("Error while deleting the task from the had disc");
throw new DukeException("Error while deleting the task from the hard disc");
}
ui.showRemovedTask(removed.toString(), taskList.size());
} else {
Expand Down
168 changes: 168 additions & 0 deletions src/main/java/duke/order/Order.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
package duke.order;

import duke.Duke;
import duke.exception.DukeException;
import duke.parser.Convert;
import duke.task.Dish;

import java.util.*;

/**
* Represents a general Order to be added by {@link Duke}.
*/
public class Order {
private Map<Integer, Integer> content; //first int is dishNb, second is dishAmount
private boolean isDone;
private Date date;
private String name;

/**
* The constructor method for {@link Order}.
*/
public Order() {
this.isDone = false;
this.date = new Date();
this.content = new HashMap<>();
this.name = "";
}

/**
* The constructor method for the {@link Order} in reservation case.
* @param date date of serving the {@link Order}.
*/
public Order(String date, String name) {
this.date = (date=="")? new Date():Convert.stringToDate(date);
this.isDone = false;
this.content = new HashMap<>();
this.name = name;
}

/**
* Used to get the serving date of the {@link Order}.
*/
public Date getDate() { return this.date;}

/**
* Used to get the customer name of the {@link Order}.
*/
public String getCustomerName() { return this.name;}

/**
* Used to alter the serving date of the {@link Order}.
* @param date reset date of the {@link Order}.
*/
public void setDate(String date) {
this.date = Convert.stringToDate(date);
}

/**
* Used to alter the serving date of the {@link Order}.
* @param name reset customer name of the reservation {@link Order}.
*/
public void setCustomerName(String name) {
this.name = name;
}

/**
* Returns a boolean indicating whether the {@link Order} was completed.
* @return boolean true if the order was marked as done, false otherwise
*/
public boolean isDone() { return isDone; }

/**
* Returns a String representation of the status icon, indicating whether the {@link Order} was done.
* @return a tick or a cross
*/
public String getStatusIcon() {
return (isDone ? "\u2713" : "\u2718"); //return tick or X symbols
}

/**
* Returns the content of the {@link Order}.
* Write the content into file.
* @return content of the Order
*/
public Map<Integer, Integer> getOrder() { return this.content; }

public String printInFile() {
String desc;
if (this.isDone()) { desc = "O|1|" + this.date + "|" + this.name; }
else { desc = "O|0|" + this.date + "|" + this.name; }
for (Map.Entry<Integer, Integer> entry : content.entrySet()) {
int DishNb = entry.getKey();
int DishAmount = entry.getValue();
desc += "\nD|" + DishAmount + "|" + DishNb;
}
return desc;
}

/**
* Returns the content of the {@link Order}.
* Show the content to the user/customer.
* @return content of the Order
*/
public String toString() {
String description = "[" + getStatusIcon() + "] ";
if (this.date!=new Date()) {
description += "Preorder under "+ this.name + " on " + this.date;
}else {
description += "Order Today";
}
for (Map.Entry<Integer, Integer> entry : content.entrySet()) {
try {
int DishNb = entry.getKey();
String DishName = getDishName(DishNb);
int DishAmount = entry.getValue();
description += "\n" + DishAmount + DishName;
} catch (DukeException e) {
e.printStackTrace();
}
}
return description;
}

public double getTotalPrice() {
//To do
//link the price with DishNb s.t. can calculate total price
int unitPrice = 1;

double total = 0;
for (Map.Entry<Integer, Integer> entry : content.entrySet()) {
int DishNb = entry.getKey();
int DishAmount = entry.getValue();
total += DishAmount*unitPrice;
}
return total;
}

public void addDish(int dishNb, int amount) {
this.content.put(dishNb, amount);
}

/**
* Used to mark the {@link Order} as finished.
*/
public void markAsDone() {
this.isDone = true;
}

public String getDishName(int dishNb) throws DukeException {
try {
switch (dishNb) {
case 1: return "Beef Noodle";
case 2: return "Pork Dumplings";
case 3: return "Chili Crab";
case 4: return "Cereal Prawn";
case 5: return "Laksa";
case 6: return "Chicken Rice";
case 7: return "Seasonal Vegetables";
default:
throw new DukeException("No corresponding dishes in today's menu!");
}
}catch (Exception e){
e.getMessage();
}
return "";
}

}
112 changes: 112 additions & 0 deletions src/main/java/duke/order/OrderList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package duke.order;

import duke.Duke;
import duke.exception.DukeException;
import duke.parser.Convert;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
* Represents a list of {@link Order}s added by {@link Duke}.
*/
public class OrderList {
private List<Order> orderList;

/**
* The constructor method(1) for OrderList.
*/
public OrderList(List<Order> orderList) {
this.orderList = orderList;
}

/**
* The constructor method(2) for OrderList.
*/
public OrderList() {
this.orderList = new ArrayList<>();
}

/**
* Adds a order to the {@link OrderList}.
* @param order {@link Order} to be added to the list
*/
public void addOrder(Order order) {
orderList.add(order);
}

/**
* Returns the number of {@link Order}s in the {@link OrderList} so far.
* @return an integer indicating the size of the list of {@link Order}s stored
*/
public int size() {
return orderList.size();
}

/**
* Marks a order as completed if the user finished it.
* @param orderNb the number of the {@link Order} in the {@link OrderList} that was completed
*/
public void markOrderDone(int orderNb) {
orderList.get(orderNb).markAsDone();
}

/**
* Returns the {@link Order} at the position indicated by the orderNb.
* @param orderNb the position of the {@link Order} requested in the {@link OrderList}
* @return the requested {@link Order}
*/
public Order getOrder(int orderNb) {
return orderList.get(orderNb);
}

/**
* Returns a list of all the {@link Order}s in the {@link OrderList}.
* @return {@link ArrayList} of {@link Order}
*/
public List<Order> getAllOrders() {
return orderList;
}

/**
* Returns a list of all the undone {@link Order}s in the {@link OrderList}.
* Not including orders that has been done.
* @return {@link ArrayList} of {@link Order}
*/
public List<Order> getAllUndoneOrders() {
List<Order> udOrderList = null;
for (Order order : orderList) {
if (!order.isDone()) { udOrderList.add(order); }
}
return udOrderList;
}
/**
* Returns the removed {@link Order} from position orderNb in the {@link OrderList}.
* @param orderNb the position of the {@link Order} to be removed from the {@link OrderList}
* @return Order the order list with the order removed
*/
public Order removeOrder(int orderNb) {
return orderList.remove(orderNb);
}

public void changeOrderDate(int orderNb, String date) throws DukeException {
Date newDate = Convert.stringToDate(date);
//If set date is before today
if (newDate.before(new Date())) {
throw new DukeException("Invalid Date!");
}else { orderList.get(orderNb).setDate(date); }
}

public void changeOrderName(int orderNb, String name) {
orderList.get(orderNb).setCustomerName(name);
}

public void addOrderDish(int orderNb, int dishNb, int amount) {
orderList.get(orderNb).addDish(dishNb, amount);
}


}


Loading

0 comments on commit a7dbee0

Please sign in to comment.