This commit is contained in:
2025-08-27 18:32:02 -04:00
parent 5551075854
commit 020bdb2be9
3 changed files with 25 additions and 13 deletions

View File

@@ -1,19 +1,22 @@
package lodge;
import lodge.reservationsystem.Account;
import lodge.reservationsystem.Address;
import lodge.reservationsystem.EmailAddress;
//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();
mgr.loadAll();
// 2. Retrieve a loaded account object that matches a specific account number
@@ -23,18 +26,19 @@ public final class TestReservations {
// 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() ));
*/
mgr.newAccount( "456-7890", new Address(), new EmailAddress() );
// 4. Request that Manager updates specific accounts 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)
Account acct = mgr.retrieveAccount("A######");
/*
acct = mgr.retrieveAccount("A######");
if (acct != null)
mgr.UpdateAccount( mgr.retrieveAccount("A######") );
/* if (acct != null)
acct.addReservation(new HotelReservation());
// 6. Complete reservation that is associated with an account

View File

@@ -5,12 +5,6 @@ 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 {
@@ -31,4 +25,10 @@ public class Accounts extends ArrayList<Account> {
public static void save(Accounts account_list, Account acct) {
}
// ** Find account return null not-existing. */
public static 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;
}
}

View File

@@ -15,6 +15,14 @@ public class ReservationSystemManager {
DATASTOREROOT = filePath;
}
public void loadAll(){
}
public Account retrieveAccount(String acct_id){
return Accounts.retrieveAccount( account_list, acct_id );
}
public void UpdateAccount(Account acct) {
Accounts.save(account_list, acct);