forked from nus-cs2113-AY1920S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Construct the basic structure for "add reservation", "mark reservatio…
…n", "void reservation", "list reservations", "list served reservations", "list unserved reservations".
- Loading branch information
Showing
11 changed files
with
487 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
63
src/main/java/seedu/duke/commands/AddReservationCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
src/main/java/seedu/duke/commands/ListReservationCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
25
src/main/java/seedu/duke/commands/ListUnservedCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
33
src/main/java/seedu/duke/commands/MarkReservationCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
33
src/main/java/seedu/duke/commands/VoidReservationCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.