updates
This commit is contained in:
@@ -11,6 +11,7 @@ import lodge.reservationsystem.CabinReservation;
|
||||
import lodge.reservationsystem.HouseReservation;
|
||||
import lodge.reservationsystem.HotelReservation;
|
||||
import lodge.reservationsystem.Reservation;
|
||||
import lodge.reservationsystem.ReservationStatusEnum;
|
||||
|
||||
public final class TestReservations {
|
||||
public static void main(String[] args) throws Exception {
|
||||
@@ -43,12 +44,11 @@ public final class TestReservations {
|
||||
// 5. Add draft lodging reservation to an account (if reservation object already
|
||||
// exists with the same reservation number, it is considered an error)
|
||||
|
||||
HotelReservation hotel = new HotelReservation();
|
||||
hotel.setPhysical_address(new Address("400 hotel ave", "Maryland City", "CA", "20723"));
|
||||
HotelReservation hotel = new HotelReservation(new Address("400 hotel ave", "Maryland City", "CA", "20723"));
|
||||
hotel.setMailing_address(new Address("400 hotel ave", "Maryland City", "MD", "20723"));
|
||||
hotel.setNumberOfBeds(3);
|
||||
hotel.setNumberOfBeds(2);
|
||||
hotel.setNumberOfFloors(1);
|
||||
hotel.setNumberOfBedRooms(2);
|
||||
hotel.setNumberOfBedRooms(1);
|
||||
hotel.setSquareFeet(450);
|
||||
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")));
|
||||
@@ -57,28 +57,26 @@ public final class TestReservations {
|
||||
|
||||
mgr.UpdateAccount(acct);
|
||||
|
||||
CabinReservation cabin = new CabinReservation();
|
||||
cabin.setPhysical_address(new Address("30 cabin ave", "Carnelian", "CA", "96140"));
|
||||
CabinReservation cabin = new CabinReservation(new Address("30 cabin ave", "Carnelian", "CA", "96140"));
|
||||
cabin.setMailing_address(new Address("40 cabin ave", "Carnelian Bay", "CA", "96140"));
|
||||
cabin.setNumberOfBeds(4);
|
||||
cabin.setNumberOfFloors(2);
|
||||
cabin.setNumberOfBedRooms(3);
|
||||
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, 9, 05, 10, 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(acct, cabin);
|
||||
assert success2;
|
||||
|
||||
mgr.UpdateAccount(acct);
|
||||
|
||||
HouseReservation house = new HouseReservation();
|
||||
house.setPhysical_address(new Address("3000 Osage ave", "GreenBelt", "MD", "20740"));
|
||||
HouseReservation house = new HouseReservation(new Address("3000 Osage ave", "GreenBelt", "MD", "20740"));
|
||||
house.setMailing_address(new Address("40012 College ave", "College Park", "MD", "20740"));
|
||||
house.setNumberOfBeds(4);
|
||||
house.setNumberOfFloors(3);
|
||||
house.setNumberOfBedRooms(3);
|
||||
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, 9, 5, 10, 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(acct, house);
|
||||
assert success3;
|
||||
@@ -98,13 +96,12 @@ public final class TestReservations {
|
||||
|
||||
// 6. Complete reservation that is associated with an account
|
||||
rsrv = mgr.retreiveReservation(cabin.getReservation_number());
|
||||
rsrv.Complete();
|
||||
|
||||
rsrv.Change(rsrv, ReservationStatusEnum.Completed);
|
||||
mgr.UpdateAccount(mgr.retrieveAccount(acct.account_number()));
|
||||
|
||||
// 7. Cancel reservation that is associated with an account
|
||||
rsrv = mgr.retreiveReservation(cabin.getReservation_number());
|
||||
rsrv.Cancel();
|
||||
rsrv.Change(rsrv, ReservationStatusEnum.Canceled);
|
||||
mgr.UpdateAccount(mgr.retrieveAccount(acct.account_number()));
|
||||
/*
|
||||
*
|
||||
|
||||
@@ -67,4 +67,5 @@ public final class AccomodationManager {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -49,12 +49,20 @@ public class Account {
|
||||
}
|
||||
|
||||
public boolean add(Reservation rsrv) throws ReservationException {
|
||||
boolean result = reservation_list.add(rsrv);
|
||||
try{
|
||||
if(!result){
|
||||
throw new ReservationException("Error Reservation already exists.");
|
||||
}} catch(ReservationException e){
|
||||
}finally{}
|
||||
boolean result = false;
|
||||
try {
|
||||
rsrv.checkValid();
|
||||
result = reservation_list.add(rsrv);
|
||||
|
||||
if (!result) {
|
||||
throw new ReservationException("Error Reservation already exists.");
|
||||
}
|
||||
} catch (ReservationException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,41 @@
|
||||
package lodge.reservationsystem;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
public final class CabinReservation extends Reservation{
|
||||
|
||||
public CabinReservation(Address physical_address) {
|
||||
numberOfBeds = 1;
|
||||
kitchen = KitchenEnum.Kitchenette;
|
||||
this.physical_address = physical_address;
|
||||
}
|
||||
|
||||
public final String ReservationType() {
|
||||
type='C';
|
||||
return "CabinReservation";
|
||||
}
|
||||
|
||||
public boolean checkValid() throws IllegalArgumentException {
|
||||
boolean result = false;
|
||||
result = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
//calculate and return the reservation's price
|
||||
// Cabin price plus additional fee of $20 for full kitchen and $5 for each additional bathroom
|
||||
public float calculatePrice() {
|
||||
price = (squareFeet > 900.0f) ? price + 15.0f : price;
|
||||
ZonedDateTime enddt = reservation_end_date.truncatedTo(ChronoUnit.DAYS);
|
||||
ZonedDateTime startdt = reservation_start_date.truncatedTo(ChronoUnit.DAYS);
|
||||
long days = ChronoUnit.DAYS.between( startdt ,enddt);
|
||||
price = (squareFeet > 900.0f) ? 120.0f + 15.0f : 120.0f;
|
||||
if ( kitchen == KitchenEnum.FullKitchen ){
|
||||
price = price + 20.0f ;
|
||||
}
|
||||
if( numberOfBathRooms > 1 ){
|
||||
price = price + (numberOfBathRooms * 5.0f);
|
||||
}
|
||||
price = price * days;
|
||||
return price;
|
||||
}
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ final class DataRepository {
|
||||
case "CabinReservation":
|
||||
jsonReader.beginObject();
|
||||
name = jsonReader.nextName();
|
||||
CabinReservation cabin = new CabinReservation();
|
||||
CabinReservation cabin = new CabinReservation(ad);
|
||||
cabin.setMailing_address(ad);
|
||||
cabin.setPhysical_address(ad);
|
||||
cabin.reservation_number = jsonReader.nextString();
|
||||
@@ -127,7 +127,7 @@ final class DataRepository {
|
||||
case "HouseReservation":
|
||||
jsonReader.beginObject();
|
||||
name = jsonReader.nextName();
|
||||
HouseReservation house = new HouseReservation();
|
||||
HouseReservation house = new HouseReservation(ad);
|
||||
house.setMailing_address(ad);
|
||||
house.setPhysical_address(ad);
|
||||
house.reservation_number = jsonReader.nextString();
|
||||
@@ -136,7 +136,7 @@ final class DataRepository {
|
||||
case "HotelReservation":
|
||||
jsonReader.beginObject();
|
||||
name = jsonReader.nextName();
|
||||
HotelReservation hotel = new HotelReservation();
|
||||
HotelReservation hotel = new HotelReservation(ad);
|
||||
hotel.setMailing_address(ad);
|
||||
hotel.setPhysical_address(ad);
|
||||
hotel.reservation_number = jsonReader.nextString();
|
||||
|
||||
@@ -1,16 +1,50 @@
|
||||
package lodge.reservationsystem;
|
||||
|
||||
public final class HotelReservation extends Reservation{
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
public final class HotelReservation extends Reservation {
|
||||
|
||||
public HotelReservation(Address physical_address) {
|
||||
numberOfBeds = 2;
|
||||
numberOfBedRooms = 1;
|
||||
numberOfBathRooms = 1;
|
||||
kitchen = KitchenEnum.None;
|
||||
this.physical_address = physical_address;
|
||||
}
|
||||
|
||||
public final String ReservationType() {
|
||||
type = 'H';
|
||||
return "HotelReservation";
|
||||
}
|
||||
|
||||
//calculate and return the reservation's price
|
||||
// Hotel price plus additional flat fee of $50 plus $10 for kitchenette
|
||||
public boolean checkValid() throws IllegalArgumentException {
|
||||
boolean result = false;
|
||||
if (numberOfBathRooms != 1) {
|
||||
throw new IllegalArgumentException("not valid, Baths");
|
||||
}
|
||||
if (numberOfBedRooms != 1) {
|
||||
throw new IllegalArgumentException("not valid, BedRooms");
|
||||
}
|
||||
if (numberOfBeds != 2) {
|
||||
throw new IllegalArgumentException("not valid, Beds");
|
||||
}
|
||||
result = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
// calculate and return the reservation's price
|
||||
// Hotel price plus additional flat fee of $50 plus $10 for kitchenette
|
||||
public float calculatePrice() {
|
||||
// flat fee
|
||||
return 0.0f;
|
||||
ZonedDateTime enddt = reservation_end_date.truncatedTo(ChronoUnit.DAYS);
|
||||
ZonedDateTime startdt = reservation_start_date.truncatedTo(ChronoUnit.DAYS);
|
||||
long days = ChronoUnit.DAYS.between( startdt ,enddt);
|
||||
price = (squareFeet > 900.0f) ? 120.0f + 15.0f : 120.0f;
|
||||
if ( kitchen == KitchenEnum.FullKitchen ){
|
||||
price = price + 10.0f ;
|
||||
}
|
||||
price = price * days;
|
||||
price = price + 50.0f;
|
||||
return price;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,27 @@
|
||||
package lodge.reservationsystem;
|
||||
|
||||
public final class HouseReservation extends Reservation{
|
||||
public final class HouseReservation extends Reservation {
|
||||
|
||||
public HouseReservation(Address physical_address) {
|
||||
numberOfBeds = 2;
|
||||
numberOfBedRooms = 1;
|
||||
numberOfBathRooms = 1;
|
||||
numberOfFloors = 1;
|
||||
kitchen = KitchenEnum.FullKitchen;
|
||||
this.physical_address = physical_address;
|
||||
}
|
||||
|
||||
public final String ReservationType() {
|
||||
type = 'Z';
|
||||
return "HouseReservation";
|
||||
}
|
||||
|
||||
public boolean checkValid() throws IllegalArgumentException {
|
||||
boolean result = false;
|
||||
result = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
// calculate and return the reservation's price
|
||||
public float calculatePrice() {
|
||||
return 0.0f;
|
||||
|
||||
6
src/java/lodge/reservationsystem/KitchenEnum.java
Normal file
6
src/java/lodge/reservationsystem/KitchenEnum.java
Normal file
@@ -0,0 +1,6 @@
|
||||
package lodge.reservationsystem;
|
||||
|
||||
public enum KitchenEnum {
|
||||
None, Kitchenette, FullKitchen;
|
||||
|
||||
}
|
||||
@@ -1,26 +1,25 @@
|
||||
package lodge.reservationsystem;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.Instant;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
public abstract class Reservation{
|
||||
public abstract class Reservation {
|
||||
char type;
|
||||
String reservation_number;
|
||||
String reservation_number = "-99";
|
||||
Address physical_address;
|
||||
Address mailing_address;
|
||||
|
||||
ZonedDateTime reservation_start_date;
|
||||
ZonedDateTime reservation_end_date;
|
||||
ReservationStatus reservation_status;
|
||||
ReservationStatusEnum reservation_status;
|
||||
|
||||
Boolean hasKitchenette;
|
||||
KitchenEnum kitchen;
|
||||
Integer numberOfBeds;
|
||||
Integer numberOfBedRooms;
|
||||
Integer numberOfBathRooms;
|
||||
@@ -29,6 +28,18 @@ public abstract class Reservation{
|
||||
|
||||
Float price;
|
||||
|
||||
protected Reservation() {
|
||||
numberOfBeds = 1;
|
||||
numberOfBedRooms = 1;
|
||||
numberOfBathRooms = 1;
|
||||
numberOfFloors = 1;
|
||||
kitchen = KitchenEnum.None;
|
||||
price = 120.0f;
|
||||
reservation_status = ReservationStatusEnum.Draft;
|
||||
mailing_address = null;
|
||||
physical_address = null;
|
||||
}
|
||||
|
||||
public String getReservation_number() {
|
||||
return reservation_number;
|
||||
}
|
||||
@@ -69,11 +80,11 @@ public abstract class Reservation{
|
||||
this.reservation_end_date = reservation_end_date;
|
||||
}
|
||||
|
||||
public ReservationStatus reservation_status() {
|
||||
public ReservationStatusEnum reservation_status() {
|
||||
return reservation_status;
|
||||
}
|
||||
|
||||
public void setReservation_status(ReservationStatus reservation_status) {
|
||||
public void setReservation_status(ReservationStatusEnum reservation_status) {
|
||||
this.reservation_status = reservation_status;
|
||||
}
|
||||
|
||||
@@ -125,27 +136,6 @@ public abstract class Reservation{
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public Reservation() {
|
||||
numberOfBeds = 1;
|
||||
numberOfBedRooms = 1;
|
||||
numberOfBathRooms = 1;
|
||||
numberOfFloors = 1;
|
||||
price = 120.0f;
|
||||
reservation_status = ReservationStatus.Draft;
|
||||
}
|
||||
|
||||
public void Draft() {
|
||||
this.reservation_status = ReservationStatus.Draft;
|
||||
}
|
||||
|
||||
public void Cancel() {
|
||||
this.reservation_status = ReservationStatus.Canceled;
|
||||
}
|
||||
|
||||
public void Complete() {
|
||||
this.reservation_status = ReservationStatus.Completed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
@@ -205,6 +195,26 @@ public abstract class Reservation{
|
||||
}
|
||||
}
|
||||
|
||||
public void Change(Reservation reservation, ReservationStatusEnum newStatus) throws IllegalStateException {
|
||||
try {
|
||||
if (reservation.reservation_status == ReservationStatusEnum.Completed) {
|
||||
if (newStatus == ReservationStatusEnum.Canceled) {
|
||||
throw new IllegalStateException ("Invalid Change, reservation has completed.");
|
||||
}
|
||||
if (ZonedDateTime.now().compareTo(this.reservation_start_date) > -1) {
|
||||
throw new IllegalStateException ("Invalid Change, reservation started.");
|
||||
}
|
||||
}
|
||||
|
||||
if (newStatus == ReservationStatusEnum.Completed) {
|
||||
this.setPrice(this.calculatePrice());
|
||||
}
|
||||
reservation.setReservation_status(newStatus);
|
||||
} catch (IllegalStateException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public float calculatePricePerNight() {
|
||||
return 0.0f;
|
||||
}
|
||||
@@ -212,5 +222,6 @@ public abstract class Reservation{
|
||||
public abstract String ReservationType();
|
||||
|
||||
public abstract float calculatePrice();
|
||||
}
|
||||
|
||||
public abstract boolean checkValid() throws Exception;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package lodge.reservationsystem;
|
||||
|
||||
public enum ReservationStatus {
|
||||
public enum ReservationStatusEnum {
|
||||
Draft,
|
||||
Canceled,
|
||||
Completed
|
||||
@@ -1 +1 @@
|
||||
{ "HotelReservation":{"reservation_type": "HotelReservation","reservation_number": "R0123077641","reservation_status": "Draft","reservation_start_date": "2025-07-05T10:00Z[UTC]","reservation_start_date": "2025-11-30T22:00Z[UTC]","physical_address": "{ "Address":{"street": "400 hotel ave","city": "Maryland City","state": "CA","zip": "20723"}}","mailing_address": "{ "Address":{"street": "400 hotel ave","city": "Maryland City","state": "MD","zip": "20723"}}","numberOfBeds": "3","numberOfBedRooms": "2","numberOfBathRooms": "1","numberOfFloors": "1","squareFeet": "450","price": "120.0"}}
|
||||
{ "HotelReservation":{"reservation_type": "HotelReservation","reservation_number": "R0123077641","reservation_status": "Draft","reservation_start_date": "2025-07-05T10:00Z[UTC]","reservation_start_date": "2025-11-30T22:00Z[UTC]","physical_address": "{ "Address":{"street": "400 hotel ave","city": "Maryland City","state": "CA","zip": "20723"}}","mailing_address": "{ "Address":{"street": "400 hotel ave","city": "Maryland City","state": "MD","zip": "20723"}}","numberOfBeds": "2","numberOfBedRooms": "1","numberOfBathRooms": "1","numberOfFloors": "1","squareFeet": "450","price": "120.0"}}
|
||||
@@ -1 +1 @@
|
||||
{ "HouseReservation":{"reservation_type": "HouseReservation","reservation_number": "R0499811708","reservation_status": "Draft","reservation_start_date": "2025-07-05T10:00Z[UTC]","reservation_start_date": "2025-11-30T22:00Z[UTC]","physical_address": "{ "Address":{"street": "3000 Osage ave","city": "GreenBelt","state": "MD","zip": "20740"}}","mailing_address": "{ "Address":{"street": "40012 College ave","city": "College Park","state": "MD","zip": "20740"}}","numberOfBeds": "4","numberOfBedRooms": "3","numberOfBathRooms": "1","numberOfFloors": "3","squareFeet": "1400","price": "120.0"}}
|
||||
{ "HouseReservation":{"reservation_type": "HouseReservation","reservation_number": "R0499811708","reservation_status": "Draft","reservation_start_date": "2025-09-05T10:00Z[UTC]","reservation_start_date": "2025-11-30T22:00Z[UTC]","physical_address": "{ "Address":{"street": "3000 Osage ave","city": "GreenBelt","state": "MD","zip": "20740"}}","mailing_address": "{ "Address":{"street": "40012 College ave","city": "College Park","state": "MD","zip": "20740"}}","numberOfBeds": "4","numberOfBedRooms": "3","numberOfBathRooms": "1","numberOfFloors": "3","squareFeet": "1400","price": "120.0"}}
|
||||
@@ -1 +1 @@
|
||||
{ "CabinReservation":{"reservation_type": "CabinReservation","reservation_number": "R2042828431","reservation_status": "Canceled","reservation_start_date": "2025-07-05T10:00Z[UTC]","reservation_start_date": "2025-11-30T22:00Z[UTC]","physical_address": "{ "Address":{"street": "30 cabin ave","city": "Carnelian","state": "CA","zip": "96140"}}","mailing_address": "{ "Address":{"street": "40 cabin ave","city": "Carnelian Bay","state": "CA","zip": "96140"}}","numberOfBeds": "4","numberOfBedRooms": "3","numberOfBathRooms": "1","numberOfFloors": "2","squareFeet": "806","price": "120.0"}}
|
||||
{ "CabinReservation":{"reservation_type": "CabinReservation","reservation_number": "R2042828431","reservation_status": "Completed","reservation_start_date": "2025-09-05T10:00Z[UTC]","reservation_start_date": "2025-11-30T22:00Z[UTC]","physical_address": "{ "Address":{"street": "30 cabin ave","city": "Carnelian","state": "CA","zip": "96140"}}","mailing_address": "{ "Address":{"street": "40 cabin ave","city": "Carnelian Bay","state": "CA","zip": "96140"}}","numberOfBeds": "4","numberOfBedRooms": "3","numberOfBathRooms": "1","numberOfFloors": "2","squareFeet": "806","price": "10320.0"}}
|
||||
Reference in New Issue
Block a user