/** * license: GPLv3 * lodge.reservationsystem */ package lodge; import java.time.ZoneId; import java.time.ZonedDateTime; 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; public final class TestReservations { public static void main(String[] args) throws Exception { AccomodationManager mgr = new AccomodationManager(getRepositoryConfig.getPath()); // 1. Get the list of loaded accounts from Manager mgr.loadAll(); // 2. Retrieve a loaded account object that matches a specific account number mgr.retrieveAccount("A1450981765"); // 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) Account acct = mgr.newAccount("701-456-7890", new Address("10 wilco ave", "wilco", "WY", "82801"), new EmailAddress("wilco@wyommin.net")); mgr.AddAccount(acct); // 4. Request that Manager updates specific account’s files with data stored in // memory mgr.UpdateAccount(acct); Account acct2 = mgr.newAccount("301-356-3890", new Address("30 Amstadam ave", "New York", "NY", "12010"), new EmailAddress("newbee952@aol.com")); mgr.AddAccount(acct2); // 5. Add draft lodging reservation to an account (if reservation object already // exists with the same reservation number, it is considered an error) HotelReservation hotel = new HotelReservation( new Address("400 hotel ave", "Maryland City", "CA", "20723")); hotel.setMailing_address(new Address("400 hotel ave", "Maryland City", "MD", "20723")); hotel.setNumberOfBeds(2); hotel.setNumberOfFloors(1); hotel.setNumberOfBedRooms(1); hotel.setSquareFeet(450); hotel.setReservation_start_date(ZonedDateTime.of(2025, 07, 05, 10, 0, 0, 0, ZoneId.of("UTC"))); hotel.setReservation_end_date(ZonedDateTime.of(2025, 07, 07, 22, 0, 0, 0, ZoneId.of("UTC"))); mgr.addReservation(acct, hotel); mgr.UpdateAccount(acct); CabinReservation cabin2 = new CabinReservation(new Address("30 cabin ave", "Carnelian", "CA", "96140")); cabin2.setMailing_address(new Address("30 cabin ave", "Carnelian Bay", "CA", "96140")); cabin2.setNumberOfBeds(4); cabin2.setNumberOfFloors(2); cabin2.setNumberOfBedRooms(3); cabin2.setSquareFeet(806); cabin2.setReservation_start_date(ZonedDateTime.of(2025, 9, 05, 10, 0, 0, 0, ZoneId.of("UTC"))); cabin2.setReservation_end_date(ZonedDateTime.of(2025, 11, 30, 22, 0, 0, 0, ZoneId.of("UTC"))); mgr.addReservation(acct2, cabin2); mgr.UpdateAccount(acct2); CabinReservation cabin = new CabinReservation(new Address("40 cabin ave", "Carnelian", "CA", "96140")); cabin.setMailing_address(new Address("40 cabin ave", "Carnelian Bay", "CA", "96140")); cabin.setNumberOfBeds(4); cabin.setNumberOfFloors(2); cabin.setNumberOfBedRooms(3); cabin.setSquareFeet(806); cabin.setReservation_start_date(ZonedDateTime.of(2025, 9, 05, 10, 0, 0, 0, ZoneId.of("UTC"))); cabin.setReservation_end_date(ZonedDateTime.of(2025, 11, 30, 22, 0, 0, 0, ZoneId.of("UTC"))); mgr.addReservation(acct, cabin); mgr.UpdateAccount(acct); HouseReservation house = new HouseReservation( new Address("3000 Osage ave", "GreenBelt", "MD", "20740")); house.setMailing_address(new Address("40012 College ave", "College Park", "MD", "20740")); house.setNumberOfBeds(4); house.setNumberOfFloors(3); house.setNumberOfBedRooms(3); house.setSquareFeet(1400); house.setReservation_start_date(ZonedDateTime.of(2025, 11, 5, 10, 0, 0, 0, ZoneId.of("UTC"))); house.setReservation_end_date(ZonedDateTime.of(2025, 11, 15, 22, 0, 0, 0, ZoneId.of("UTC"))); mgr.addReservation(acct, house); mgr.UpdateAccount(acct); try { mgr.addReservation(acct, cabin); mgr.UpdateAccount(mgr.retrieveAccount(acct.getAccount_number())); } catch (DuplicateObjectException e) { System.out.println(e.getMessage()); } Account account = mgr.retrieveLoadedAccounts().getFirst(); 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.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.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); // 9. Request for price per night to be calculated and returned for a // per night // reservation // 10. Request for total reservation price to be calculated and returned for // specific reservation rsrv = account.findReservation(house.getReservation_number()); rsrv.calculatePrice(); mgr.showReservationList(); System.out.println("Program Completed."); } public final static class getRepositoryConfig { public final static String getPath() { String home = System.getenv("HOME") != null ? System.getenv("HOME") : System.getenv("HOMEDRIVE") + System.getenv("HOMEPATH"); return home.replace('\\', '/') + "/workspace/reservationsystem/src/resources"; } } }