diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF new file mode 100644 index 0000000..22fc519 --- /dev/null +++ b/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: lodge.TestReservations +Class-Path: . \ No newline at end of file diff --git a/src/lodge/TestReservations.java b/src/lodge/TestReservations.java new file mode 100644 index 0000000..65edda2 --- /dev/null +++ b/src/lodge/TestReservations.java @@ -0,0 +1,70 @@ +package lodge; + +//import lodge.reservationsystem.Address; +//import lodge.reservationsystem.EmailAddress; +import lodge.reservationsystem.ReservationSystemManager; + +public final class TestReservations { + public static void main(String[] args) throws Exception { +/* + ReservationSystemManager mgr = new ReservationSystemManager(); + + mgr.setDataStoreRoot("~/data"); + + // 1. Get the list of loaded accounts from Manager + + mgr.retrieveAccounts(); + + // 2. Retrieve a loaded account object that matches a specific account number + + mgr.retrieveAccount("A######"); + + // 3. Add new account object to the list managed by Manager (if account object + // already exists on add action with the same account number, it is considered + // an error) + + mgr.UpdateAccount( mgr.newAccount("456-7890", new Address(), new EmailAddress() )); + */ + + // 4. Request that Manager updates specific account’s files with data stored in + // memory + + // 5. Add draft lodging reservation to an account (if reservation object already + // exists with the same reservation number, it is considered an error) + +/* + acct = mgr.retrieveAccount("A######"); + if (acct != null) + acct.addReservation(new HotelReservation()); + + // 6. Complete reservation that is associated with an account + Reservation rsrv = null; + acct = null; + acct = mgr.retrieveAccount("A######"); + if (acct != null) { + rsrv = acct.retrieve("?######"); + rsrv.Complete(); + } + + // 7. Cancel reservation that is associated with an account + if (acct != null) { + rsrv = acct.retrieve("?######"); + if (rsrv != null) + rsrv.Cancel(); + } + + if (rsrv != null) { + // 8. Change reservation values that can be changed (if reservation is + // cancelled, completed, or for past date, it is considered an error) + rsrv = Reservation.update(rsrv); + + // 9. Request for price per night to be calculated and returned for a specific + // reservation + + rsrv = Reservation.calculatePricePerNight(rsrv); + // 10. Request for total reservation price to be calculated and returned for a + // specific reservation + } */ + System.out.println("Program Completed."); + } +} diff --git a/src/lodge/reservationsystem/Account.java b/src/lodge/reservationsystem/Account.java new file mode 100644 index 0000000..8ac95b5 --- /dev/null +++ b/src/lodge/reservationsystem/Account.java @@ -0,0 +1,61 @@ +package lodge.reservationsystem; + +import java.util.ArrayList; + +public final class Account { + + String anumber; + ArrayList reservation_list = new ArrayList(); + + String phone_number; + Address mailing_address; + EmailAddress email_address; + + public String getAnumber() { + return anumber; + } + + public void setAnumber(String account_number) { + this.anumber = account_number; + } + + public String toString() { + return super.toString(); + } + + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + + if (obj.getClass() != this.getClass()) { + return false; + } + + final Account other = (Account) obj; + if ((this.getAnumber() == null) ? (other.getAnumber() != null) + : !this.getAnumber().equals(other.getAnumber())) { + return false; + } + + return true; + } + + public int hashCode() { + return java.util.Objects.hash(getAnumber()); + } + + public void addReservation(Reservation reservation) { + reservation_list.add(reservation); + } + + public static Account newAccount(String phone_number, Address mailing_address, EmailAddress email_address) + throws Exception { + Account A = new Account(); + A.anumber = "A" + java.util.Objects.hash(phone_number, mailing_address, email_address); + A.phone_number = phone_number; + A.mailing_address = mailing_address; + A.email_address = email_address; + return A; + } +} diff --git a/src/lodge/reservationsystem/AccountException.java b/src/lodge/reservationsystem/AccountException.java new file mode 100644 index 0000000..2e24eb6 --- /dev/null +++ b/src/lodge/reservationsystem/AccountException.java @@ -0,0 +1,12 @@ +package lodge.reservationsystem; + +class AccountException extends Exception { + public AccountException() { + super(); + } + + public AccountException(String message) { + super(message); + } + +} \ No newline at end of file diff --git a/src/lodge/reservationsystem/Accounts.java b/src/lodge/reservationsystem/Accounts.java new file mode 100644 index 0000000..d793de2 --- /dev/null +++ b/src/lodge/reservationsystem/Accounts.java @@ -0,0 +1,34 @@ +package lodge.reservationsystem; + +import java.util.ArrayList; +import java.util.Optional; + +public class Accounts extends ArrayList { + + // ** Find account return null not-existing. */ + public Account retrieveAccount(Accounts account_list, String account_number) { + Optional account = account_list.stream().filter(e -> e.getAnumber() == account_number).findFirst(); + return account.isPresent() ? account.get() : null; + } + + // ** Add account throw error if account number is pre-existing. */ + public Account addAccount(Accounts account_list, Account account) throws NullPointerException, Exception { + + if (account_list.stream().map(Account::getAnumber).count() > 0) { + throw new AccountException("Account exists, duplicates not allowed."); + } else { + account_list.add(account); + } + return account; + } + + // save account in edit status + public void save(Account acct) { + + } + + // save accounts in edit status + public static void save(Accounts account_list, Account acct) { + + } +} diff --git a/src/lodge/reservationsystem/Address.java b/src/lodge/reservationsystem/Address.java new file mode 100644 index 0000000..8598f95 --- /dev/null +++ b/src/lodge/reservationsystem/Address.java @@ -0,0 +1,47 @@ +package lodge.reservationsystem; + +public class Address implements Cloneable { + + public String street; + + public String city; + + public String state; + + public String zip; + + // format and return object's data in XML format + public String toString() { + return null; + } + + // create and return a copy of the object + public Address clone() throws CloneNotSupportedException { + Address result = new Address(); + + result.street = this.street; + result.city = this.city; + result.state = this.state; + result.zip = this.zip; + + return result; + } + + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + + if (obj.getClass() != this.getClass()) { + return false; + } + + final Account other = (Account) obj; + return hashCode() == other.hashCode(); + + } + + public int hashCode() { + return java.util.Objects.hash(street, city, state, zip); + } +} \ No newline at end of file diff --git a/src/lodge/reservationsystem/CabinReservation.java b/src/lodge/reservationsystem/CabinReservation.java new file mode 100644 index 0000000..176669f --- /dev/null +++ b/src/lodge/reservationsystem/CabinReservation.java @@ -0,0 +1,21 @@ +package lodge.reservationsystem; + +public class CabinReservation extends Reservation { + +//format and return object's data in XML format + public String toString() { + return null; + } + + //create and return a copy of the object + public CabinReservation clone() throws CloneNotSupportedException { + CabinReservation result = new CabinReservation(); + return result; + } + + //calculate and return the reservation's price + public float calculatePrice() { + return 0.0f; + } + +} \ No newline at end of file diff --git a/src/lodge/reservationsystem/EmailAddress.java b/src/lodge/reservationsystem/EmailAddress.java new file mode 100644 index 0000000..ff33019 --- /dev/null +++ b/src/lodge/reservationsystem/EmailAddress.java @@ -0,0 +1,6 @@ +package lodge.reservationsystem; + +public class EmailAddress implements Cloneable{ + String email_address; + +} diff --git a/src/lodge/reservationsystem/HotelReservation.java b/src/lodge/reservationsystem/HotelReservation.java new file mode 100644 index 0000000..cc1399d --- /dev/null +++ b/src/lodge/reservationsystem/HotelReservation.java @@ -0,0 +1,21 @@ +package lodge.reservationsystem; + +public class HotelReservation extends Reservation { + +//format and return object's data in XML format + public String toString() { + return null; + } + + //create and return a copy of the object + public HotelReservation clone() throws CloneNotSupportedException { + HotelReservation result = new HotelReservation(); + return result; + } + + //calculate and return the reservation's price + public float calculatePrice() { + return 0.0f; + } + +} \ No newline at end of file diff --git a/src/lodge/reservationsystem/HouseReservation.java b/src/lodge/reservationsystem/HouseReservation.java new file mode 100644 index 0000000..e754bd3 --- /dev/null +++ b/src/lodge/reservationsystem/HouseReservation.java @@ -0,0 +1,21 @@ +package lodge.reservationsystem; + +public class HouseReservation extends Reservation { + +//format and return object's data in XML format + public String toString() { + return null; + } + + //create and return a copy of the object + public HotelReservation clone() throws CloneNotSupportedException { + HotelReservation result = new HotelReservation(); + return result; + } + + //calculate and return the reservation's price + public float calculatePrice() { + return 0.0f; + } + +} \ No newline at end of file diff --git a/src/lodge/reservationsystem/Reservation.java b/src/lodge/reservationsystem/Reservation.java new file mode 100644 index 0000000..38e76fe --- /dev/null +++ b/src/lodge/reservationsystem/Reservation.java @@ -0,0 +1,76 @@ +package lodge.reservationsystem; + +import java.time.ZonedDateTime; + +public abstract class Reservation implements Cloneable { + + String reservation_number; + String physical_address; + String mailing_address; + + ZonedDateTime reservation_start_date; + ZonedDateTime reservation_end_date; + + ReservationStatus reservation_status = ReservationStatus.Draft; + + Integer numberOfBeds = 0; + Integer numberOfBedRooms = 0; + Integer numberOfBathRooms = 0; + + Integer squareFeet = 0; + + Float price = 0.0f; + + // format and return object's data in XML format + public String toString() { + return null; + } + + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + + if (obj.getClass() != this.getClass()) { + return false; + } + + final Reservation other = (Reservation) obj; + if ((reservation_number == null) ? (other.reservation_number != null) + : !reservation_number.equals(other.reservation_number)) { + return false; + } + + return true; + } + + public int hashCode() { + return java.util.Objects.hash(reservation_number); + } + + // create and return a copy of the object + public abstract Reservation clone() throws CloneNotSupportedException; + + public void Cancel() throws Exception { + + } + + public void Complete() throws Exception { + + } + + // public Reservation retrieve( ArrayList reservation_list, String reservation_number) { + // Optional reservation = reservation_list.stream() + // .filter(e -> e.reservation_number == reservation_number).findFirst(); + // return reservation.isPresent() ? reservation.get() : null; + // } + + public static Reservation update(Reservation rsrv) { + return rsrv; + } + + public static Reservation calculatePricePerNight(Reservation rsrv) { + return rsrv; + } + +} \ No newline at end of file diff --git a/src/lodge/reservationsystem/ReservationStatus.java b/src/lodge/reservationsystem/ReservationStatus.java new file mode 100644 index 0000000..7e3909a --- /dev/null +++ b/src/lodge/reservationsystem/ReservationStatus.java @@ -0,0 +1,8 @@ +package lodge.reservationsystem; + +public enum ReservationStatus { + Draft, + Completed, + Finished + +} diff --git a/src/lodge/reservationsystem/ReservationSystemManager.java b/src/lodge/reservationsystem/ReservationSystemManager.java new file mode 100644 index 0000000..cd66bdb --- /dev/null +++ b/src/lodge/reservationsystem/ReservationSystemManager.java @@ -0,0 +1,33 @@ +package lodge.reservationsystem; + +public class ReservationSystemManager { + + Accounts account_list = new Accounts(); + // hard code data store location for storage of + // account data files on filesystem + String DATASTOREROOT = ""; + + public String getDataStoreRoot() { + return DATASTOREROOT; + } + + public void setDataStoreRoot(String filePath) { + DATASTOREROOT = filePath; + } + + public void UpdateAccount(Account acct) { + + Accounts.save(account_list, acct); + } + + public final Account newAccount(String phone_number, Address mailing_address, EmailAddress email_address){ + Account acct = null; + try { + acct = Account.newAccount(phone_number, mailing_address, email_address); + } catch (Exception e) { + e.printStackTrace(); + } + Accounts.save(account_list, acct); + return acct; + } +} diff --git a/src/module-info.java b/src/module-info.java new file mode 100644 index 0000000..249bb31 --- /dev/null +++ b/src/module-info.java @@ -0,0 +1,3 @@ +module lodge { + exports lodge.reservationsystem; +} \ No newline at end of file