FileDocCategorySizeDatePackage
CDDisc.javaAPI DocExample3939Thu Oct 13 14:57:44 BST 2005com.samscdrental.model

CDDisc

public class CDDisc extends Object implements Serializable

Title: Sams CD Rental Store

Description:

Copyright: Copyright (c) 2004

Company:

author
Ken Pugh
version
1.0

Fields Summary
private static final long
serialVersionUID
private CDRelease
theCDRelease
private PhysicalID
thePhysicalID
private Rental
theRental
private static final Dollar
OVERDUE_FEE
private static final String
ERROR_ENDING_NON_STARTED_RENTAL
private static final String
ERROR_CDDISC_ALREADY_RENTED
Constructors Summary
public CDDisc(CDRelease aCDRelease, PhysicalID aPhysicalID)

 

	      
	
		theCDRelease = aCDRelease;
		thePhysicalID = aPhysicalID;
	
Methods Summary
public voidendRental()
endRental

		if ( theRental == null )
		{
			throw new CheckInDeviation( ERROR_ENDING_NON_STARTED_RENTAL );
		}
		else
		{
			theRental.checkIn();
			if ( theRental.isLateReturn() )
			{
				OverdueRentalDTO aOverdueRentalDTO = makeOverdueRentalDTO();
				theRental = null;
				throw new LateReturnDeviation( aOverdueRentalDTO );
			}
		}
		theRental = null;
		return;
	
public CDReleasegetCdRelease()

		return theCDRelease;
	
public PhysicalIDgetPhysicalID()

		return thePhysicalID;
	
public RentalgetRental()

		return theRental;
	
public booleanisRented()
isRented

return
boolean

		return ( theRental != null );

	
private OverdueRentalDTOmakeOverdueRentalDTO()
makeOverdueRentalDTO

		OverdueRentalDTO aOverdueRentalDTO = new OverdueRentalDTO();
		aOverdueRentalDTO.theCDDiscPhysicalID = this.thePhysicalID;
		aOverdueRentalDTO.theCDReleaseTitle = this.theCDRelease.
			getTitle();
		aOverdueRentalDTO.theCustomerID = this.theRental.getCustomer().
			getCustomerID();
		aOverdueRentalDTO.theCustomerName = this.theRental.getCustomer().
			getName();
		aOverdueRentalDTO.theOverdueFee = OVERDUE_FEE;
		aOverdueRentalDTO.theRentalDueTime = this.theRental.getDueTime();
		aOverdueRentalDTO.theRentalEndTime = this.theRental.getEndTime();
		aOverdueRentalDTO.theRentalStartTime = this.theRental.
			getStartTime();
		return aOverdueRentalDTO;
	
private RentalContractDTOmakeRentalContractDTO(Customer aCustomer)
makeOverdueRentalDTO

		RentalContractDTO aRentalContractDTO = new RentalContractDTO();
		aRentalContractDTO.theCDDiscPhysicalID = this.thePhysicalID;
		aRentalContractDTO.theCDReleaseTitle = this.theCDRelease.getTitle();
		aRentalContractDTO.theCustomerName = aCustomer.getName();
		aRentalContractDTO.theRentalDueTime = this.theRental.getDueTime();
		aRentalContractDTO.theRentalFee = this.theRental.getRentalFee();
		aRentalContractDTO.theRentalStartTime = this.theRental.getStartTime();
		return aRentalContractDTO;
	
public RentalContractDTOstartRental(Customer aCustomer)
start_rental

param
theCustomer Customer

		int aBaseRentalPeriodDays =
			theCDRelease.getBaseRentalPeriodDays();
		Dollar rentalFee = theCDRelease.getRentalFee();
		if ( theRental != null )
		{
			throw new CheckOutDeviation( ERROR_CDDISC_ALREADY_RENTED );
		}
		theRental = new Rental( aCustomer, aBaseRentalPeriodDays, rentalFee );

		RentalContractDTO aRentalContractDTO = makeRentalContractDTO( aCustomer );
		return aRentalContractDTO;