updates
This commit is contained in:
@@ -39,7 +39,7 @@ public final class TestReservations {
|
|||||||
|
|
||||||
// 4. Request that Manager updates specific account’s files with data stored in
|
// 4. Request that Manager updates specific account’s files with data stored in
|
||||||
// memory
|
// memory
|
||||||
mgr.UpdateAccount(mgr.retrieveAccount(acct.account_number()));
|
mgr.UpdateAccount(acct);
|
||||||
// 5. Add draft lodging reservation to an account (if reservation object already
|
// 5. Add draft lodging reservation to an account (if reservation object already
|
||||||
// exists with the same reservation number, it is considered an error)
|
// exists with the same reservation number, it is considered an error)
|
||||||
|
|
||||||
@@ -52,10 +52,10 @@ public final class TestReservations {
|
|||||||
hotel.setSquareFeet(450);
|
hotel.setSquareFeet(450);
|
||||||
hotel.setReservation_start_date(ZonedDateTime.of(2025, 07, 05, 10, 0, 0, 0, ZoneId.of("UTC")));
|
hotel.setReservation_start_date(ZonedDateTime.of(2025, 07, 05, 10, 0, 0, 0, ZoneId.of("UTC")));
|
||||||
hotel.setReservation_end_date(ZonedDateTime.of(2025, 11, 30, 22, 0, 0, 0, ZoneId.of("UTC")));
|
hotel.setReservation_end_date(ZonedDateTime.of(2025, 11, 30, 22, 0, 0, 0, ZoneId.of("UTC")));
|
||||||
boolean success1 = mgr.addReservation(mgr.retrieveAccount(acct.account_number()), hotel);
|
boolean success1 = mgr.addReservation(acct, hotel);
|
||||||
assert success1;
|
assert success1;
|
||||||
|
|
||||||
mgr.UpdateAccount(mgr.retrieveAccount(acct.account_number()));
|
mgr.UpdateAccount(acct);
|
||||||
|
|
||||||
CabinReservation cabin = new CabinReservation();
|
CabinReservation cabin = new CabinReservation();
|
||||||
cabin.setPhysical_address(new Address("30 cabin ave", "Carnelian", "CA", "96140"));
|
cabin.setPhysical_address(new Address("30 cabin ave", "Carnelian", "CA", "96140"));
|
||||||
@@ -66,9 +66,11 @@ public final class TestReservations {
|
|||||||
cabin.setSquareFeet(806);
|
cabin.setSquareFeet(806);
|
||||||
cabin.setReservation_start_date(ZonedDateTime.of(2025, 07, 05, 10, 0, 0, 0, ZoneId.of("UTC")));
|
cabin.setReservation_start_date(ZonedDateTime.of(2025, 07, 05, 10, 0, 0, 0, ZoneId.of("UTC")));
|
||||||
cabin.setReservation_end_date(ZonedDateTime.of(2025, 11, 30, 22, 0, 0, 0, ZoneId.of("UTC")));
|
cabin.setReservation_end_date(ZonedDateTime.of(2025, 11, 30, 22, 0, 0, 0, ZoneId.of("UTC")));
|
||||||
boolean success2 = mgr.addReservation(mgr.retrieveAccount(acct.account_number()), cabin);
|
boolean success2 = mgr.addReservation(acct, cabin);
|
||||||
assert success2;
|
assert success2;
|
||||||
|
|
||||||
|
mgr.UpdateAccount(acct);
|
||||||
|
|
||||||
HouseReservation house = new HouseReservation();
|
HouseReservation house = new HouseReservation();
|
||||||
house.setPhysical_address(new Address("3000 Osage ave", "GreenBelt", "MD", "20740"));
|
house.setPhysical_address(new Address("3000 Osage ave", "GreenBelt", "MD", "20740"));
|
||||||
house.setMailing_address(new Address("40012 College ave", "College Park", "MD", "20740"));
|
house.setMailing_address(new Address("40012 College ave", "College Park", "MD", "20740"));
|
||||||
@@ -78,17 +80,21 @@ public final class TestReservations {
|
|||||||
house.setSquareFeet(1400);
|
house.setSquareFeet(1400);
|
||||||
house.setReservation_start_date(ZonedDateTime.of(2025, 07, 05, 10, 0, 0, 0, ZoneId.of("UTC")));
|
house.setReservation_start_date(ZonedDateTime.of(2025, 07, 05, 10, 0, 0, 0, ZoneId.of("UTC")));
|
||||||
house.setReservation_end_date(ZonedDateTime.of(2025, 11, 30, 22, 0, 0, 0, ZoneId.of("UTC")));
|
house.setReservation_end_date(ZonedDateTime.of(2025, 11, 30, 22, 0, 0, 0, ZoneId.of("UTC")));
|
||||||
boolean success3 = mgr.addReservation(mgr.retrieveAccount(acct.account_number()), house);
|
boolean success3 = mgr.addReservation(acct, house);
|
||||||
assert success3;
|
assert success3;
|
||||||
|
|
||||||
Reservation rsrv = (Reservation) cabin;
|
mgr.UpdateAccount(acct);
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
assert mgr.addReservation(acct, cabin);
|
mgr.addReservation(acct, cabin);
|
||||||
|
mgr.UpdateAccount(mgr.retrieveAccount(acct.account_number()));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("Error: cabin already in list.");
|
System.out.println(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
mgr.UpdateAccount(mgr.retrieveAccount(acct.account_number()));
|
Account account = mgr.retrieveLoadedAccounts().getFirst();
|
||||||
|
Reservation rsrv = account.getReservation_list().getLast();
|
||||||
|
|
||||||
// 6. Complete reservation that is associated with an account
|
// 6. Complete reservation that is associated with an account
|
||||||
rsrv = mgr.retreiveReservation(cabin.getReservation_number());
|
rsrv = mgr.retreiveReservation(cabin.getReservation_number());
|
||||||
|
|||||||
@@ -52,8 +52,9 @@ public final class AccomodationManager {
|
|||||||
return acct;
|
return acct;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean addReservation(final Account account, final Reservation reservation) {
|
public boolean addReservation(final Account account, final Reservation reservation) throws ReservationException {
|
||||||
return account.add(reservation);
|
boolean result = account.add(reservation);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Reservation retreiveReservation(String reservation_number) {
|
public Reservation retreiveReservation(String reservation_number) {
|
||||||
|
|||||||
@@ -8,13 +8,17 @@ import java.nio.file.Path;
|
|||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
public class Account {
|
public class Account {
|
||||||
String account_number="-99";
|
String account_number = "-99";
|
||||||
String phone_number;
|
String phone_number;
|
||||||
Address mailing_address;
|
Address mailing_address;
|
||||||
EmailAddress email_address;
|
EmailAddress email_address;
|
||||||
|
|
||||||
AccountReservationList reservation_list = new AccountReservationList();;
|
AccountReservationList reservation_list = new AccountReservationList();;
|
||||||
|
|
||||||
|
public AccountReservationList getReservation_list() {
|
||||||
|
return reservation_list;
|
||||||
|
}
|
||||||
|
|
||||||
public Account(
|
public Account(
|
||||||
String account_number,
|
String account_number,
|
||||||
String phone_number,
|
String phone_number,
|
||||||
@@ -26,7 +30,7 @@ public class Account {
|
|||||||
this.email_address = email_address;
|
this.email_address = email_address;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Account(){
|
public Account() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,18 +42,22 @@ public class Account {
|
|||||||
sb.append("\"account_number\": \"" + account_number + "\",");
|
sb.append("\"account_number\": \"" + account_number + "\",");
|
||||||
sb.append("\"phone_number\": \"" + phone_number + "\",");
|
sb.append("\"phone_number\": \"" + phone_number + "\",");
|
||||||
sb.append("\"mailing_address\": " + mailing_address + ",");
|
sb.append("\"mailing_address\": " + mailing_address + ",");
|
||||||
sb.append("\"email_address\": " + email_address + "," );
|
sb.append("\"email_address\": " + email_address + ",");
|
||||||
sb.append( this.reservation_list.toString());
|
sb.append(this.reservation_list.toString());
|
||||||
sb.append("}}");
|
sb.append("}}");
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean add(Reservation rsrv){
|
public boolean add(Reservation rsrv) throws ReservationException {
|
||||||
return reservation_list.add(rsrv);
|
boolean result = reservation_list.add(rsrv);
|
||||||
|
try{
|
||||||
|
if(!result){
|
||||||
|
throw new ReservationException("Error Reservation already exists.");
|
||||||
|
}} catch(ReservationException e){
|
||||||
|
}finally{}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// @TODO Write Account out in JSON
|
|
||||||
public static void Write(Account acct) throws IOException {
|
public static void Write(Account acct) throws IOException {
|
||||||
String dataRoot = DataRepository.getPath();
|
String dataRoot = DataRepository.getPath();
|
||||||
dataRoot = dataRoot + "/acc-" + acct.account_number + ".json";
|
dataRoot = dataRoot + "/acc-" + acct.account_number + ".json";
|
||||||
@@ -60,7 +68,7 @@ public class Account {
|
|||||||
writer.flush();
|
writer.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Reservation r: acct.reservation_list){
|
for (Reservation r : acct.reservation_list) {
|
||||||
r.Write(r);
|
r.Write(r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,11 +9,13 @@ public class AccountReservationList extends ArrayList<Reservation> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean add(final Reservation reservation) {
|
public boolean add(final Reservation reservation) {
|
||||||
if (this.contains(reservation)){
|
boolean result = true;
|
||||||
return false;
|
for(Reservation rsrv: this){
|
||||||
|
result = rsrv.getReservation_number() == reservation.getReservation_number();
|
||||||
|
if(result) return result;
|
||||||
}
|
}
|
||||||
reservation.reservation_number = AccountReservationList.reservationSerial(reservation);
|
reservation.reservation_number = AccountReservationList.reservationSerial(reservation);
|
||||||
return super.add(reservation);
|
return result = super.add(reservation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package lodge.reservationsystem;
|
package lodge.reservationsystem;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
|
||||||
|
|
||||||
public final class CabinReservation extends Reservation{
|
public final class CabinReservation extends Reservation{
|
||||||
|
|
||||||
public final String ReservationType() {
|
public final String ReservationType() {
|
||||||
|
|||||||
@@ -205,17 +205,6 @@ public abstract class Reservation{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @TODO read reservation out in json
|
|
||||||
public void Read(Reservation reservation) throws IOException {
|
|
||||||
String dataRoot = DataRepository.getPath();
|
|
||||||
dataRoot = dataRoot + "/rsv-" + reservation.reservation_number + ".json";
|
|
||||||
Path path = Paths.get(dataRoot);
|
|
||||||
|
|
||||||
try (BufferedReader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) {
|
|
||||||
reader.lines();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public float calculatePricePerNight() {
|
public float calculatePricePerNight() {
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|||||||
12
src/java/lodge/reservationsystem/ReservationException.java
Normal file
12
src/java/lodge/reservationsystem/ReservationException.java
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
package lodge.reservationsystem;
|
||||||
|
|
||||||
|
class ReservationException extends Exception {
|
||||||
|
public ReservationException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReservationException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user