updates,constructors
This commit is contained in:
@@ -111,18 +111,18 @@ public final class TestReservations {
|
||||
|
||||
Reservation rsrv = account.findReservation(house.getReservation_number());
|
||||
// 6. Complete reservation that is associated with an account
|
||||
rsrv = mgr.retreiveReservation(rsrv.getReservation_number());
|
||||
rsrv.Change(rsrv, ReservationStatusEnum.Completed);
|
||||
mgr.retreiveReservation(house.getReservation_number());
|
||||
house.Change(house, ReservationStatusEnum.Completed);
|
||||
mgr.UpdateAccount(mgr.retrieveAccount(acct.getAccount_number()));
|
||||
|
||||
// 7. Cancel reservation that is associated with an account
|
||||
rsrv = mgr.retreiveReservation(rsrv.getReservation_number());
|
||||
rsrv.Change(rsrv, ReservationStatusEnum.Canceled);
|
||||
mgr.retreiveReservation(house.getReservation_number());
|
||||
house.Change(house, ReservationStatusEnum.Canceled);
|
||||
mgr.UpdateAccount(mgr.retrieveAccount(acct.getAccount_number()));
|
||||
|
||||
// 8. Change reservation values that can be changed (if reservation is
|
||||
// cancelled, completed, or for past date, it is considered an error)
|
||||
rsrv.update(rsrv);
|
||||
house.update(house);
|
||||
|
||||
// 9. Request for price per night to be calculated and returned for a
|
||||
// per night
|
||||
@@ -130,8 +130,8 @@ public final class TestReservations {
|
||||
|
||||
// 10. Request for total reservation price to be calculated and returned for
|
||||
// specific reservation
|
||||
rsrv = account.findReservation(house.getReservation_number());
|
||||
rsrv.calculatePrice();
|
||||
account.findReservation(house.getReservation_number());
|
||||
house.calculatePrice();
|
||||
|
||||
mgr.showReservationList();
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
*/
|
||||
package lodge.reservationsystem;
|
||||
|
||||
import java.util.List;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
|
||||
public final class AccomodationManager {
|
||||
|
||||
@@ -66,7 +66,7 @@ public final class AccomodationManager {
|
||||
throws Exception {
|
||||
Account acct = null;
|
||||
try {
|
||||
acct = AccountList.newAccount(phone_number, mailing_address, email_address);
|
||||
acct = new Account(phone_number, mailing_address, email_address);
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.toString());
|
||||
}
|
||||
|
||||
@@ -33,8 +33,15 @@ public class Account {
|
||||
this.email_address = email_address;
|
||||
}
|
||||
|
||||
public Account(String phone_number, Address mailing_address, EmailAddress email_address) {
|
||||
this(AccountList.accountSerial(phone_number, mailing_address, email_address),
|
||||
phone_number,
|
||||
mailing_address,
|
||||
email_address);
|
||||
}
|
||||
|
||||
private final AccountReservationList reservation_list = new AccountReservationList();;
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -60,9 +67,9 @@ public class Account {
|
||||
System.out.println(String.format("%s", e.getMessage()));
|
||||
} finally {
|
||||
}
|
||||
if(result){
|
||||
/* add account number to reservation for tracking purposes */
|
||||
rsrv.setAccountNumber( this.account_number );
|
||||
if (result) {
|
||||
/* add account number to reservation for tracking purposes */
|
||||
rsrv.setAccountNumber(this.account_number);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -123,7 +130,7 @@ public class Account {
|
||||
}
|
||||
|
||||
public Reservation findReservation(String reservation_number) {
|
||||
return this.reservation_list.find(reservation_number);
|
||||
return this.reservation_list.find(reservation_number);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,16 +20,6 @@ public class AccountList extends ArrayList<Account> {
|
||||
return String.format("A%09d", Math.abs(java.util.Objects.hash(phone_number, mailing_address, email_address)));
|
||||
}
|
||||
|
||||
public static Account newAccount(String phone_number, Address mailing_address, EmailAddress email_address)
|
||||
throws Exception {
|
||||
Account A = new Account(AccountList.accountSerial(phone_number, mailing_address, email_address),
|
||||
phone_number,
|
||||
mailing_address,
|
||||
email_address);
|
||||
|
||||
return A;
|
||||
}
|
||||
|
||||
// ** Add account throw error if account number is pre-existing. */
|
||||
@Override
|
||||
public synchronized boolean add(final Account account)
|
||||
@@ -70,7 +60,7 @@ public class AccountList extends ArrayList<Account> {
|
||||
}
|
||||
|
||||
public List<? extends Reservation> getListOfReservations() {
|
||||
ArrayList<Reservation> readList = new ArrayList<Reservation>();
|
||||
ArrayList<Reservation> readList = new ArrayList<>();
|
||||
for (Account acct: this){
|
||||
ListIterator<Reservation> itr = acct.getAllReservations();
|
||||
while( itr.hasNext() ){
|
||||
|
||||
@@ -13,22 +13,21 @@ public class AccountReservationList extends ArrayList<Reservation> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(final Reservation reservation) throws RuntimeException{
|
||||
public synchronized boolean add(final Reservation reservation) throws RuntimeException{
|
||||
boolean result = true;
|
||||
Reservation rsrv = this.find(reservation.getReservation_number());
|
||||
if( rsrv != null ){
|
||||
result = false;
|
||||
result = rsrv == null;
|
||||
if( !result ){
|
||||
throw new DuplicateObjectException(String.format("Error No Dups, Reservation exists: %s.", rsrv.getReservation_number()));
|
||||
}
|
||||
try {
|
||||
result = reservation.checkValid();
|
||||
} catch (RuntimeException ex) {
|
||||
result = false;
|
||||
}
|
||||
result = reservation.checkValid();
|
||||
|
||||
if(result){
|
||||
reservation.setReservation_number(AccountReservationList.reservationSerial(reservation));
|
||||
reservation.setPrice(reservation.calculatePrice());
|
||||
result = super.add(reservation);
|
||||
}else{
|
||||
throw new IllegalArgumentException(String.format("error reservation invalid: %s", reservation.getReservation_number()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -11,15 +11,19 @@ public final class Address{
|
||||
String state;
|
||||
String zip;
|
||||
|
||||
/** not used
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
private Address() {
|
||||
}
|
||||
|
||||
public Address(String street, String city, String state, String zip) {
|
||||
this.street = street;
|
||||
this.city = city;
|
||||
this.state = state;
|
||||
this.zip = zip;
|
||||
}
|
||||
|
||||
protected Address() {
|
||||
}
|
||||
|
||||
public String getStreet() {
|
||||
return street;
|
||||
|
||||
@@ -9,20 +9,20 @@ import java.time.temporal.ChronoUnit;
|
||||
|
||||
public final class CabinReservation extends Reservation {
|
||||
|
||||
CabinReservation(){
|
||||
super();
|
||||
protected CabinReservation() {
|
||||
setType('C');
|
||||
}
|
||||
public CabinReservation(final Address physical_address) {
|
||||
setNumberOfBeds( 1);
|
||||
setKitchen( KitchenEnum.Kitchenette );
|
||||
this.setPhysical_address(new Address());
|
||||
this.getPhysical_address().setStreet(physical_address.getStreet());
|
||||
this.getPhysical_address().setCity(physical_address.getCity());
|
||||
this.getPhysical_address().setState(physical_address.getState());
|
||||
this.getPhysical_address().setZip(physical_address.getZip());
|
||||
this.setNumberOfBeds(1);
|
||||
this.setKitchen(KitchenEnum.Kitchenette);
|
||||
}
|
||||
|
||||
public CabinReservation(final Address physical_address) {
|
||||
this();
|
||||
this.setPhysical_address(
|
||||
new Address(physical_address.getStreet(), physical_address.getCity(), physical_address.getState(),
|
||||
physical_address.getZip()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String ReservationType() {
|
||||
return "CabinReservation";
|
||||
}
|
||||
@@ -31,33 +31,35 @@ public final class CabinReservation extends Reservation {
|
||||
public boolean checkValid() throws IllegalArgumentException {
|
||||
boolean result = false;
|
||||
if (getPhysical_address() == null) {
|
||||
throw new IllegalArgumentException("not valid, physical_address");
|
||||
throw new IllegalArgumentException(String.format("not valid, physical_address %s", this.getReservation_number()));
|
||||
}
|
||||
if (getMailing_address() == null) {
|
||||
throw new IllegalArgumentException("not valid, mailing_address");
|
||||
throw new IllegalArgumentException(String.format("not valid, mailing_address: %s", this.getReservation_number()));
|
||||
}
|
||||
result = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public float getPricePerNight() {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
//calculate and return the reservation's price
|
||||
// Cabin price plus additional fee of $20 for full kitchen and $5 for each additional bathroom
|
||||
// calculate and return the reservation's price
|
||||
// Cabin price plus additional fee of $20 for full kitchen and $5 for each
|
||||
// additional bathroom
|
||||
@Override
|
||||
public float calculatePrice() {
|
||||
ZonedDateTime enddt = getReservation_end_date().truncatedTo(ChronoUnit.DAYS);
|
||||
ZonedDateTime startdt = getReservation_start_date().truncatedTo(ChronoUnit.DAYS);
|
||||
long days = ChronoUnit.DAYS.between( startdt ,enddt);
|
||||
days = ( days < 2 ) ? 1: days - 1;
|
||||
float calcprice = (getSquareFeet() > 900.0f) ? 120.0f + 15.0f : 120.0f;
|
||||
if ( getKitchen() == KitchenEnum.FullKitchen ){
|
||||
long days = ChronoUnit.DAYS.between(startdt, enddt);
|
||||
days = (days < 2) ? 1 : days - 1;
|
||||
float calcprice = (getSquareFeet() > 900.0f) ? 120.0f + 15.0f : 120.0f;
|
||||
if (getKitchen() == KitchenEnum.FullKitchen) {
|
||||
calcprice = calcprice + 20.0f;
|
||||
}
|
||||
if( getNumberOfBathRooms() > 1 ){
|
||||
setPrice( getPrice() + (getNumberOfBathRooms() * 5.0f));
|
||||
if (getNumberOfBathRooms() > 1) {
|
||||
setPrice(getPrice() + (getNumberOfBathRooms() * 5.0f));
|
||||
}
|
||||
calcprice = calcprice * days;
|
||||
return calcprice;
|
||||
|
||||
@@ -91,18 +91,17 @@ final class DataRepository {
|
||||
break;
|
||||
case "Address":
|
||||
jsonReader.beginObject();
|
||||
Address ad = new Address();
|
||||
jsonReader.nextName();
|
||||
ad.setStreet(jsonReader.nextString());
|
||||
String mstreet = jsonReader.nextString();
|
||||
jsonReader.nextName();
|
||||
ad.setCity(jsonReader.nextString());
|
||||
String mcity = jsonReader.nextString();
|
||||
jsonReader.nextName();
|
||||
ad.setState(jsonReader.nextString());
|
||||
String mstate = jsonReader.nextString();
|
||||
jsonReader.nextName();
|
||||
ad.setZip(jsonReader.nextString());
|
||||
String mzip = jsonReader.nextString();
|
||||
jsonReader.endObject();
|
||||
jsonReader.endObject();
|
||||
ac.setMailing_address(ad);
|
||||
ac.setMailing_address(new Address(mstreet, mcity, mstate, mzip));
|
||||
break;
|
||||
case "email_address":
|
||||
jsonReader.beginObject();
|
||||
@@ -145,7 +144,7 @@ final class DataRepository {
|
||||
}
|
||||
|
||||
private static void loadReservation(Account ac, String reservationType,
|
||||
String reservationNumber) throws IOException {
|
||||
String reservationNumber) throws NullPointerException, IOException {
|
||||
String filename = String.format("rsv-%s.json", reservationNumber);
|
||||
Path basePath = Paths.get(getPath());
|
||||
Path resolvedPath = basePath.resolve(filename);
|
||||
@@ -175,34 +174,32 @@ final class DataRepository {
|
||||
jsonReader.nextName();
|
||||
jsonReader.beginObject();
|
||||
jsonReader.nextName();
|
||||
Address adP = new Address();
|
||||
adP.setStreet(jsonReader.nextString());
|
||||
String street = jsonReader.nextString();
|
||||
jsonReader.nextName();
|
||||
adP.setCity(jsonReader.nextString());
|
||||
String city = jsonReader.nextString();
|
||||
jsonReader.nextName();
|
||||
adP.setState(jsonReader.nextString());
|
||||
String state = jsonReader.nextString();
|
||||
jsonReader.nextName();
|
||||
adP.setZip(jsonReader.nextString());
|
||||
String zip =jsonReader.nextString();
|
||||
jsonReader.endObject();
|
||||
jsonReader.endObject();
|
||||
rsrv.setPhysical_address(adP);
|
||||
rsrv.setPhysical_address(new Address(street, city, state, zip));
|
||||
break;
|
||||
case "mailing_address":
|
||||
jsonReader.beginObject();
|
||||
jsonReader.nextName();
|
||||
jsonReader.beginObject();
|
||||
jsonReader.nextName();
|
||||
Address adM = new Address();
|
||||
adM.setStreet(jsonReader.nextString());
|
||||
String mstreet = jsonReader.nextString();
|
||||
jsonReader.nextName();
|
||||
adM.setCity(jsonReader.nextString());
|
||||
String mcity = jsonReader.nextString();
|
||||
jsonReader.nextName();
|
||||
adM.setState(jsonReader.nextString());
|
||||
String mstate = jsonReader.nextString();
|
||||
jsonReader.nextName();
|
||||
adM.setZip(jsonReader.nextString());
|
||||
String mzip =jsonReader.nextString();
|
||||
jsonReader.endObject();
|
||||
jsonReader.endObject();
|
||||
rsrv.setMailing_address(adM);
|
||||
rsrv.setMailing_address(new Address(mstreet, mcity, mstate, mzip));
|
||||
break;
|
||||
case "reservation_type":
|
||||
jsonReader.nextString();
|
||||
|
||||
@@ -10,23 +10,21 @@ import java.time.temporal.ChronoUnit;
|
||||
|
||||
public final class HotelReservation extends Reservation {
|
||||
|
||||
HotelReservation() {
|
||||
super();
|
||||
setType('H');
|
||||
setNumberOfBeds(2);
|
||||
protected HotelReservation() {
|
||||
this.setType('H');
|
||||
this.setNumberOfBeds(2);
|
||||
this.setNumberOfBeds(2);
|
||||
this.setNumberOfBedRooms(1);
|
||||
this.setNumberOfBathRooms(1);
|
||||
this.setNumberOfFloors(1);
|
||||
this.setKitchen(KitchenEnum.Kitchenette);
|
||||
}
|
||||
|
||||
public HotelReservation(final Address physical_address) {
|
||||
setNumberOfBeds(2);
|
||||
setNumberOfBedRooms(1);
|
||||
setNumberOfBathRooms(1);
|
||||
setNumberOfFloors(1);
|
||||
setKitchen(KitchenEnum.Kitchenette);
|
||||
this.setPhysical_address(new Address());
|
||||
this.getPhysical_address().setStreet(physical_address.getStreet());
|
||||
this.getPhysical_address().setCity(physical_address.getCity());
|
||||
this.getPhysical_address().setState(physical_address.getState());
|
||||
this.getPhysical_address().setZip(physical_address.getZip());
|
||||
this();
|
||||
this.setPhysical_address(
|
||||
new Address(physical_address.getStreet(), physical_address.getCity(), physical_address.getState(),
|
||||
physical_address.getZip()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -47,15 +45,16 @@ public final class HotelReservation extends Reservation {
|
||||
throw new IllegalArgumentException("not valid, Beds");
|
||||
}
|
||||
if (getPhysical_address() == null) {
|
||||
throw new IllegalArgumentException("not valid, physical_address");
|
||||
throw new IllegalArgumentException(String.format("not valid, physical_address %s", this.getReservation_number()));
|
||||
}
|
||||
if (getMailing_address() == null) {
|
||||
throw new IllegalArgumentException("not valid, mailing_address");
|
||||
throw new IllegalArgumentException(String.format("not valid, mailing_address: %s", this.getReservation_number()));
|
||||
}
|
||||
result = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPricePerNight() {
|
||||
return 0.0f;
|
||||
}
|
||||
@@ -69,8 +68,8 @@ public final class HotelReservation extends Reservation {
|
||||
long days = ChronoUnit.DAYS.between(startdt, enddt);
|
||||
|
||||
ZonedDateTime checkOutTime = enddt.with(LocalTime.of(12, 0));
|
||||
if(getReservation_end_date().isBefore(checkOutTime)){
|
||||
days = days-1;
|
||||
if (getReservation_end_date().isBefore(checkOutTime)) {
|
||||
days = days - 1;
|
||||
}
|
||||
|
||||
float calcprice = (getSquareFeet() > 900.0f) ? 120.0f + 15.0f : 120.0f;
|
||||
|
||||
@@ -9,41 +9,42 @@ import java.time.temporal.ChronoUnit;
|
||||
|
||||
public final class HouseReservation extends Reservation {
|
||||
|
||||
HouseReservation() {
|
||||
super();
|
||||
protected HouseReservation() {
|
||||
this.setType('Z');
|
||||
this.setNumberOfBeds(2);
|
||||
this.setNumberOfBedRooms(1);
|
||||
this.setNumberOfBathRooms(1);
|
||||
this.setNumberOfFloors(1);
|
||||
this.setKitchen(KitchenEnum.Kitchenette);
|
||||
}
|
||||
|
||||
public HouseReservation(final Address physical_address) {
|
||||
setNumberOfBeds(2);
|
||||
setNumberOfBedRooms(1);
|
||||
setNumberOfBathRooms(1);
|
||||
setNumberOfFloors(1);
|
||||
setKitchen(KitchenEnum.Kitchenette);
|
||||
this.setPhysical_address(new Address());
|
||||
this.getPhysical_address().setStreet(physical_address.getStreet());
|
||||
this.getPhysical_address().setCity(physical_address.getCity());
|
||||
this.getPhysical_address().setState(physical_address.getState());
|
||||
this.getPhysical_address().setZip(physical_address.getZip());
|
||||
this();
|
||||
this.setPhysical_address(
|
||||
new Address(physical_address.getStreet(), physical_address.getCity(), physical_address.getState(),
|
||||
physical_address.getZip()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String ReservationType() {
|
||||
return "HouseReservation";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkValid() throws IllegalArgumentException {
|
||||
boolean result = false;
|
||||
if (getPhysical_address() == null) {
|
||||
throw new IllegalArgumentException("not valid, physical_address");
|
||||
throw new IllegalArgumentException(String.format("not valid, physical_address %s", this.getReservation_number()));
|
||||
}
|
||||
if (getMailing_address() == null) {
|
||||
throw new IllegalArgumentException("not valid, mailing_address");
|
||||
throw new IllegalArgumentException(String.format("not valid, mailing_address: %s", this.getReservation_number()));
|
||||
}
|
||||
result = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
// House price plus additional flat fee for additional space per day
|
||||
@Override
|
||||
public float getPricePerNight() {
|
||||
return (getSquareFeet() > 900.0f) ? 120.0f + 15.0f : 120.0f;
|
||||
}
|
||||
|
||||
0
src/resources/acc-A1450981765.json
Executable file → Normal file
0
src/resources/acc-A1450981765.json
Executable file → Normal file
0
src/resources/rsv-R0123077641.json
Executable file → Normal file
0
src/resources/rsv-R0123077641.json
Executable file → Normal file
0
src/resources/rsv-R0499811708.json
Executable file → Normal file
0
src/resources/rsv-R0499811708.json
Executable file → Normal file
0
src/resources/rsv-R2042828431.json
Executable file → Normal file
0
src/resources/rsv-R2042828431.json
Executable file → Normal file
Reference in New Issue
Block a user