fixups
This commit is contained in:
@@ -54,7 +54,7 @@ public final class TestReservations {
|
|||||||
hotel.setNumberOfBedRooms(1);
|
hotel.setNumberOfBedRooms(1);
|
||||||
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, 07, 07, 22, 0, 0, 0, ZoneId.of("UTC")));
|
||||||
mgr.addReservation(acct, hotel);
|
mgr.addReservation(acct, hotel);
|
||||||
|
|
||||||
mgr.UpdateAccount(acct);
|
mgr.UpdateAccount(acct);
|
||||||
@@ -89,8 +89,8 @@ public final class TestReservations {
|
|||||||
house.setNumberOfFloors(3);
|
house.setNumberOfFloors(3);
|
||||||
house.setNumberOfBedRooms(3);
|
house.setNumberOfBedRooms(3);
|
||||||
house.setSquareFeet(1400);
|
house.setSquareFeet(1400);
|
||||||
house.setReservation_start_date(ZonedDateTime.of(2025, 9, 5, 10, 0, 0, 0, ZoneId.of("UTC")));
|
house.setReservation_start_date(ZonedDateTime.of(2025, 11, 5, 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, 15, 22, 0, 0, 0, ZoneId.of("UTC")));
|
||||||
mgr.addReservation(acct, house);
|
mgr.addReservation(acct, house);
|
||||||
|
|
||||||
mgr.UpdateAccount(acct);
|
mgr.UpdateAccount(acct);
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ public final class AccomodationManager {
|
|||||||
return acct;
|
return acct;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean addReservation(final Account account, final Reservation reservation) throws ReservationException {
|
public boolean addReservation(final Account account, final Reservation reservation){
|
||||||
boolean result = account.add(reservation);
|
boolean result = account.add(reservation);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
package lodge.reservationsystem;
|
|
||||||
|
|
||||||
class AccountException extends Exception {
|
|
||||||
public AccountException() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public AccountException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -9,7 +9,7 @@ public class AccountReservationList extends ArrayList<Reservation> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean add(final Reservation reservation) {
|
public boolean add(final Reservation reservation) throws RuntimeException{
|
||||||
boolean result = true;
|
boolean result = true;
|
||||||
Reservation rsrv = this.find(reservation.getReservation_number());
|
Reservation rsrv = this.find(reservation.getReservation_number());
|
||||||
if( rsrv != null ){
|
if( rsrv != null ){
|
||||||
@@ -18,11 +18,12 @@ public class AccountReservationList extends ArrayList<Reservation> {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
result = reservation.checkValid();
|
result = reservation.checkValid();
|
||||||
} catch (ReservationException ex) {
|
} catch (RuntimeException ex) {
|
||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
if(result){
|
if(result){
|
||||||
reservation.setReservation_number(AccountReservationList.reservationSerial(reservation));
|
reservation.setReservation_number(AccountReservationList.reservationSerial(reservation));
|
||||||
|
reservation.setPrice(reservation.calculatePrice());
|
||||||
result = super.add(reservation);
|
result = super.add(reservation);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -36,6 +36,10 @@ public final class CabinReservation extends Reservation {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float getPricePerNight() {
|
||||||
|
return 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
//calculate and return the reservation's price
|
//calculate and return the reservation's price
|
||||||
// Cabin price plus additional fee of $20 for full kitchen and $5 for each additional bathroom
|
// Cabin price plus additional fee of $20 for full kitchen and $5 for each additional bathroom
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package lodge.reservationsystem;
|
package lodge.reservationsystem;
|
||||||
|
|
||||||
|
import java.time.LocalTime;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
|
|
||||||
@@ -8,7 +9,7 @@ public final class HotelReservation extends Reservation {
|
|||||||
HotelReservation() {
|
HotelReservation() {
|
||||||
super();
|
super();
|
||||||
setType('H');
|
setType('H');
|
||||||
setNumberOfBeds( 2 );
|
setNumberOfBeds(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HotelReservation(final Address physical_address) {
|
public HotelReservation(final Address physical_address) {
|
||||||
@@ -16,7 +17,7 @@ public final class HotelReservation extends Reservation {
|
|||||||
setNumberOfBedRooms(1);
|
setNumberOfBedRooms(1);
|
||||||
setNumberOfBathRooms(1);
|
setNumberOfBathRooms(1);
|
||||||
setNumberOfFloors(1);
|
setNumberOfFloors(1);
|
||||||
setKitchen(KitchenEnum.Kitchenette );
|
setKitchen(KitchenEnum.Kitchenette);
|
||||||
this.setPhysical_address(new Address());
|
this.setPhysical_address(new Address());
|
||||||
this.getPhysical_address().setStreet(physical_address.getStreet());
|
this.getPhysical_address().setStreet(physical_address.getStreet());
|
||||||
this.getPhysical_address().setCity(physical_address.getCity());
|
this.getPhysical_address().setCity(physical_address.getCity());
|
||||||
@@ -51,14 +52,22 @@ public final class HotelReservation extends Reservation {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float getPricePerNight() {
|
||||||
|
return 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
// calculate and return the reservation's price
|
// calculate and return the reservation's price
|
||||||
// Hotel price plus additional flat fee of $50 plus $10 for kitchenette
|
// Hotel price plus additional flat fee of $50 plus $10 for kitchenette
|
||||||
@Override
|
@Override
|
||||||
public float calculatePrice() {
|
public float calculatePrice() {
|
||||||
ZonedDateTime enddt = getReservation_end_date().truncatedTo(ChronoUnit.DAYS);
|
ZonedDateTime enddt = getReservation_end_date().truncatedTo(ChronoUnit.DAYS);
|
||||||
ZonedDateTime startdt = getReservation_start_date().truncatedTo(ChronoUnit.DAYS);
|
ZonedDateTime startdt = getReservation_start_date().truncatedTo(ChronoUnit.DAYS);
|
||||||
long days = ChronoUnit.DAYS.between( startdt ,enddt);
|
long days = ChronoUnit.DAYS.between(startdt, enddt);
|
||||||
days = ( days < 2 ) ? 1: days - 1;
|
|
||||||
|
ZonedDateTime checkOutTime = enddt.with(LocalTime.of(12, 0));
|
||||||
|
if(getReservation_end_date().isBefore(checkOutTime)){
|
||||||
|
days = days-1;
|
||||||
|
}
|
||||||
|
|
||||||
float calcprice = (getSquareFeet() > 900.0f) ? 120.0f + 15.0f : 120.0f;
|
float calcprice = (getSquareFeet() > 900.0f) ? 120.0f + 15.0f : 120.0f;
|
||||||
if (getKitchen() == KitchenEnum.FullKitchen) {
|
if (getKitchen() == KitchenEnum.FullKitchen) {
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import java.time.temporal.ChronoUnit;
|
|||||||
|
|
||||||
public final class HouseReservation extends Reservation {
|
public final class HouseReservation extends Reservation {
|
||||||
|
|
||||||
HouseReservation(){
|
HouseReservation() {
|
||||||
super();
|
super();
|
||||||
this.setType( 'Z' );
|
this.setType('Z');
|
||||||
}
|
}
|
||||||
|
|
||||||
public HouseReservation(final Address physical_address) {
|
public HouseReservation(final Address physical_address) {
|
||||||
@@ -15,7 +15,7 @@ public final class HouseReservation extends Reservation {
|
|||||||
setNumberOfBedRooms(1);
|
setNumberOfBedRooms(1);
|
||||||
setNumberOfBathRooms(1);
|
setNumberOfBathRooms(1);
|
||||||
setNumberOfFloors(1);
|
setNumberOfFloors(1);
|
||||||
setKitchen(KitchenEnum.Kitchenette );
|
setKitchen(KitchenEnum.Kitchenette);
|
||||||
this.setPhysical_address(new Address());
|
this.setPhysical_address(new Address());
|
||||||
this.getPhysical_address().setStreet(physical_address.getStreet());
|
this.getPhysical_address().setStreet(physical_address.getStreet());
|
||||||
this.getPhysical_address().setCity(physical_address.getCity());
|
this.getPhysical_address().setCity(physical_address.getCity());
|
||||||
@@ -39,18 +39,18 @@ public final class HouseReservation extends Reservation {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getPricePerNight(){
|
// House price plus additional flat fee for additional space per day
|
||||||
|
public float getPricePerNight() {
|
||||||
return (getSquareFeet() > 900.0f) ? 120.0f + 15.0f : 120.0f;
|
return (getSquareFeet() > 900.0f) ? 120.0f + 15.0f : 120.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculate and return the reservation's price
|
// calculate and return the reservation's price
|
||||||
// Hotel price plus additional flat fee of $50 plus $10 for kitchenette
|
|
||||||
@Override
|
@Override
|
||||||
public float calculatePrice() {
|
public float calculatePrice() {
|
||||||
ZonedDateTime enddt = getReservation_end_date().truncatedTo(ChronoUnit.DAYS);
|
ZonedDateTime enddt = getReservation_end_date().truncatedTo(ChronoUnit.DAYS);
|
||||||
ZonedDateTime startdt = getReservation_start_date().truncatedTo(ChronoUnit.DAYS);
|
ZonedDateTime startdt = getReservation_start_date().truncatedTo(ChronoUnit.DAYS);
|
||||||
long days = ChronoUnit.DAYS.between( startdt ,enddt);
|
long days = ChronoUnit.DAYS.between(startdt, enddt);
|
||||||
days = ( days < 2 ) ? 1: days - 1;
|
days = (days < 2) ? 1 : days - 1;
|
||||||
float calcprice = getPricePerNight() * days;
|
float calcprice = getPricePerNight() * days;
|
||||||
return calcprice;
|
return calcprice;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -256,6 +256,7 @@ public abstract class Reservation{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public abstract String ReservationType();
|
public abstract String ReservationType();
|
||||||
|
public abstract float getPricePerNight();
|
||||||
public abstract float calculatePrice();
|
public abstract float calculatePrice();
|
||||||
public abstract boolean checkValid() throws ReservationException;
|
public abstract boolean checkValid();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
package lodge.reservationsystem;
|
|
||||||
|
|
||||||
class ReservationException extends Exception {
|
|
||||||
public ReservationException() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ReservationException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1 +1,33 @@
|
|||||||
{ "HotelReservation":{"reservation_type": "HotelReservation","reservation_number": "R0123077641","reservation_status": "Draft","reservation_start_date": "2025-07-05T10:00Z[UTC]","reservation_end_date": "2025-11-30T22:00Z[UTC]","account_number": "A1450981765","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"}},"kitchen": "Kitchenette","numberOfBeds": "2","numberOfBedRooms": "1","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_end_date": "2025-07-07T22:00Z[UTC]",
|
||||||
|
"account_number": "A1450981765",
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"kitchen": "Kitchenette",
|
||||||
|
"numberOfBeds": "2",
|
||||||
|
"numberOfBedRooms": "1",
|
||||||
|
"numberOfBathRooms": "1",
|
||||||
|
"numberOfFloors": "1",
|
||||||
|
"squareFeet": "450",
|
||||||
|
"price": "290.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1 +1 @@
|
|||||||
{ "HouseReservation":{"reservation_type": "HouseReservation","reservation_number": "R0499811708","reservation_status": "Completed","reservation_start_date": "2025-09-05T10:00Z[UTC]","reservation_end_date": "2025-11-30T22:00Z[UTC]","account_number": "A1450981765","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"}},"kitchen": "Kitchenette","numberOfBeds": "4","numberOfBedRooms": "3","numberOfBathRooms": "1","numberOfFloors": "3","squareFeet": "1400","price": "11475.0"}}
|
{ "HouseReservation":{"reservation_type": "HouseReservation","reservation_number": "R0499811708","reservation_status": "Completed","reservation_start_date": "2025-11-05T10:00Z[UTC]","reservation_end_date": "2025-11-15T22:00Z[UTC]","account_number": "A1450981765","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"}},"kitchen": "Kitchenette","numberOfBeds": "4","numberOfBedRooms": "3","numberOfBathRooms": "1","numberOfFloors": "3","squareFeet": "1400","price": "1215.0"}}
|
||||||
@@ -1 +1 @@
|
|||||||
{ "CabinReservation":{"reservation_type": "CabinReservation","reservation_number": "R0535276622","reservation_status": "Draft","reservation_start_date": "2025-09-05T10:00Z[UTC]","reservation_end_date": "2025-11-30T22:00Z[UTC]","account_number": "A1450981765","physical_address": { "Address":{"street": "40 cabin ave","city": "Carnelian","state": "CA","zip": "96140"}},"mailing_address": { "Address":{"street": "40 cabin ave","city": "Carnelian Bay","state": "CA","zip": "96140"}},"kitchen": "Kitchenette","numberOfBeds": "4","numberOfBedRooms": "3","numberOfBathRooms": "1","numberOfFloors": "2","squareFeet": "806","price": "120.0"}}
|
{ "CabinReservation":{"reservation_type": "CabinReservation","reservation_number": "R0535276622","reservation_status": "Draft","reservation_start_date": "2025-09-05T10:00Z[UTC]","reservation_end_date": "2025-11-30T22:00Z[UTC]","account_number": "A1450981765","physical_address": { "Address":{"street": "40 cabin ave","city": "Carnelian","state": "CA","zip": "96140"}},"mailing_address": { "Address":{"street": "40 cabin ave","city": "Carnelian Bay","state": "CA","zip": "96140"}},"kitchen": "Kitchenette","numberOfBeds": "4","numberOfBedRooms": "3","numberOfBathRooms": "1","numberOfFloors": "2","squareFeet": "806","price": "10200.0"}}
|
||||||
@@ -1 +1 @@
|
|||||||
{ "CabinReservation":{"reservation_type": "CabinReservation","reservation_number": "R2042828431","reservation_status": "Draft","reservation_start_date": "2025-09-05T10:00Z[UTC]","reservation_end_date": "2025-11-30T22:00Z[UTC]","account_number": "A2074212339","physical_address": { "Address":{"street": "30 cabin ave","city": "Carnelian","state": "CA","zip": "96140"}},"mailing_address": { "Address":{"street": "30 cabin ave","city": "Carnelian Bay","state": "CA","zip": "96140"}},"kitchen": "Kitchenette","numberOfBeds": "4","numberOfBedRooms": "3","numberOfBathRooms": "1","numberOfFloors": "2","squareFeet": "806","price": "120.0"}}
|
{ "CabinReservation":{"reservation_type": "CabinReservation","reservation_number": "R2042828431","reservation_status": "Draft","reservation_start_date": "2025-09-05T10:00Z[UTC]","reservation_end_date": "2025-11-30T22:00Z[UTC]","account_number": "A2074212339","physical_address": { "Address":{"street": "30 cabin ave","city": "Carnelian","state": "CA","zip": "96140"}},"mailing_address": { "Address":{"street": "30 cabin ave","city": "Carnelian Bay","state": "CA","zip": "96140"}},"kitchen": "Kitchenette","numberOfBeds": "4","numberOfBedRooms": "3","numberOfBathRooms": "1","numberOfFloors": "2","squareFeet": "806","price": "10200.0"}}
|
||||||
Reference in New Issue
Block a user