Class VacationPackage
Constructor Summary
Constructor and Description |
---|
VacationPackage(java.lang.String name, int numDays)
Initializes a VacationPackage with provided values. |
Method Summary
Modifier and Type | Method and Description |
---|---|
boolean | equals(java.lang.Object other)
Provides a logical equality comparison for VacationPackages and any other object type. |
double | getAmountDue()
This method provides the remaining amount due to the travel agent for this trip less any deposit made upfront. |
abstract double | getDepositAmount()
This method provides the required upfront deposit amount for a given vacation. |
abstract double | getLodgingCost()
This method provides the subtotal for a trip related to lodging expenses (ie, not including flights, meals, and incidentals). |
java.lang.String | getName()
Retrieves the promotional name of this package. |
int | getNumDays()
Retrieves the number of days included in this package. |
abstract double | getPrice()
This method provides the full price of a vacation package, which is must be computed based on the specific kind of trip being booked. |
void | setLength(int numDays)
Updates the length of this VacationPackage. |
void | setName(java.lang.String name)
Updates the VacationPackage's externally facing promotional name. |
java.lang.String | toString()
This method produces a String summary of a VacationPackage. |
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, waitConstructor Detail
VacationPackage
public VacationPackage(java.lang.String name, int numDays)
Initializes a VacationPackage with provided values.
Parameters:
name - The promotional marketing name for this package.
numDays - The number of days included in this VacationPackage trip.
Method Detail
setName
public void setName(java.lang.String name)
Updates the VacationPackage's externally facing promotional name. Due to travel agency policy, this name is never allowed to be empty as it would be confusing for agents and customers interacting with the system. Names that do not comply with this policy will be ignored and the package will be given the name "PACKAGE NAME TBD" as a placeholder.
Parameters:
name - The updated name to use for this package.
setLength
public void setLength(int numDays)
Updates the length of this VacationPackage. All packages must have a minimum of one day.
Parameters:
numDays - The new number of days for this package.
getName
public java.lang.String getName()
Retrieves the promotional name of this package.
Returns:
The name.
getNumDays
public int getNumDays()
Retrieves the number of days included in this package.
Returns:
The number of days for this trip.
getPrice
public abstract double getPrice()
This method provides the full price of a vacation package, which is must be computed based on the specific kind of trip being booked.
Returns:
The price of a vacation package in US Dollars.
getDepositAmount
public abstract double getDepositAmount()
This method provides the required upfront deposit amount for a given vacation. This must be computed based on rules determined by specific package types, per travel agency policies.
Returns:
The deposit amount required in US Dollars.
getAmountDue
public double getAmountDue()
This method provides the remaining amount due to the travel agent for this trip less any deposit made upfront.
Returns:
The remaining balance to pay the travel agency.
getLodgingCost
public abstract double getLodgingCost()
This method provides the subtotal for a trip related to lodging expenses (ie, not including flights, meals, and incidentals). Lodging rates are determined by specific package types.
Returns:
The lodging subtotal in US Dollars.
toString
public java.lang.String toString()This method produces a String summary of a VacationPackage. Strings will be prefixed with the $ symbol, followed by trip total price rounded to two decimal places in a 8 character wide field. Price details should be followed by two spaces and the promotional name of this trip. For example:
$ 1234.56 Spring Break at the Beach $ 150.99 Rustic Backpacking at Mt. Rushmore
Overrides:
toString in class java.lang.Object
Returns:
The formatted string summary.
equals
public boolean equals(java.lang.Object other)
Provides a logical equality comparison for VacationPackages and any other object type.
Overrides:
equals in class java.lang.Object
Parameters:
other - A reference to another object to be compared with this one.
Returns:
true if and only if this VacationPackage shares the same promotional name as one referred to by other. false when other is not a valid VacationPackage object or the names do not match
class VacationPackage
{
private String pName;
private int nDays;
public VacationPackage(String name, int numDays)
{
this.pName = name;
this.nDays = numDays;
}
public void setName(String name)
{
this.pName = name;
}
public void setLength(int NumDays)
{
this.nDays = NumDays;
}
public String getName()
{
return this.pName;
}
public int getNumDays()
{
return this.nDays;
}
public abstract Double getPrice();
public abstract double getDepositAmount();
public double getAmountDue()
{
return this.getPrice()-this.getDepositAmount();
}
public abstract double getLodgingCost();
public String toString()
{
String p = String.format("%7.2f",this.getPrice());
return "$"+p+" "+this.getName();
}
public boolean equals(Object other)
{
if(other instanceof VacationPackage)
if(this.getName()==other.getName())
return true;
return false;
}
}
Get Answers For Free
Most questions answered within 1 hours.