change
This commit is contained in:
70
src/lodge/TestReservations.java
Normal file
70
src/lodge/TestReservations.java
Normal file
@@ -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.");
|
||||
}
|
||||
}
|
||||
61
src/lodge/reservationsystem/Account.java
Normal file
61
src/lodge/reservationsystem/Account.java
Normal file
@@ -0,0 +1,61 @@
|
||||
package lodge.reservationsystem;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public final class Account {
|
||||
|
||||
String anumber;
|
||||
ArrayList<Reservation> reservation_list = new ArrayList<Reservation>();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
12
src/lodge/reservationsystem/AccountException.java
Normal file
12
src/lodge/reservationsystem/AccountException.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package lodge.reservationsystem;
|
||||
|
||||
class AccountException extends Exception {
|
||||
public AccountException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public AccountException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
||||
34
src/lodge/reservationsystem/Accounts.java
Normal file
34
src/lodge/reservationsystem/Accounts.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package lodge.reservationsystem;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Accounts extends ArrayList<Account> {
|
||||
|
||||
// ** Find account return null not-existing. */
|
||||
public Account retrieveAccount(Accounts account_list, String account_number) {
|
||||
Optional<Account> 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) {
|
||||
|
||||
}
|
||||
}
|
||||
47
src/lodge/reservationsystem/Address.java
Normal file
47
src/lodge/reservationsystem/Address.java
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
21
src/lodge/reservationsystem/CabinReservation.java
Normal file
21
src/lodge/reservationsystem/CabinReservation.java
Normal file
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
6
src/lodge/reservationsystem/EmailAddress.java
Normal file
6
src/lodge/reservationsystem/EmailAddress.java
Normal file
@@ -0,0 +1,6 @@
|
||||
package lodge.reservationsystem;
|
||||
|
||||
public class EmailAddress implements Cloneable{
|
||||
String email_address;
|
||||
|
||||
}
|
||||
21
src/lodge/reservationsystem/HotelReservation.java
Normal file
21
src/lodge/reservationsystem/HotelReservation.java
Normal file
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
21
src/lodge/reservationsystem/HouseReservation.java
Normal file
21
src/lodge/reservationsystem/HouseReservation.java
Normal file
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
76
src/lodge/reservationsystem/Reservation.java
Normal file
76
src/lodge/reservationsystem/Reservation.java
Normal file
@@ -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> reservation_list, String reservation_number) {
|
||||
// Optional<Reservation> 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;
|
||||
}
|
||||
|
||||
}
|
||||
8
src/lodge/reservationsystem/ReservationStatus.java
Normal file
8
src/lodge/reservationsystem/ReservationStatus.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package lodge.reservationsystem;
|
||||
|
||||
public enum ReservationStatus {
|
||||
Draft,
|
||||
Completed,
|
||||
Finished
|
||||
|
||||
}
|
||||
33
src/lodge/reservationsystem/ReservationSystemManager.java
Normal file
33
src/lodge/reservationsystem/ReservationSystemManager.java
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
3
src/module-info.java
Normal file
3
src/module-info.java
Normal file
@@ -0,0 +1,3 @@
|
||||
module lodge {
|
||||
exports lodge.reservationsystem;
|
||||
}
|
||||
Reference in New Issue
Block a user