implement toString
This commit is contained in:
@@ -5,8 +5,10 @@ import java.net.URI;
|
|||||||
import lodge.reservationsystem.AccomodationManager;
|
import lodge.reservationsystem.AccomodationManager;
|
||||||
import lodge.reservationsystem.Account;
|
import lodge.reservationsystem.Account;
|
||||||
import lodge.reservationsystem.Address;
|
import lodge.reservationsystem.Address;
|
||||||
|
import lodge.reservationsystem.CabinReservation;
|
||||||
import lodge.reservationsystem.DataRepository;
|
import lodge.reservationsystem.DataRepository;
|
||||||
import lodge.reservationsystem.EmailAddress;
|
import lodge.reservationsystem.EmailAddress;
|
||||||
|
import lodge.reservationsystem.Reservation;
|
||||||
|
|
||||||
public final class TestReservations {
|
public final class TestReservations {
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
@@ -31,28 +33,30 @@ public final class TestReservations {
|
|||||||
Account acct = mgr.newAccount("767-456-7890",
|
Account acct = mgr.newAccount("767-456-7890",
|
||||||
new Address("10 wilco ave", "wilco", "WY", "82801"),
|
new Address("10 wilco ave", "wilco", "WY", "82801"),
|
||||||
new EmailAddress("wilco@wyommin.net"));
|
new EmailAddress("wilco@wyommin.net"));
|
||||||
|
mgr.AddAccount(acct);
|
||||||
|
|
||||||
// 4. Request that Manager updates specific account’s files with data stored in
|
// 4. Request that Manager updates specific account’s files with data stored in
|
||||||
// memory
|
// memory
|
||||||
mgr.AddAccount(acct);
|
mgr.UpdateAccount(mgr.retrieveAccount(acct.account_number()));
|
||||||
// 5. Add draft lodging reservation to an account (if reservation object already
|
// 5. Add draft lodging reservation to an account (if reservation object already
|
||||||
// exists with the same reservation number, it is considered an error)
|
// exists with the same reservation number, it is considered an error)
|
||||||
|
|
||||||
mgr.UpdateAccount(mgr.retrieveAccount(acct.account_number()));
|
CabinReservation cabin = new CabinReservation();
|
||||||
|
cabin.setPhysical_address(new Address("30 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);
|
||||||
|
mgr.addReservation( mgr.retrieveAccount(acct.account_number()), cabin);
|
||||||
|
|
||||||
|
// 6. Complete reservation that is associated with an account
|
||||||
|
Reservation rsrv = mgr.retreiveReservation("R######");
|
||||||
|
rsrv.Complete();
|
||||||
|
|
||||||
|
//mgr.UpdateAccount(mgr.retrieveAccount(acct.account_number()));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 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
|
* // 7. Cancel reservation that is associated with an account
|
||||||
* if (acct != null) {
|
* if (acct != null) {
|
||||||
* rsrv = acct.retrieve("?######");
|
* rsrv = acct.retrieve("?######");
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import java.nio.file.FileVisitResult;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.SimpleFileVisitor;
|
import java.nio.file.SimpleFileVisitor;
|
||||||
import java.nio.file.attribute.BasicFileAttributes;
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
@@ -57,4 +56,14 @@ public class AccomodationManager {
|
|||||||
AccountList.save(account_list, acct);
|
AccountList.save(account_list, acct);
|
||||||
return acct;
|
return acct;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addReservation(Account account, CabinReservation cabin) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
throw new UnsupportedOperationException("Unimplemented method 'addReservation'");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Reservation retreiveReservation(String string) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
throw new UnsupportedOperationException("Unimplemented method 'retreiveReservation'");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
package lodge.reservationsystem;
|
package lodge.reservationsystem;
|
||||||
|
|
||||||
import java.io.BufferedOutputStream;
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
@@ -30,20 +26,24 @@ public class Account {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Account [account_number=" + account_number + ", phone_number=" + phone_number
|
|
||||||
+ ", mailing_address=" + mailing_address + ", email_address=" + email_address
|
StringBuilder sb = new StringBuilder();
|
||||||
+ ", account_number()=" + account_number() + ", phone_number()=" + phone_number()
|
sb.append("{ \"Account\":{");
|
||||||
+ ", mailing_address()=" + mailing_address() + ", email_address()=" + email_address()
|
sb.append("\"account_number\": \"" + account_number + "\",");
|
||||||
+ "]";
|
sb.append("\"phone_number\": \"" + phone_number + "\",");
|
||||||
|
sb.append("\"mailing_address\": " + mailing_address + ",");
|
||||||
|
sb.append("\"email_address\": " + email_address );
|
||||||
|
sb.append("}}");
|
||||||
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
//@TODO Write Account out in JSON
|
// @TODO Write Account out in JSON
|
||||||
public static void Write(Account acct) throws IOException {
|
public static void Write(Account acct) throws IOException {
|
||||||
String dataRoot = DataRepository.getPath();
|
String dataRoot = DataRepository.getPath();
|
||||||
dataRoot = dataRoot + "/" + acct.account_number + ".txt";
|
dataRoot = dataRoot + "/" + acct.account_number + ".json";
|
||||||
Path path = Paths.get(dataRoot);
|
Path path = Paths.get(dataRoot);
|
||||||
|
|
||||||
try(BufferedWriter writer = Files.newBufferedWriter(path, StandardCharsets.UTF_8)){
|
try (BufferedWriter writer = Files.newBufferedWriter(path, StandardCharsets.UTF_8)) {
|
||||||
writer.write(acct.toString());
|
writer.write(acct.toString());
|
||||||
writer.flush();
|
writer.flush();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,36 +6,46 @@ public final class Address {
|
|||||||
String city;
|
String city;
|
||||||
String state;
|
String state;
|
||||||
String zip;
|
String zip;
|
||||||
|
|
||||||
public Address(String street, String city, String state, String zip) {
|
public Address(String street, String city, String state, String zip) {
|
||||||
this.street = street;
|
this.street = street;
|
||||||
this.city = city;
|
this.city = city;
|
||||||
this.state = state;
|
this.state = state;
|
||||||
this.zip = zip;
|
this.zip = zip;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getStreet() {
|
public String getStreet() {
|
||||||
return street;
|
return street;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStreet(String street) {
|
public void setStreet(String street) {
|
||||||
this.street = street;
|
this.street = street;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCity() {
|
public String getCity() {
|
||||||
return city;
|
return city;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCity(String city) {
|
public void setCity(String city) {
|
||||||
this.city = city;
|
this.city = city;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getState() {
|
public String getState() {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setState(String state) {
|
public void setState(String state) {
|
||||||
this.state = state;
|
this.state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getZip() {
|
public String getZip() {
|
||||||
return zip;
|
return zip;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setZip(String zip) {
|
public void setZip(String zip) {
|
||||||
this.zip = zip;
|
this.zip = zip;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
@@ -46,6 +56,7 @@ public final class Address {
|
|||||||
result = prime * result + ((zip == null) ? 0 : zip.hashCode());
|
result = prime * result + ((zip == null) ? 0 : zip.hashCode());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj)
|
||||||
@@ -77,9 +88,17 @@ public final class Address {
|
|||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Address [street=" + street + ", city=" + city + ", state=" + state + ", zip=" + zip + "]";
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append("{ \"Address\":{");
|
||||||
|
sb.append("\"street\": \"" + street + "\",");
|
||||||
|
sb.append("\"city\": \"" + city + "\",");
|
||||||
|
sb.append("\"state\": \"" + state + "\",");
|
||||||
|
sb.append("\"zip\": \"" + zip + "\"");
|
||||||
|
sb.append("}}");
|
||||||
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -42,7 +42,11 @@ public class EmailAddress{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "EmailAddress [email_address=" + email_address + "]";
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append("{ \"EmailAdress\":{");
|
||||||
|
sb.append("\"email\": \"" + email_address + "\"");
|
||||||
|
sb.append("}}");
|
||||||
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import java.time.ZonedDateTime;
|
|||||||
|
|
||||||
public abstract class Reservation {
|
public abstract class Reservation {
|
||||||
String reservation_number;
|
String reservation_number;
|
||||||
String physical_address;
|
Address physical_address;
|
||||||
String mailing_address;
|
Address mailing_address;
|
||||||
|
|
||||||
ZonedDateTime reservation_start_date;
|
ZonedDateTime reservation_start_date;
|
||||||
ZonedDateTime reservation_end_date;
|
ZonedDateTime reservation_end_date;
|
||||||
@@ -27,19 +27,19 @@ public abstract class Reservation {
|
|||||||
this.reservation_number = reservation_number;
|
this.reservation_number = reservation_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String physical_address() {
|
public Address physical_address() {
|
||||||
return physical_address;
|
return physical_address;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPhysical_address(String physical_address) {
|
public void setPhysical_address(Address physical_address) {
|
||||||
this.physical_address = physical_address;
|
this.physical_address = physical_address;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String mailing_address() {
|
public Address mailing_address() {
|
||||||
return mailing_address;
|
return mailing_address;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMailing_address(String mailing_address) {
|
public void setMailing_address(Address mailing_address) {
|
||||||
this.mailing_address = mailing_address;
|
this.mailing_address = mailing_address;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,16 +124,16 @@ public abstract class Reservation {
|
|||||||
reservation_status = ReservationStatus.Draft;
|
reservation_status = ReservationStatus.Draft;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Draft(){
|
public void Draft() {
|
||||||
this.reservation_status=ReservationStatus.Draft;
|
this.reservation_status = ReservationStatus.Draft;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Cancel() {
|
public void Cancel() {
|
||||||
this.reservation_status=ReservationStatus.Canceled;
|
this.reservation_status = ReservationStatus.Canceled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Complete() {
|
public void Complete() {
|
||||||
this.reservation_status=ReservationStatus.Completed;
|
this.reservation_status = ReservationStatus.Completed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -163,15 +163,25 @@ public abstract class Reservation {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Reservation [reservation_number=" + reservation_number + ", physical_address=" + physical_address
|
StringBuilder sb = new StringBuilder();
|
||||||
+ ", mailing_address=" + mailing_address + ", reservation_start_date=" + reservation_start_date
|
sb.append("{ \"Reservation\":{");
|
||||||
+ ", reservation_end_date=" + reservation_end_date + ", reservation_status=" + reservation_status
|
sb.append("\"reservation_number\": \"" + reservation_number + "\",");
|
||||||
+ ", numberOfBeds=" + numberOfBeds + ", numberOfBedRooms=" + numberOfBedRooms + ", numberOfBathRooms="
|
sb.append("\"reservation_status\": \"" + reservation_status + "\",");
|
||||||
+ numberOfBathRooms + ", numberOfFloors=" + numberOfFloors + ", squareFeet=" + squareFeet + ", price="
|
sb.append("\"reservation_start_date\": \"" + reservation_start_date + "\",");
|
||||||
+ price + "]";
|
sb.append("\"reservation_start_date\": \"" + reservation_end_date + "\",");
|
||||||
|
sb.append("\"physical_address\": \"" + physical_address + "\",");
|
||||||
|
sb.append("\"mailing_address\": \"" + mailing_address + "\",");
|
||||||
|
sb.append("\"numberOfBeds\": \"" + numberOfBeds + "\",");
|
||||||
|
sb.append("\"numberOfBedRooms\": \"" + numberOfBedRooms + "\",");
|
||||||
|
sb.append("\"numberOfBathRooms\": \"" + numberOfBathRooms + "\",");
|
||||||
|
sb.append("\"numberOfFloors\": \"" + numberOfFloors + "\",");
|
||||||
|
sb.append("\"squareFeet\": \"" + squareFeet + "\",");
|
||||||
|
sb.append("\"price\": \"" + price + "\"");
|
||||||
|
sb.append("}}");
|
||||||
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public float calculatePricePerNight(){
|
public float calculatePricePerNight() {
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user