changes
This commit is contained in:
@@ -8,16 +8,17 @@ package lodge;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
import lodge.data.Account;
|
||||
import lodge.data.Address;
|
||||
import lodge.data.DuplicateObjectException;
|
||||
import lodge.data.EmailAddress;
|
||||
import lodge.data.Reservation;
|
||||
import lodge.data.ReservationStatusEnum;
|
||||
import lodge.reservationsystem.AccomodationManager;
|
||||
import lodge.reservationsystem.Account;
|
||||
import lodge.reservationsystem.Address;
|
||||
import lodge.reservationsystem.CabinReservation;
|
||||
import lodge.reservationsystem.DuplicateObjectException;
|
||||
import lodge.reservationsystem.EmailAddress;
|
||||
import lodge.reservationsystem.HotelReservation;
|
||||
import lodge.reservationsystem.HouseReservation;
|
||||
import lodge.reservationsystem.Reservation;
|
||||
import lodge.reservationsystem.ReservationStatusEnum;
|
||||
import lodge.reservationsystem.IReservation;
|
||||
|
||||
public final class TestReservations {
|
||||
public static void main(String[] args) throws Exception {
|
||||
@@ -101,27 +102,30 @@ public final class TestReservations {
|
||||
mgr.UpdateAccount(acct);
|
||||
|
||||
try {
|
||||
mgr.addReservation(acct, cabin);
|
||||
mgr.UpdateAccount(mgr.retrieveAccount(acct.getAccount_number()));
|
||||
if( mgr.addReservation(acct, cabin) ){
|
||||
mgr.UpdateAccount(mgr.retrieveAccount(acct.getAccount_number()));
|
||||
}
|
||||
} catch (DuplicateObjectException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
|
||||
Account account = mgr.retrieveLoadedAccounts().getFirst();
|
||||
Account account = mgr.retrieveLoadedAccounts().get(0);
|
||||
|
||||
Reservation rsrv = account.findReservation(house.getReservation_number());
|
||||
// 6. Complete reservation that is associated with an account
|
||||
mgr.retreiveReservation(house.getReservation_number());
|
||||
house.Change(house, ReservationStatusEnum.Completed);
|
||||
Reservation rsrv = account.findReservation(house.getReservation_number());
|
||||
house.Change(rsrv, ReservationStatusEnum.Completed);
|
||||
mgr.UpdateAccount(mgr.retrieveAccount(acct.getAccount_number()));
|
||||
|
||||
// 7. Cancel reservation that is associated with an account
|
||||
mgr.retreiveReservation(house.getReservation_number());
|
||||
house.Change(house, ReservationStatusEnum.Canceled);
|
||||
mgr.UpdateAccount(mgr.retrieveAccount(acct.getAccount_number()));
|
||||
account = mgr.retrieveLoadedAccounts().getLast();
|
||||
IReservation ir = account.getAllReservations().next();
|
||||
rsrv = (Reservation)ir;
|
||||
rsrv.Change(rsrv, ReservationStatusEnum.Canceled);
|
||||
mgr.UpdateAccount(mgr.retrieveAccount(rsrv.getAccountNumber()));
|
||||
|
||||
// 8. Change reservation values that can be changed (if reservation is
|
||||
// cancelled, completed, or for past date, it is considered an error)
|
||||
rsrv.Change(rsrv, ReservationStatusEnum.Completed);
|
||||
house.update(house);
|
||||
|
||||
// 9. Request for price per night to be calculated and returned for a
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* license: GPLv3
|
||||
* lodge.reservationsystem
|
||||
*/
|
||||
package lodge.reservationsystem;
|
||||
package lodge.data;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
@@ -12,11 +12,14 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ListIterator;
|
||||
|
||||
import lodge.reservationsystem.IReservation;
|
||||
|
||||
public class Account {
|
||||
private String account_number = "-99";
|
||||
private String phone_number;
|
||||
private Address mailing_address;
|
||||
private EmailAddress email_address;
|
||||
private final AccountReservationList reservations = new AccountReservationList();
|
||||
|
||||
protected Account() {
|
||||
|
||||
@@ -40,8 +43,6 @@ public class Account {
|
||||
email_address);
|
||||
}
|
||||
|
||||
private final AccountReservationList reservation_list = new AccountReservationList();;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -51,7 +52,7 @@ public class Account {
|
||||
sb.append("\"phone_number\": \"").append(phone_number).append("\",");
|
||||
sb.append("\"mailing_address\": ").append(mailing_address).append(",");
|
||||
sb.append("\"email_address\": ").append(email_address).append(",");
|
||||
sb.append(this.reservation_list.toString());
|
||||
sb.append(this.reservations.toString());
|
||||
sb.append("}}");
|
||||
return sb.toString();
|
||||
}
|
||||
@@ -62,7 +63,7 @@ public class Account {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
result = reservation_list.add(rsrv);
|
||||
result = reservations.add((IReservation) rsrv);
|
||||
} catch (DuplicateObjectException e) {
|
||||
System.out.println(String.format("%s", e.getMessage()));
|
||||
} finally {
|
||||
@@ -84,7 +85,8 @@ public class Account {
|
||||
writer.flush();
|
||||
}
|
||||
|
||||
for (Reservation r : acct.reservation_list) {
|
||||
for (IReservation i : acct.reservations) {
|
||||
Reservation r = (Reservation) i;
|
||||
r.Write(r);
|
||||
}
|
||||
}
|
||||
@@ -130,7 +132,7 @@ public class Account {
|
||||
}
|
||||
|
||||
public Reservation findReservation(String reservation_number) {
|
||||
return this.reservation_list.find(reservation_number);
|
||||
return this.reservations.find(reservation_number);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -156,8 +158,8 @@ public class Account {
|
||||
this.setMailing_address(acct.mailing_address);
|
||||
}
|
||||
|
||||
public ListIterator<Reservation> getAllReservations() {
|
||||
return this.reservation_list.listIterator();
|
||||
public ListIterator<IReservation> getAllReservations() {
|
||||
return this.reservations.listIterator();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
* license: GPLv3
|
||||
* lodge.reservationsystem
|
||||
*/
|
||||
package lodge.reservationsystem;
|
||||
package lodge.data;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@@ -10,7 +10,9 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
class AccountList extends ArrayList<Account> {
|
||||
import lodge.reservationsystem.IReservation;
|
||||
|
||||
public class AccountList extends ArrayList<Account> {
|
||||
|
||||
public static String accountSerial(String phone_number, Address mailing_address, EmailAddress email_address) {
|
||||
return String.format("A%09d", Math.abs(java.util.Objects.hash(phone_number, mailing_address, email_address)));
|
||||
@@ -51,10 +53,10 @@ class AccountList extends ArrayList<Account> {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<? extends Reservation> getListOfReservations() {
|
||||
ArrayList<Reservation> readList = new ArrayList<>();
|
||||
public List<? extends IReservation> getListOfReservations() {
|
||||
ArrayList<IReservation> readList = new ArrayList<>();
|
||||
for (Account acct: this){
|
||||
ListIterator<Reservation> itr = acct.getAllReservations();
|
||||
ListIterator<IReservation> itr = acct.getAllReservations();
|
||||
while( itr.hasNext() ){
|
||||
readList.add(itr.next());
|
||||
}
|
||||
@@ -2,32 +2,34 @@
|
||||
* license: GPLv3
|
||||
* lodge.reservationsystem
|
||||
*/
|
||||
package lodge.reservationsystem;
|
||||
package lodge.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
class AccountReservationList extends ArrayList<Reservation> {
|
||||
import lodge.reservationsystem.IReservation;
|
||||
|
||||
class AccountReservationList extends ArrayList<IReservation> {
|
||||
|
||||
private static String reservationSerial(Reservation reservation) {
|
||||
return String.format("R%010d", Math.abs(java.util.Objects.hash(reservation.getPhysical_address())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean add(final Reservation reservation) throws RuntimeException{
|
||||
public synchronized boolean add(final IReservation reservation) throws RuntimeException{
|
||||
boolean result = true;
|
||||
Reservation rsrv = this.find(reservation.getReservation_number());
|
||||
result = rsrv == null;
|
||||
if( !result ){
|
||||
throw new DuplicateObjectException(String.format("Error No Dups, Reservation exists: %s.", rsrv.getReservation_number()));
|
||||
}
|
||||
result = reservation.checkValid();
|
||||
result = ((IReservation)reservation).checkValid();
|
||||
|
||||
if(result){
|
||||
reservation.setReservation_number(AccountReservationList.reservationSerial(reservation));
|
||||
reservation.setPrice(reservation.calculatePrice());
|
||||
((Reservation)reservation).setReservation_number(AccountReservationList.reservationSerial((Reservation)reservation));
|
||||
((Reservation)reservation).setPrice(reservation.calculatePrice());
|
||||
result = super.add(reservation);
|
||||
}else{
|
||||
throw new IllegalArgumentException(String.format("error reservation invalid: %s", reservation.getReservation_number()));
|
||||
throw new IllegalArgumentException(String.format("error reservation invalid: %s", ((Reservation)reservation).getReservation_number()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -35,7 +37,7 @@ class AccountReservationList extends ArrayList<Reservation> {
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("\"reservation_list\":[");
|
||||
sb.append("\"reservations\":[");
|
||||
|
||||
for (int ix = 0; ix < this.size(); ix++) {
|
||||
String name = this.get(ix).ReservationType() + "";
|
||||
@@ -53,19 +55,19 @@ class AccountReservationList extends ArrayList<Reservation> {
|
||||
}
|
||||
|
||||
public Reservation find(String reservation_number) {
|
||||
for(Reservation rsrv: this){
|
||||
for(IReservation rsrv: this){
|
||||
if( rsrv.getReservation_number().compareTo(reservation_number) == 0 ){
|
||||
return rsrv;
|
||||
return (Reservation)rsrv;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void update(AccountReservationList incoming_reservation_list) {
|
||||
for (Reservation rsrv : incoming_reservation_list) {
|
||||
for (IReservation rsrv : incoming_reservation_list) {
|
||||
Reservation onListRsrv = find(rsrv.getReservation_number());
|
||||
if( onListRsrv != null ){
|
||||
onListRsrv.update(rsrv);
|
||||
onListRsrv.update((Reservation)rsrv);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
* license: GPLv3
|
||||
* lodge.reservationsystem
|
||||
*/
|
||||
package lodge.reservationsystem;
|
||||
package lodge.data;
|
||||
|
||||
public final class Address{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* license: GPLv3
|
||||
* lodge.reservationsystem
|
||||
*/
|
||||
package lodge.reservationsystem;
|
||||
package lodge.data;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
@@ -18,7 +18,12 @@ import java.time.ZonedDateTime;
|
||||
|
||||
import com.google.gson.stream.JsonReader;
|
||||
|
||||
final class DataRepository {
|
||||
import lodge.reservationsystem.AccomodationManager;
|
||||
import lodge.reservationsystem.CabinReservation;
|
||||
import lodge.reservationsystem.HotelReservation;
|
||||
import lodge.reservationsystem.HouseReservation;
|
||||
|
||||
public final class DataRepository {
|
||||
// SINGLETON CLASS
|
||||
// hard code data store location for storage of
|
||||
// account data files on filesystem
|
||||
@@ -37,6 +42,18 @@ final class DataRepository {
|
||||
return getInstance().directoryPath;
|
||||
}
|
||||
|
||||
public final static Reservation Reservation(String type) {
|
||||
switch (type) {
|
||||
case "HotelReservation":
|
||||
return HotelReservation.copy(type);
|
||||
case "HouseReservation":
|
||||
return HouseReservation.copy(type);
|
||||
case "CabinReservation":
|
||||
return CabinReservation.copy(type);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void WalkFileSystemTree(final AccomodationManager manager, final Path rootDir) throws IOException {
|
||||
Files.walkFileTree(rootDir, new SimpleFileVisitor<Path>() {
|
||||
@Override
|
||||
@@ -116,7 +133,7 @@ final class DataRepository {
|
||||
jsonReader.endObject();
|
||||
jsonReader.endObject();
|
||||
break;
|
||||
case "reservation_list":
|
||||
case "reservations":
|
||||
loadReservationRefList(jsonReader, ac);
|
||||
break;
|
||||
default:
|
||||
@@ -159,15 +176,15 @@ final class DataRepository {
|
||||
switch (name) {
|
||||
case "HotelReservation":
|
||||
jsonReader.beginObject();
|
||||
rsrv = new HotelReservation();
|
||||
rsrv = Reservation("HotelReservation");
|
||||
break;
|
||||
case "HouseReservation":
|
||||
jsonReader.beginObject();
|
||||
rsrv = new HouseReservation();
|
||||
rsrv = Reservation("HouseReservation");
|
||||
break;
|
||||
case "CabinReservation":
|
||||
jsonReader.beginObject();
|
||||
rsrv = new CabinReservation();
|
||||
rsrv = Reservation("CabinReservation");
|
||||
break;
|
||||
case "physical_address":
|
||||
jsonReader.beginObject();
|
||||
@@ -180,7 +197,7 @@ final class DataRepository {
|
||||
jsonReader.nextName();
|
||||
String state = jsonReader.nextString();
|
||||
jsonReader.nextName();
|
||||
String zip =jsonReader.nextString();
|
||||
String zip = jsonReader.nextString();
|
||||
jsonReader.endObject();
|
||||
jsonReader.endObject();
|
||||
rsrv.setPhysical_address(new Address(street, city, state, zip));
|
||||
@@ -196,7 +213,7 @@ final class DataRepository {
|
||||
jsonReader.nextName();
|
||||
String mstate = jsonReader.nextString();
|
||||
jsonReader.nextName();
|
||||
String mzip =jsonReader.nextString();
|
||||
String mzip = jsonReader.nextString();
|
||||
jsonReader.endObject();
|
||||
jsonReader.endObject();
|
||||
rsrv.setMailing_address(new Address(mstreet, mcity, mstate, mzip));
|
||||
@@ -2,7 +2,7 @@
|
||||
* license: GPLv3
|
||||
* lodge.reservationsystem
|
||||
*/
|
||||
package lodge.reservationsystem;
|
||||
package lodge.data;
|
||||
|
||||
public class DuplicateObjectException extends RuntimeException {
|
||||
public DuplicateObjectException() {
|
||||
@@ -2,7 +2,7 @@
|
||||
* license: GPLv3
|
||||
* lodge.reservationsystem
|
||||
*/
|
||||
package lodge.reservationsystem;
|
||||
package lodge.data;
|
||||
|
||||
public class EmailAddress{
|
||||
String email_address;
|
||||
@@ -2,7 +2,7 @@
|
||||
* license: GPLv3
|
||||
* lodge.reservationsystem
|
||||
*/
|
||||
package lodge.reservationsystem;
|
||||
package lodge.data;
|
||||
|
||||
public enum KitchenTypeEnum {
|
||||
None, Kitchenette, FullKitchen;
|
||||
@@ -2,7 +2,7 @@
|
||||
* license: GPLv3
|
||||
* lodge.reservationsystem
|
||||
*/
|
||||
package lodge.reservationsystem;
|
||||
package lodge.data;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
@@ -12,7 +12,10 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
public abstract class Reservation{
|
||||
import lodge.reservationsystem.IReservation;
|
||||
import lodge.reservationsystem.IllegalOperationException;
|
||||
|
||||
public abstract class Reservation {
|
||||
private char type;
|
||||
private String reservation_number = "-99";
|
||||
private Address physical_address;
|
||||
@@ -58,7 +61,7 @@ public abstract class Reservation{
|
||||
return this.accountNumber;
|
||||
}
|
||||
|
||||
protected void setAccountNumber(String account_number) {
|
||||
public void setAccountNumber(String account_number) {
|
||||
this.accountNumber = account_number;
|
||||
}
|
||||
|
||||
@@ -126,7 +129,7 @@ public abstract class Reservation{
|
||||
return type;
|
||||
}
|
||||
|
||||
protected void setType(char type) {
|
||||
public void setType(char type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@@ -202,8 +205,7 @@ public abstract class Reservation{
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append(String.format("{ \"%s\":{", ReservationType()));
|
||||
sb.append(String.format("{ \"%s\":{", this.ReservationType()));
|
||||
sb.append("\"reservation_type\": \"").append(ReservationType()).append("\",");
|
||||
sb.append("\"reservation_number\": \"").append(reservation_number).append("\",");
|
||||
sb.append("\"reservation_status\": \"").append(reservation_status).append("\",");
|
||||
@@ -237,17 +239,20 @@ public abstract class Reservation{
|
||||
|
||||
public void Change(Reservation reservation, ReservationStatusEnum newStatus) throws IllegalOperationException {
|
||||
try {
|
||||
if (reservation.reservation_status == ReservationStatusEnum.Completed) {
|
||||
if (reservation.reservation_status == ReservationStatusEnum.Completed ||
|
||||
reservation.reservation_status == ReservationStatusEnum.Canceled) {
|
||||
if (newStatus == ReservationStatusEnum.Canceled) {
|
||||
throw new IllegalOperationException("Invalid Change, reservation has completed.");
|
||||
throw new IllegalOperationException(
|
||||
String.format("Invalid Change, reservation has %s.", reservation.getReservation_status()));
|
||||
}
|
||||
if (ZonedDateTime.now().compareTo(this.reservation_start_date) > -1) {
|
||||
throw new IllegalOperationException("Invalid Change, reservation time started.");
|
||||
throw new IllegalOperationException("Invalid Change, reservation has begun.");
|
||||
}
|
||||
}
|
||||
|
||||
if (newStatus == ReservationStatusEnum.Completed) {
|
||||
this.setPrice(this.calculatePrice());
|
||||
IReservation irsrv = (IReservation) this;
|
||||
this.setPrice(irsrv.calculatePrice());
|
||||
}
|
||||
reservation.setReservation_status(newStatus);
|
||||
} catch (IllegalOperationException e) {
|
||||
@@ -260,7 +265,4 @@ public abstract class Reservation{
|
||||
}
|
||||
|
||||
public abstract String ReservationType();
|
||||
public abstract float getPricePerNight();
|
||||
public abstract float calculatePrice();
|
||||
public abstract boolean checkValid();
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
* license: GPLv3
|
||||
* lodge.reservationsystem
|
||||
*/
|
||||
package lodge.reservationsystem;
|
||||
package lodge.data;
|
||||
|
||||
public enum ReservationStatusEnum {
|
||||
Draft,
|
||||
@@ -6,12 +6,20 @@ package lodge.reservationsystem;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import lodge.data.Account;
|
||||
import lodge.data.AccountList;
|
||||
import lodge.data.Address;
|
||||
import lodge.data.DataRepository;
|
||||
import lodge.data.EmailAddress;
|
||||
import lodge.data.Reservation;
|
||||
|
||||
public final class AccomodationManager {
|
||||
|
||||
private final AccountList account_list = new AccountList();
|
||||
private final AccountList accounts = new AccountList();
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private AccomodationManager() {
|
||||
@@ -27,39 +35,39 @@ public final class AccomodationManager {
|
||||
}
|
||||
|
||||
public final void loadAll() throws Exception {
|
||||
account_list.clear();
|
||||
accounts.clear();
|
||||
// walk directories
|
||||
Path rootDir = Paths.get(DataRepository.getPath());
|
||||
DataRepository.WalkFileSystemTree(this, rootDir);
|
||||
System.out.println(String.format("%s LoadAll Accounts %d", "Deserializing", account_list.size()));
|
||||
System.out.println(String.format("%s LoadAll Accounts %d", "Deserializing", accounts.size()));
|
||||
}
|
||||
|
||||
// Load / Deserialize Account
|
||||
void load(Path file) throws Exception {
|
||||
public void load(Path file) throws Exception {
|
||||
|
||||
Account account = DataRepository.LoadAccount(file);
|
||||
if (account == null) {
|
||||
System.out.println(String.format("%s", file.toString()));
|
||||
} else {
|
||||
account_list.add(account);
|
||||
accounts.add(account);
|
||||
}
|
||||
}
|
||||
|
||||
public final List<Account> retrieveLoadedAccounts() {
|
||||
return Collections.unmodifiableList(account_list);
|
||||
return Collections.unmodifiableList(accounts);
|
||||
}
|
||||
|
||||
public Account retrieveAccount(String acct_id) {
|
||||
return account_list.find(acct_id);
|
||||
return accounts.find(acct_id);
|
||||
}
|
||||
|
||||
public synchronized void AddAccount(final Account acct) throws Exception {
|
||||
account_list.add(acct);
|
||||
accounts.add(acct);
|
||||
}
|
||||
|
||||
public synchronized void UpdateAccount(final Account acct) throws Exception {
|
||||
if( acct != null ){
|
||||
account_list.save(acct);
|
||||
accounts.save(acct);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +79,7 @@ public final class AccomodationManager {
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.toString());
|
||||
}
|
||||
account_list.save(acct);
|
||||
accounts.save(acct);
|
||||
return acct;
|
||||
}
|
||||
|
||||
@@ -80,22 +88,22 @@ public final class AccomodationManager {
|
||||
return result;
|
||||
}
|
||||
|
||||
public final Reservation retreiveReservation(String reservation_number) {
|
||||
public final Reservation findReservation(String reservation_number) {
|
||||
Reservation rsrv = null;
|
||||
for (Account acct : account_list) {
|
||||
for (Account acct : accounts) {
|
||||
rsrv = acct.findReservation(reservation_number);
|
||||
if( rsrv!=null ) break;
|
||||
}
|
||||
return rsrv;
|
||||
}
|
||||
|
||||
public List<? extends Reservation> getReservationList() {
|
||||
return account_list.getListOfReservations();
|
||||
public List<? extends IReservation> getReservationList() {
|
||||
return accounts.getListOfReservations();
|
||||
}
|
||||
|
||||
public void showReservationList() {
|
||||
for (Reservation rsrv : this.getReservationList()) {
|
||||
System.out.println(String.format("Account %s:, %s", rsrv.getAccountNumber(), rsrv.getReservation_number()));
|
||||
for (IReservation irsrv : this.getReservationList()) {
|
||||
System.out.println(String.format("Account %s: %s, %s", irsrv.getAccountNumber(), irsrv.getReservation_number(), irsrv.getPhysical_address().getStreet()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,13 +7,21 @@ package lodge.reservationsystem;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
public final class CabinReservation extends Reservation {
|
||||
import lodge.data.Address;
|
||||
import lodge.data.KitchenTypeEnum;
|
||||
import lodge.data.Reservation;
|
||||
|
||||
protected CabinReservation() {
|
||||
setType('C');
|
||||
public final class CabinReservation extends Reservation implements IReservation {
|
||||
|
||||
public CabinReservation() {
|
||||
this.setType('C');
|
||||
this.setNumberOfBeds(1);
|
||||
this.setKitchen(KitchenTypeEnum.Kitchenette);
|
||||
}
|
||||
|
||||
public static Reservation copy(String reservationType) {
|
||||
return new CabinReservation();
|
||||
}
|
||||
|
||||
public CabinReservation(final Address physical_address) {
|
||||
this();
|
||||
@@ -22,8 +30,7 @@ public final class CabinReservation extends Reservation {
|
||||
physical_address.getZip()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String ReservationType() {
|
||||
public String ReservationType() {
|
||||
return "CabinReservation";
|
||||
}
|
||||
|
||||
|
||||
@@ -8,9 +8,13 @@ import java.time.LocalTime;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
public final class HotelReservation extends Reservation {
|
||||
import lodge.data.Address;
|
||||
import lodge.data.KitchenTypeEnum;
|
||||
import lodge.data.Reservation;
|
||||
|
||||
protected HotelReservation() {
|
||||
public final class HotelReservation extends Reservation implements IReservation{
|
||||
|
||||
public HotelReservation() {
|
||||
this.setType('H');
|
||||
this.setNumberOfBeds(2);
|
||||
this.setNumberOfBeds(2);
|
||||
@@ -19,6 +23,10 @@ public final class HotelReservation extends Reservation {
|
||||
this.setNumberOfFloors(1);
|
||||
this.setKitchen(KitchenTypeEnum.Kitchenette);
|
||||
}
|
||||
|
||||
public static Reservation copy(String reservationType) {
|
||||
return new HotelReservation();
|
||||
}
|
||||
|
||||
public HotelReservation(final Address physical_address) {
|
||||
this();
|
||||
|
||||
@@ -7,9 +7,13 @@ package lodge.reservationsystem;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
public final class HouseReservation extends Reservation {
|
||||
import lodge.data.Address;
|
||||
import lodge.data.KitchenTypeEnum;
|
||||
import lodge.data.Reservation;
|
||||
|
||||
protected HouseReservation() {
|
||||
public final class HouseReservation extends Reservation implements IReservation {
|
||||
|
||||
public HouseReservation() {
|
||||
this.setType('Z');
|
||||
this.setNumberOfBeds(2);
|
||||
this.setNumberOfBedRooms(1);
|
||||
@@ -18,6 +22,10 @@ public final class HouseReservation extends Reservation {
|
||||
this.setKitchen(KitchenTypeEnum.Kitchenette);
|
||||
}
|
||||
|
||||
public static Reservation copy(String reservationType) {
|
||||
return new HouseReservation();
|
||||
}
|
||||
|
||||
public HouseReservation(final Address physical_address) {
|
||||
this();
|
||||
this.setPhysical_address(
|
||||
|
||||
16
src/java/lodge/reservationsystem/IReservation.java
Normal file
16
src/java/lodge/reservationsystem/IReservation.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package lodge.reservationsystem;
|
||||
|
||||
import lodge.data.Address;
|
||||
import lodge.data.Reservation;
|
||||
|
||||
public interface IReservation {
|
||||
|
||||
public abstract String ReservationType();
|
||||
public static Reservation copy(String type){ return null; };
|
||||
public String getReservation_number();
|
||||
public String getAccountNumber();
|
||||
public Address getPhysical_address();
|
||||
public float getPricePerNight();
|
||||
public float calculatePrice();
|
||||
public boolean checkValid();
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
package lodge.reservationsystem;
|
||||
|
||||
class IllegalOperationException extends RuntimeException {
|
||||
public class IllegalOperationException extends RuntimeException {
|
||||
public IllegalOperationException () {
|
||||
super();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user