Skip to content

Commit

Permalink
Construct the basic structure for "add reservation", "mark reservatio…
Browse files Browse the repository at this point in the history
…n", "void reservation", "list reservations", "list served reservations", "list unserved reservations".
  • Loading branch information
SibingWu committed Mar 9, 2020
1 parent fa66381 commit 9ee8f83
Show file tree
Hide file tree
Showing 11 changed files with 487 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/seedu/duke/Ui.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package seedu.duke;

/** Deals with interactions with the user. */
public class Ui {

}
63 changes: 63 additions & 0 deletions src/main/java/seedu/duke/commands/AddReservationCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package seedu.duke.commands;

import seedu.duke.reservation.Reservation;
import seedu.duke.reservation.ReservationList;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

import static seedu.duke.utils.Constants.*;

/* Command object for "add reservation" command */
public class AddReservationCommand extends ReservationCommand{
private int reservationNumber;
private String description;

public AddReservationCommand(int reservationNumber, String description) {
this.reservationNumber = reservationNumber;
this.description = description;
}

/**
* Adds a reservation into the list.
*
* @param reservations Existing reservation list.
*/
@Override
public void execute(ReservationList reservations) {
// TODO: may have delimiter missing exception
// name
int namePos = description.indexOf(RES_PERSON_MARKER);
int nameEndPos = description.indexOf(DELIMITER, namePos);
String name = description.substring(namePos + RES_PERSON_MARKER.length(), nameEndPos + 1).trim();

// date
int datePos = description.indexOf(RES_DATE_MARKER);
int dateEndPos = description.indexOf(DELIMITER, datePos);
LocalDate date = LocalDate.parse(description.substring(datePos + RES_DATE_MARKER.length(), dateEndPos + 1).trim(),
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));

// numberOfGuests
int numberPos = description.indexOf(RES_NUM_MARKER);
int numberEndPos = description.indexOf(DELIMITER, numberPos);
int numberOfGuests = Integer.parseInt(description.substring(numberPos + RES_NUM_MARKER.length(), numberEndPos + 1).trim());

// contact
int contactPos = description.indexOf(RES_CONTACT_MARKER);
int contactEndPos = description.indexOf(DELIMITER, contactPos);
String contact = description.substring(contactPos + RES_CONTACT_MARKER.length(), contactEndPos + 1).trim();

// comments
int commentsPos = description.indexOf(RES_COMMENT_MARKER);
int commentsEndPos = description.indexOf(DELIMITER, commentsPos);
String comments = description.substring(commentsPos + RES_COMMENT_MARKER.length(), commentsEndPos + 1).trim();

// reservationNumber
int reservationNumber = reservations.getSize();

Reservation reservation = new Reservation(reservationNumber, name, date, numberOfGuests, contact);
reservations.addReservation(reservation);

// TODO: display some message
}
}
19 changes: 19 additions & 0 deletions src/main/java/seedu/duke/commands/ListReservationCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package seedu.duke.commands;

import seedu.duke.reservation.ReservationList;

/* Command object for "list reservations" command */
public class ListReservationCommand extends ReservationCommand {
/**
* Lists all reservations, including served, unserved, and invalid reservations.
*
* @param reservations Existing reservation list.
*/
@Override
public void execute(ReservationList reservations) {
// TODO: wrap it into Ui class
for (int i = 1; i <= reservations.getSize(); i++) {
System.out.println(reservations.getReservation(i));
}
}
}
25 changes: 25 additions & 0 deletions src/main/java/seedu/duke/commands/ListServedCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package seedu.duke.commands;

import seedu.duke.reservation.ReservationList;

import static seedu.duke.utils.Constants.SERVED;

/* Command object for "list served reservations" command */
public class ListServedCommand extends ReservationCommand {
/**
* Lists all served reservations.
*
* @param reservations Existing reservation list.
*/
@Override
public void execute(ReservationList reservations) {
// TODO: wrap it into Ui class
for (int i = 1; i <= reservations.getSize(); i++) {
if (!reservations.getReservation(i).getStatus().equals(SERVED)) {
continue;
}

System.out.println(reservations.getReservation(i));
}
}
}
25 changes: 25 additions & 0 deletions src/main/java/seedu/duke/commands/ListUnservedCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package seedu.duke.commands;

import seedu.duke.reservation.ReservationList;

import static seedu.duke.utils.Constants.NOT_SERVED;

/* Command object for "list unserved reservations" command */
public class ListUnservedCommand extends ReservationCommand {
/**
* Lists all unserved reservations.
*
* @param reservations Existing reservation list.
*/
@Override
public void execute(ReservationList reservations) {
// TODO: wrap it into Ui class
for (int i = 1; i <= reservations.getSize(); i++) {
if (!reservations.getReservation(i).getStatus().equals(NOT_SERVED)) {
continue;
}

System.out.println(reservations.getReservation(i));
}
}
}
33 changes: 33 additions & 0 deletions src/main/java/seedu/duke/commands/MarkReservationCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package seedu.duke.commands;

import seedu.duke.reservation.ReservationList;

import static seedu.duke.utils.Constants.DELIMITER;
import static seedu.duke.utils.Constants.RES_INDEX_MARKER;

/* Command object for "mark reservation" command */
public class MarkReservationCommand extends ReservationCommand {
private String description;

public MarkReservationCommand(String description) {
this.description = description;
}

/**
* Specifies the index number of the target reservations.
* Marks the reservation as done.
*
* @param reservations Existing reservation list.
*/
@Override
public void execute(ReservationList reservations) {
// specifies the reservation number
int numberPos = description.indexOf(RES_INDEX_MARKER);
int numberEndPos = description.indexOf(DELIMITER, numberPos);
int reservationNumber = Integer.parseInt(description.substring(numberPos + RES_INDEX_MARKER.length(),
numberEndPos + 1).trim());

// mark the reservation as done
reservations.markReservationAsServed(reservationNumber);
}
}
7 changes: 7 additions & 0 deletions src/main/java/seedu/duke/commands/ReservationCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package seedu.duke.commands;

import seedu.duke.reservation.ReservationList;

public abstract class ReservationCommand {
public abstract void execute(ReservationList reservations);
}
33 changes: 33 additions & 0 deletions src/main/java/seedu/duke/commands/VoidReservationCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package seedu.duke.commands;

import seedu.duke.reservation.ReservationList;

import static seedu.duke.utils.Constants.DELIMITER;
import static seedu.duke.utils.Constants.RES_INDEX_MARKER;

/* Command object for "void reservation" command */
public class VoidReservationCommand extends ReservationCommand {
private String description;

public VoidReservationCommand(String description) {
this.description = description;
}

/**
* Specifies the index number of the target reservations.
* Marks the reservation as invalid in the case like reservation cancellation and etc.
*
* @param reservations Existing reservation list.
*/
@Override
public void execute(ReservationList reservations) {
// specifies the reservation number
int numberPos = description.indexOf(RES_INDEX_MARKER);
int numberEndPos = description.indexOf(DELIMITER, numberPos);
int reservationNumber = Integer.parseInt(description.substring(numberPos + RES_INDEX_MARKER.length(),
numberEndPos + 1).trim());

// voids the reservation
reservations.voidReservation(reservationNumber);
}
}
Loading

0 comments on commit 9ee8f83

Please sign in to comment.