I am kind of new to object oriented programming and I am learning the concepts. Right now I only need help on just logically organizing the classes. The parts about the methods, attributes, and constructors I can figure out. I was assigned this following problem.
Holiday Travel Vehicles sells new recreational vehicles and travel
trailers. When new vehicles arrive at Holiday Travel Vehicles, a new
vehicle record is created. Included in the new vehicle record are a
vehicle serial number, name, model, year, manufacturer, and base cost.
When a customer arrives at Holiday Travel Vehicles, he or she works
with a salesperson to negotiate a vehicle purchase. When a purchase
has been agreed upon, a sales invoice is completed by the salesperson.
The invoice summarizes the purchase, including full customer
information, information on the trade-‐in vehicle (if any), the
trade-‐in allowance, and information on the purchased vehicle. If the
customer requests dealer-‐installed options, they are listed on the
invoice as well. The invoice also summarizes the negotiated price,
plus any applicable taxes and license fees. The transaction concludes
with a customer signature on the sales invoice.
So far what I have thought of doing is making an invoice superclass with a customer and vehicle subclass since vehicle information and customer information is on the invoice. However since vehicles get records upon arrival to the dealership, I also thought about making vehicle it’s own class with the subclass travel trailer and RV since one involves an engine and one does not. However if I am doing vehicle records and vehicle information in an invoice I can’t make vehicle both it’s own class and a subclass of invoice.(If everything I am saying does not make sense, I am sorry I am just really confused.) So how should I arrange those classes? I am really lost.
Making vehicle and customer a sub-class of invoice doesn’t make a whole lot of sense. What I think you want is to make a vehicle class and a customer class, then within your invoice class you can hold an instance of the vehicle object and the customer object it dictates.
For travel trailer and RV class it makes more sense to sub-class vehicle since they are in essence a vehicle so will share many common variables with vehicles. The question you need to ask yourself is whether something
issomething else (an RVisa vehicle), or itpointsto something (an invoice has a reference to a vehicle). I hope that is clear, it is definitely something I remember struggling with as I first learned it.