Files
reservationsystem/src/java/lodge/TestReservations.java

154 lines
7.2 KiB
Java
Raw Normal View History

2025-09-15 11:08:45 -04:00
/**
* license: GPLv3
* lodge.reservationsystem
*/
2025-08-28 21:08:16 -04:00
package lodge;
2025-09-03 08:56:57 -04:00
import java.time.ZoneId;
import java.time.ZonedDateTime;
2025-09-18 12:18:33 -04:00
import lodge.data.Account;
import lodge.data.Address;
import lodge.data.DuplicateObjectException;
import lodge.data.EmailAddress;
2025-09-18 21:39:24 -04:00
2025-09-18 12:18:33 -04:00
import lodge.data.ReservationStatusEnum;
2025-08-28 21:08:16 -04:00
import lodge.reservationsystem.AccomodationManager;
2025-08-31 18:59:49 -04:00
import lodge.reservationsystem.CabinReservation;
import lodge.reservationsystem.HotelReservation;
2025-09-05 09:16:57 -04:00
import lodge.reservationsystem.HouseReservation;
2025-09-18 21:39:24 -04:00
import lodge.reservation.Reservation;
import lodge.reservation.IReservation;
2025-08-28 21:08:16 -04:00
public final class TestReservations {
public static void main(String[] args) throws Exception {
2025-09-05 10:26:49 -04:00
AccomodationManager mgr = new AccomodationManager(getRepositoryConfig.getPath());
2025-08-28 21:08:16 -04:00
// 1. Get the list of loaded accounts from Manager
mgr.loadAll();
// 2. Retrieve a loaded account object that matches a specific account number
2025-09-06 19:21:01 -04:00
mgr.retrieveAccount("A1450981765");
2025-08-28 21:08:16 -04:00
// 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)
2025-09-03 08:56:57 -04:00
Account acct = mgr.newAccount("701-456-7890",
new Address("10 wilco ave", "wilco", "WY", "82801"),
new EmailAddress("wilco@wyommin.net"));
2025-08-29 07:26:53 -04:00
mgr.AddAccount(acct);
2025-08-28 21:08:16 -04:00
// 4. Request that Manager updates specific accounts files with data stored in
// memory
2025-09-03 12:25:10 -04:00
mgr.UpdateAccount(acct);
2025-09-10 19:32:19 -04:00
Account acct2 = mgr.newAccount("301-356-3890",
new Address("30 Amstadam ave", "New York", "NY", "12010"),
new EmailAddress("newbee952@aol.com"));
mgr.AddAccount(acct2);
2025-08-28 21:08:16 -04:00
// 5. Add draft lodging reservation to an account (if reservation object already
// exists with the same reservation number, it is considered an error)
2025-09-10 17:54:48 -04:00
HotelReservation hotel = new HotelReservation(
new Address("400 hotel ave", "Maryland City", "CA", "20723"));
2025-09-03 08:56:57 -04:00
hotel.setMailing_address(new Address("400 hotel ave", "Maryland City", "MD", "20723"));
2025-09-03 16:08:44 -04:00
hotel.setNumberOfBeds(2);
2025-09-03 08:56:57 -04:00
hotel.setNumberOfFloors(1);
2025-09-03 16:08:44 -04:00
hotel.setNumberOfBedRooms(1);
2025-09-03 08:56:57 -04:00
hotel.setSquareFeet(450);
2025-09-03 10:12:45 -04:00
hotel.setReservation_start_date(ZonedDateTime.of(2025, 07, 05, 10, 0, 0, 0, ZoneId.of("UTC")));
2025-09-14 22:50:38 -04:00
hotel.setReservation_end_date(ZonedDateTime.of(2025, 07, 07, 22, 0, 0, 0, ZoneId.of("UTC")));
2025-09-10 19:32:19 -04:00
mgr.addReservation(acct, hotel);
2025-09-03 08:56:57 -04:00
2025-09-03 12:25:10 -04:00
mgr.UpdateAccount(acct);
2025-09-03 08:56:57 -04:00
2025-09-13 20:33:29 -04:00
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);
2025-09-10 19:32:19 -04:00
mgr.UpdateAccount(acct2);
2025-09-13 20:33:29 -04:00
CabinReservation cabin = new CabinReservation(new Address("40 cabin ave", "Carnelian", "CA", "96140"));
2025-08-29 07:26:53 -04:00
cabin.setMailing_address(new Address("40 cabin ave", "Carnelian Bay", "CA", "96140"));
cabin.setNumberOfBeds(4);
cabin.setNumberOfFloors(2);
cabin.setNumberOfBedRooms(3);
cabin.setSquareFeet(806);
2025-09-03 16:08:44 -04:00
cabin.setReservation_start_date(ZonedDateTime.of(2025, 9, 05, 10, 0, 0, 0, ZoneId.of("UTC")));
2025-09-03 10:12:45 -04:00
cabin.setReservation_end_date(ZonedDateTime.of(2025, 11, 30, 22, 0, 0, 0, ZoneId.of("UTC")));
2025-09-10 19:32:19 -04:00
mgr.addReservation(acct, cabin);
2025-09-03 08:56:57 -04:00
2025-09-03 12:25:10 -04:00
mgr.UpdateAccount(acct);
2025-09-10 17:54:48 -04:00
HouseReservation house = new HouseReservation(
new Address("3000 Osage ave", "GreenBelt", "MD", "20740"));
2025-09-03 08:56:57 -04:00
house.setMailing_address(new Address("40012 College ave", "College Park", "MD", "20740"));
house.setNumberOfBeds(4);
house.setNumberOfFloors(3);
house.setNumberOfBedRooms(3);
house.setSquareFeet(1400);
2025-09-14 22:50:38 -04:00
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")));
2025-09-10 19:32:19 -04:00
mgr.addReservation(acct, house);
2025-09-03 08:56:57 -04:00
2025-09-03 12:25:10 -04:00
mgr.UpdateAccount(acct);
2025-09-03 08:56:57 -04:00
try {
2025-09-18 12:18:33 -04:00
if( mgr.addReservation(acct, cabin) ){
mgr.UpdateAccount(mgr.retrieveAccount(acct.getAccount_number()));
}
2025-09-10 13:06:54 -04:00
} catch (DuplicateObjectException e) {
2025-09-03 12:25:10 -04:00
System.out.println(e.getMessage());
2025-09-03 08:56:57 -04:00
}
2025-09-18 12:18:33 -04:00
Account account = mgr.retrieveLoadedAccounts().get(0);
2025-08-31 18:59:49 -04:00
2025-08-29 07:26:53 -04:00
// 6. Complete reservation that is associated with an account
2025-09-18 12:18:33 -04:00
Reservation rsrv = account.findReservation(house.getReservation_number());
house.Change(rsrv, ReservationStatusEnum.Completed);
2025-09-10 16:08:11 -04:00
mgr.UpdateAccount(mgr.retrieveAccount(acct.getAccount_number()));
2025-08-29 10:32:10 -04:00
// 7. Cancel reservation that is associated with an account
2025-09-18 12:18:33 -04:00
account = mgr.retrieveLoadedAccounts().getLast();
IReservation ir = account.getAllReservations().next();
rsrv = (Reservation)ir;
rsrv.Change(rsrv, ReservationStatusEnum.Canceled);
mgr.UpdateAccount(mgr.retrieveAccount(rsrv.getAccountNumber()));
2025-09-10 17:54:48 -04:00
// 8. Change reservation values that can be changed (if reservation is
// cancelled, completed, or for past date, it is considered an error)
2025-09-18 12:18:33 -04:00
rsrv.Change(rsrv, ReservationStatusEnum.Completed);
2025-09-15 16:47:39 -04:00
house.update(house);
2025-09-10 17:54:48 -04:00
// 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
2025-09-15 16:47:39 -04:00
account.findReservation(house.getReservation_number());
house.calculatePrice();
2025-09-10 17:54:48 -04:00
2025-09-14 11:56:57 -04:00
mgr.showReservationList();
2025-08-28 21:08:16 -04:00
System.out.println("Program Completed.");
}
2025-09-10 17:54:48 -04:00
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";
2025-09-05 09:16:57 -04:00
}
}
2025-08-28 21:08:16 -04:00
}